Isotropic Closing function produces smaller binary object than the input #192
-
Hello, I tried the function IsotropicClosing on a binary image consisting of a single active point in the centre. import diplib as dip
import numpy as np
arr = np.zeros((10,10))
arr[5,5] = 1
arr = arr>=1
#10x10 binary image with only pixel(5,5) active
image = dip.Image(arr)
dip.viewer.Show(image,title='inputimage')
image_closed = dip.IsotropicClosing(image,3)
dip.viewer.Show(image_closed,title='image closed') By inspecting the source code the function IsotropicClosing calls (as expected) a IsotropicDilation followed by a IsotropicErosion but their parameter is not the same the one of IsotropicDilation i guess is rounded below (Lesser(...)) and the the one of IsotropicErosion is rounded up (Greater(...)). Here's a snipped of the C++ source code, version 3.5.2. void IsotropicDilation(
Image const& in,
Image& out,
dfloat distance
) {
DIP_THROW_IF( !in.IsForged(), E::IMAGE_NOT_FORGED );
DIP_THROW_IF( !in.IsScalar(), E::IMAGE_NOT_SCALAR );
DIP_THROW_IF( in.DataType() != DT_BIN, E::DATA_TYPE_NOT_SUPPORTED );
DIP_STACK_TRACE_THIS( Lesser( EuclideanDistanceTransform( !( in.QuickCopy() ), "object", "square" ), distance * distance, out ));
// Note: QuickCopy() discards the pixel sizes. This allows `distance` to be in pixels rather than a physical distance.
}
void IsotropicErosion(
Image const& in,
Image& out,
dfloat distance
) {
DIP_THROW_IF( !in.IsForged(), E::IMAGE_NOT_FORGED );
DIP_THROW_IF( !in.IsScalar(), E::IMAGE_NOT_SCALAR );
DIP_THROW_IF( in.DataType() != DT_BIN, E::DATA_TYPE_NOT_SUPPORTED );
DIP_STACK_TRACE_THIS( Greater( EuclideanDistanceTransform( in.QuickCopy(), "object", "square" ), distance * distance, out ));
// See note above in IsotropicDilation().
} I am afraid there is not a quick fix solution to this but it is definetly an incorrect behaviour since the structure element should be the same for both erosion and dilation. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Thank you for reporting this bug! I've fixed it here: 903c5b0 |
Beta Was this translation helpful? Give feedback.
Thank you for reporting this bug!
I've fixed it here: 903c5b0