Description:
Currently, skimage.morphology.dilation calls scipy.ndimage.grey_dilation with the default mode value (boundary extension, this is what the filter does outside the image bounds). The default is 'reflect', which fills in values outside the image using values from inside the image. The same applies to erosion and other morphological filters.
With dilations and erosions, if the structuring element is compact, this will not matter at all. It samples some of the pixels twice. But if the structuring element is not compact, then it will sample some pixels we didn't intend to sample. See for example this Stack Overflow answer I just posted, where the structuring element doesn't include the central pixel.
Ideally, we'd extend the boundary with the minimum allowed value for the data type (or the maximum in the case of the erosion). This way, pixels outside the image will not influence the result at all. This can be accomplished by setting the mode and cval arguments to scipy.ndimage.grey_dilation appropriately:
ndi.grey_dilation(image, footprint=footprint, output=out, mode="constant", cval=np.iinfo(image.dtype).min)
(to be tested that this works OK in ndimage with 64-bit integer arrays and so forth).
Alternatively, one could consider allowing the user to select a boundary extension method.
BTW: I'm happy to send a PR, but I didn't know which solution this community preferred.
Description:
Currently,
skimage.morphology.dilationcallsscipy.ndimage.grey_dilationwith the defaultmodevalue (boundary extension, this is what the filter does outside the image bounds). The default is'reflect', which fills in values outside the image using values from inside the image. The same applies toerosionand other morphological filters.With dilations and erosions, if the structuring element is compact, this will not matter at all. It samples some of the pixels twice. But if the structuring element is not compact, then it will sample some pixels we didn't intend to sample. See for example this Stack Overflow answer I just posted, where the structuring element doesn't include the central pixel.
Ideally, we'd extend the boundary with the minimum allowed value for the data type (or the maximum in the case of the erosion). This way, pixels outside the image will not influence the result at all. This can be accomplished by setting the
modeandcvalarguments toscipy.ndimage.grey_dilationappropriately:(to be tested that this works OK in ndimage with 64-bit integer arrays and so forth).
Alternatively, one could consider allowing the user to select a boundary extension method.
BTW: I'm happy to send a PR, but I didn't know which solution this community preferred.