performs morphological reconstruction of the image
J = imreconstruct(
mask, and returns the reconstruction in
J. The elements of
marker must be less
than or equal to the corresponding elements of
mask. If the
marker are greater than corresponding elements in
imreconstruct clips the
values to the
mask level before starting the procedure.
You optionally can perform morphological reconstruction of 2-D images
Read and display a grayscale image.
I = imread('snowflakes.png'); imshow(I)
Adjust the contrast of the image to create the mask image and display results.
mask = adapthisteq(I); imshow(mask)
Create a marker image that identifies high-intensity objects in the image using morphological erosion and display results.
se = strel('disk',5); marker = imerode(mask,se); imshow(marker)
Perform morphological opening on the mask image, using the marker image to identify high-intensity objects in the mask. Display the result.
obr = imreconstruct(marker,mask); imshow(obr,)
Read a logical image into workspace and display it. This is the mask image.
mask = imread('text.png'); figure imshow(mask)
Create a marker image that identifies the object in the image you want to extract through segmentation. For this example, identify the "w" in the word "watershed".
marker = false(size(mask)); marker(13,94) = true;
Perform segmentation of the mask image using the marker image.
im = imreconstruct(marker,mask); figure imshow(im)
marker— Input image
Input image, specified as a numeric or logical array.
se = strel('disk',5); marker = imerode(mask,se);
mask— Mask image
Mask image, specified as a numeric or logical array of the same size and data type as
mask = imread('text.png');
conn— Pixel connectivity
26| 3-by-3-by- ... -by-3 matrix of
Pixel connectivity, specified as one of the values in this table. The
default connectivity is
8 for 2-D images, and
26 for 3-D images.
Pixels are connected if their edges touch. The neighborhood of a pixel are the adjacent pixels in the horizontal or vertical direction.
Pixels are connected if their edges or corners touch. The neighborhood of a pixel are the adjacent pixels in the horizontal, vertical, or diagonal direction.
Pixels are connected if their faces touch. The neighborhood of a pixel are the adjacent pixels in:
Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:
Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:
For higher dimensions,
imreconstruct uses the default
J— Reconstructed image
Reconstructed image, returned as a numeric or logical array, depending on the input image, that is the same size as the input image.
Morphological reconstruction is the algorithmic basis for several other
Toolbox™ functions, including
Performance note: This function may take advantage of
hardware optimization for data types
double to run faster.
Hardware optimization requires
mask to be 2-D images and
imreconstruct uses the fast hybrid grayscale reconstruction algorithm
described in .
 Vincent, L., "Morphological Grayscale Reconstruction in Image Analysis: Applications and Efficient Algorithms," IEEE Transactions on Image Processing, Vol. 2, No. 2, April, 1993, pp. 176-201.
Usage notes and limitations:
imreconstruct supports the generation of C
code (requires MATLAB®
Coder™). Note that if you choose the generic
MATLAB Host Computer
imreconstruct generates code that uses a precompiled,
platform-specific shared library. Use of a shared library preserves performance optimizations
but limits the target platforms for which code can be generated. For more information, see Code Generation Using a Shared Library.
When generating code, the optional third input argument,
conn, must be a compile-time constant, and can
only take the value
imreconstruct does not support
int64 data types
for code generation.
Usage notes and limitations:
Input images must be 2-D numeric or logical matrices.
imreconstruct does not support RGB images and 3-D
images on a GPU. Only the 2-D connectivities (4 and 8) are supported.
For more information, see Image Processing on a GPU.