Steve Eddins retired from MathWorks in 2024 after 30 years of service. He can now be found at MATLAB Central and at Matrix Values, where he continues to write about MATLAB and related topics. His MathWorks career included image processing, toolbox development, MATLAB development and design, development team management, and MATLAB design standards. He wrote the Steve on Image Processing blog for 18 years and is a co-author of Digital Image Processing Using MATLAB.
An amateur musician and French horn enthusiast, Steve is a member of Concord Orchestra and Melrose Symphony Orchestra, as well as a member of the board of directors for Cormont Music and the Kendall Betts Horn Camp. He blogs about music and French horn at Horn Journey.
Today I want to show you a morphological operation called "opening by reconstruction."
The normal morphological opening is an erosion followed by a dilation. The erosion "shrinks" an image according to the shape
of the structuring element, removing objects that are smaller than the shape. Then the dilation step "regrows" the remaining
objects by the same shape.
Here's an example using a fragment of text from the book Digital Image Processing Using MATLAB.
Suppose we want to identify characters containing a tall vertical segment. We can do this by opening with a vertical structuring
element.
Erode first:
se = strel(ones(51, 1));
bw2 = imerode(bw, se);
imshow(bw2)
Then dilate:
bw3 = imdilate(bw2, se);
imshow(bw3)
Or you can do the opening in a single step by calling imopen:
bw3 = imopen(bw, se);
imshow(bw3)
The dilation step in the opening operation restored the vertical strokes, but the other strokes of the characters are missing.
How can we get the entire characters containing vertical strokes?
The answer is to use morphological reconstruction. For binary images, reconstruction starts from a set of starting pixels
(or "seed" pixels) and then grows in flood-fill fashion to include complete connected components.
To get ready to use reconstruction, first define a "marker" image. This is the image containing the starting or seed locations.
For our text example, the marker image will the output of the erosion.
marker = imerode(bw, se);
imshow(marker)
Next, define mask image. The flood-filling will be constrained to spread only to foreground pixels in the mask image. We
can use the original text image as our reconstruction mask.
mask = bw;
Finally, call imreconstruct to perform the operation.
Performing morphological reconstruction, using the eroded image as the marker and the original image as the mask, is called
"opening by reconstruction."
Do you have other uses for morphological reconstruction in your own applications? Tell us about it: Click on the "Comment"
link below.
Comments
To leave a comment, please click here to sign in to your MathWorks Account or create a new one.