morphological reconstruction of the image
IM = imreconstruct(
be two intensity images or two binary images with the same size. The
IM is an intensity image or a binary
image, depending on the input images, and is the same size as the
marker must be the same size as
and its elements must be less than or equal to the corresponding elements
mask. If the values in
greater than corresponding elements in
the values to the
mask level before starting the
imreconstruct uses 8-connected
neighborhoods for 2-D images and 26-connected neighborhoods for 3-D
images. For higher dimensions,
Read a grayscale image and display it.
I = imread('snowflakes.png'); figure imshow(I)
Adjust the contast of the image to create the mask image and display results.
mask = adapthisteq(I); figure 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 results.
obr = imreconstruct(marker,mask); figure 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)
Read mask image and create gpuArray.
mask = gpuArray(imread('text.png')); figure, imshow(mask),
Create marker image gpuArray.
marker = gpuArray.false(size(mask)); marker(13,94) = true;
Perform the segmentation and display the result.
im = imreconstruct(marker,mask); figure, imshow(im)
marker— Input image
Input image, specified as a nonsparse numeric or logical array.
se = strel('disk',5); marker = imerode(mask,se);
mask— Mask image
Mask image, specified as a nonsparse numeric or logical array.
mask = imread('text.png');
Connectivity, specified as one of the values in this table.
Connectivity can also be defined in a more general way for any
dimension by using for
conn a 3-by-3-by- ... -by-3
elements define neighborhood locations relative to the center element
conn. Note that
be symmetric about its center element.
obr = imreconstruct(marker,mask,4);
gpuarrayMarker— Input image on a GPU
Input image on a GPU, specified as a gpuArray.
marker = gpuArray(imread(‘text.png'));
gpuarrayMask— Mask image on a GPU
Mask image on a GPU, specified as a gpuArray.
mask = gpuArray(imread(‘text.png'));
IM— 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.
This function supports the generation of C code using MATLAB® Coder™.
Note that if you choose the generic
MATLAB Host Computer target
platform, the function 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 Understanding Code Generation with Image Processing Toolbox.
When generating code, the optional third input argument,
must be a compile-time constant, and can only take the value
You can use this function in the MATLAB Function Block in Simulink.
Morphological reconstruction is the algorithmic basis
for several other Image Processing Toolbox™ functions, including
Performance note: This function
may take advantage of hardware optimization for data types
single to run faster. Hardware optimization
be 2-D images and
conn to be either 4 or 8.
 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.