imreconstruct

Morphological reconstruction

Syntax

IM = imreconstruct(marker,mask)
IM = imreconstruct(marker,mask,conn)
gpuarrayIM = imreconstruct(gpuarrayMarker,gpuarrayMask,conn)

Description

IM = imreconstruct(marker,mask) performs morphological reconstruction of the image marker under the image mask. marker and mask can be two intensity images or two binary images with the same size. The returned image IM is an intensity or binary image, respectively. marker must be the same size as mask, and its elements must be less than or equal to the corresponding elements of mask. If values in marker are greater than corresponding elements in mask, imreconstruct clips the values to the mask level.

By default, imreconstruct uses 8-connected neighborhoods for 2-D images and 26-connected neighborhoods for 3-D images. For higher dimensions, imreconstruct uses conndef(ndims(I),'maximal').

IM = imreconstruct(marker,mask,conn) performs morphological reconstruction with the specified connectivity. conn can have any of the following scalar values.

Value

Meaning

Two-dimensional connectivities

4

4-connected neighborhood

8

8-connected neighborhood

Three-dimensional connectivities

6

6-connected neighborhood

18

18-connected neighborhood

26

26-connected neighborhood

Connectivity can be defined in a more general way for any dimension by using for conn a 3-by-3-by- ... -by-3 matrix of 0's and 1's. The 1-valued elements define neighborhood locations relative to the center element of conn. Note that conn must be symmetric about its center element.

gpuarrayIM = imreconstruct(gpuarrayMarker,gpuarrayMask,conn) performs morphological reconstruction of the gpuArray image gpuarrayMarker under the gpuArray image gpuarrayMask. Both input images must be 2-D. The optional connectivity argument (conn) can be 4 or 8. If not specified, imreconstruct uses a 4-connected neighborhood. This syntax requires the Parallel Computing Toolbox™.

Morphological reconstruction is the algorithmic basis for several other Image Processing Toolbox™ functions, including imclearborder, imextendedmax, imextendedmin, imfill, imhmax, imhmin, and imimposemin.

Code Generation

imreconstruct supports the generation of efficient, production-quality C/C++ code from MATLAB. When generating code, the optional third input argument, conn, must be a compile-time constant. Generated code for this function uses a precompiled platform-specific shared library. To see a complete list of toolbox functions that support code generation, see List of Supported Functions with Usage Notes.

Class Support

marker and mask must be nonsparse numeric (including uint64 or int64) or logical arrays with the same class and any dimension. IM is of the same class as marker and mask.

gpuarrayMarker and gpuarrayMask must be nonsparse numeric (excluding uint64 or int64) or logical gpuArrays with the same underlying class and any dimension. The output image, gpuarrayIM, is a gpuArray of the same underlying class as gpuarrayMarker and gpuarrayMask.

Performance Note

This function may take advantage of hardware optimization for data types logical, uint8, and single to run faster. Hardware optimization requires marker and mask to be 2-D images and conn to be either 4 or 8.

Examples

expand all

Perform opening-by-reconstruction to identify high intensity snowflakes

Read mask image.

I = imread('snowflakes.png');
mask = adapthisteq(I);
figure, imshow(mask);

Create marker image.

se = strel('disk',5);
marker = imerode(mask,se);

Perform morphological opening on the image.

obr = imreconstruct(marker,mask);
figure, imshow(obr,[])

Use reconstruction to segment an image

Read mask image.

mask = imread('text.png');
imshow(mask);

Create marker image.

marker = false(size(mask));
marker(13,94) = true;

Perform the segmentation and display image.

im = imreconstruct(marker,mask);
figure, imshow(im)

Use reconstruction to segment an image on a GPU

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)

More About

expand all

Algorithms

imreconstruct uses the fast hybrid grayscale reconstruction algorithm described in [1].

References

[1] 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.

Was this topic helpful?