CrImage::Util::Morphology
Morphological operations for image processing. Includes erosion, dilation, opening, closing, and morphological gradient.
Class methods
Applies morphological closing (dilation followed by erosion).
Closing fills small holes and gaps while preserving larger structures. Useful for connecting nearby objects and filling gaps.
Parameters:
src: The source imagekernel_size: Size of structuring element (must be odd)shape: Shape of structuring element (default: Rectangle)
Returns: A new closed Image
Example:
img = CrImage::PNG.read("gaps.png")
closed = CrImage::Util::Morphology.close(img, 5)
Applies dilation to an image.
Dilation expands bright regions and shrinks dark regions. Useful for filling small holes and connecting nearby objects.
Parameters:
src: The source imagekernel_size: Size of structuring element (must be odd)shape: Shape of structuring element (default: Rectangle)
Returns: A new dilated Image
Example:
img = CrImage::PNG.read("binary.png")
dilated = CrImage::Util::Morphology.dilate(img, 3)
Applies erosion to an image.
Erosion shrinks bright regions and enlarges dark regions. Useful for removing small bright spots and separating objects.
Parameters:
src: The source imagekernel_size: Size of structuring element (must be odd)shape: Shape of structuring element (default: Rectangle)
Returns: A new eroded Image
Example:
img = CrImage::PNG.read("noisy.png")
eroded = CrImage::Util::Morphology.erode(img, 3)
Applies morphological gradient (dilation - erosion).
Gradient highlights edges and boundaries of objects. Useful for edge detection and boundary extraction.
Parameters:
src: The source imagekernel_size: Size of structuring element (must be odd)shape: Shape of structuring element (default: Rectangle)
Returns: A new gradient Image
Example:
img = CrImage::PNG.read("objects.png")
gradient = CrImage::Util::Morphology.gradient(img, 3)
Applies morphological opening (erosion followed by dilation).
Opening removes small bright spots while preserving larger structures. Useful for noise removal and smoothing object boundaries.
Parameters:
src: The source imagekernel_size: Size of structuring element (must be odd)shape: Shape of structuring element (default: Rectangle)
Returns: A new opened Image
Example:
img = CrImage::PNG.read("noisy.png")
opened = CrImage::Util::Morphology.open(img, 5)