Repository navigation
Conversation
- When a mask is not provided, do not do bleed-over calculation; bleed-over normalization does affect the outcome a tiny bit. - Do not use `preserve_range=True` in the Gaussian filter, since it rescales the smoothed image unnecessarily.
|
Test script: Output of skimage v0.19: Output before this patch: Output after this patch: |
|
Legitimate failure after patch: |
rfezzani
left a comment
There was a problem hiding this comment.
If you want to change boundary mode, better do it in canny function signature, otherwise, everything seems good: running
import skimage
from skimage.feature import canny
import numpy as np
im = np.zeros((100, 100))
im[:50, :50] = 1
print(f"{skimage.__version__=}")
for mode in ['reflect', 'constant']:
print(f"{mode=}")
for dtype in ["float64", "float32",
"uint8", "uint16", "uint32", "uint64",
"int8", "int16", "int32", "int64"]:
print(f"\tPixels count with {dtype} input: ",
np.count_nonzero(canny(im.astype(dtype),
low_threshold=0, high_threshold=1,
mode=mode)))gives
skimage.__version__='0.21.0rc0.dev0'
mode='reflect'
Pixels count with float64 input: 185
Pixels count with float32 input: 185
Pixels count with uint8 input: 185
Pixels count with uint16 input: 185
Pixels count with uint32 input: 185
Pixels count with uint64 input: 185
Pixels count with int8 input: 185
Pixels count with int16 input: 185
Pixels count with int32 input: 185
Pixels count with int64 input: 185
mode='constant'
Pixels count with float64 input: 270
Pixels count with float32 input: 270
Pixels count with uint8 input: 270
Pixels count with uint16 input: 270
Pixels count with uint32 input: 270
Pixels count with uint64 input: 270
Pixels count with int8 input: 270
Pixels count with int16 input: 270
Pixels count with int32 input: 270
Pixels count with int64 input: 270
| # pixel data that's due to significant points) | ||
| bleed_over = gaussian(mask.astype(float_type, copy=False), | ||
| **gaussian_kwargs) + np.finfo(float_type).eps | ||
| sigma=1, mode='nearest') + np.finfo(float_type).eps |
There was a problem hiding this comment.
Changing mode from constant to nearest is not necessary to fix this issue, and is better suited in canny function signature.
There was a problem hiding this comment.
Without it, the results with a full mask do not match the unmasked version.
|
Setting import skimage
from skimage.feature import canny
import numpy as np
print(f"{skimage.__version__=}")
for l, h in [(0, 1), (0.01, 0.99), (0.1, 0.9)]:
print(f"low_threshold={l}, high_threshold={h}")
for name in ["camera", "moon", "coins"]:
print(f"Test image: {name}")
for mode in ['reflect', 'constant']:
im = getattr(skimage.data, name)()
print(f"\t{mode=}")
for dtype in ["uint8", "uint16", "uint32", "uint64",
"int16", "int32", "int64"]:
print(f"\t\tPixels count with {dtype} input: ",
np.count_nonzero(canny(im.astype(dtype),
low_threshold=l, high_threshold=h,
mode=mode, use_quantiles=True)))
im = skimage.img_as_float(im)
for dtype in ["float64", "float32"]:
print(f"\t\tPixels count with {dtype} input: ",
np.count_nonzero(canny(im.astype(dtype),
low_threshold=l, high_threshold=h,
mode=mode, use_quantiles=True)))gives |
|
@rfezzani The bleed over is incorrect for the full mask case; this should already be alarming. We cannot just change to the quantile version, that would be backward incompatible. Priority here is to figure out why your change modified the output, address that change (even if that means reverting that and all subsequent changes to canny); thereafter, we need to fix up the masked case. You say the image mode and the bleedover modes should be tied together, but look at what happens: the bleedover mask is divided into the image, and since those values are never close to 1 for a full image mask, this is completely broken. |
If you meant this as advice for the end-user, then yes agreed---it does make the result more stable. |
|
Given that uint64 is not a supported data-type, I think I will catch that situation, throw an error, and change |
|
Phew, after some more headscratching, I figured out another element of the problem: the masked behavior is better than the non-masked behavior. A long time ago, we made a poor choice of default Looking at the difference between v0.20 and v0.19, the border may account for the large reduction in values seen (will confirm). The only change necessary then is to prevent uint64 images from being processed; this "worked" in the past, but it was never guaranteed. If, indeed, the border behavior changed between v0.19 and v0.20, we may have to reintroduce that 😬 and fix it in skimage v2. |
|
Should #6874 (comment) go into API changes for skimage2 - HackMD? |
I already added it to the v1 issue, #5439; if that's no longer where you're tracking the v2 changes, let's unify the two documents and add links between them. |
|
A lesson from long ago that I've apparently forgotten: always look at the output. |
|
I'd consider the v0.20 behavior to be more correct than the v0.19 behavior. Changes proposed then: prohibit 64-bit integer images as input; add test to ensure masked and unmasked outputs are equal. |


preserve_range=Truein the Gaussian filter, since it rescales the smoothed image unnecessarily.Closes #6871