Main Content

imreconstruct

Morphological reconstruction

Description

J = imreconstruct(marker,mask) performs morphological reconstruction of the image marker under the image 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 values in marker are greater than corresponding elements in mask, then imreconstruct clips the values to the mask level before starting the procedure.

example

J = imreconstruct(marker,mask,conn) performs morphological reconstruction with the specified connectivity, conn.

Examples

collapse all

Read and display a grayscale image.

I = imread('snowflakes.png');
imshow(I)

Figure contains an axes object. The hidden axes object contains an object of type image.

Adjust the contrast of the image to create the mask image and display results.

mask = adapthisteq(I);
imshow(mask)

Figure contains an axes object. The hidden axes object contains an object of type image.

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)

Figure contains an axes object. The hidden axes object contains an object of type image.

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,[])

Figure contains an axes object. The hidden axes object contains an object of type image.

Read a logical image into workspace and display it. This is the mask image.

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

Figure contains an axes object. The hidden axes object contains an object of type image.

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)

Figure contains an axes object. The hidden axes object contains an object of type image.

Input Arguments

collapse all

Input image, specified as a numeric or logical array.

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Mask image, specified as a numeric or logical array of the same size and data type as marker.

Example: mask = imread('text.png');

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

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.

Value

Meaning

Two-Dimensional Connectivities

4

Pixels are connected if their edges touch. The neighborhood of a pixel are the adjacent pixels in the horizontal or vertical direction.

3-by-3 pixel neighborhood with four pixels connected to the center pixel

Current pixel is shown in gray.

8

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.

3-by-3 pixel neighborhood with 8 pixels connected to the center pixel

Current pixel is shown in gray.

Three-Dimensional Connectivities

6

Pixels are connected if their faces touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces of the center pixel

Current pixel is shown in gray.

18

Pixels are connected if their faces or edges touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces and 12 pixels connected to the edges of the center pixel

Current pixel is center of cube.

26

Pixels are connected if their faces, edges, or corners touch. The neighborhood of a pixel are the adjacent pixels in:

  • One of these directions: in, out, left, right, up, and down

  • A combination of two directions, such as right-down or in-up

  • A combination of three directions, such as in-right-up or in-left-down

3-by-3-by-3 pixel neighborhood with 6 pixels connected to the faces, 12 pixels connected to the edges, and 8 pixels connected to the corners of the center pixel

Current pixel is center of cube.

For higher dimensions, imreconstruct uses the default value conndef(ndims(marker),'maximal').

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

Data Types: double | logical

Output Arguments

collapse all

Reconstructed image, returned as a numeric or logical array, depending on the input image, that is the same size as the input image.

Tips

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.

Extended Capabilities

Version History

Introduced before R2006a

expand all