Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

How to expand a black region in a boolean image?

Asked by Sunil Shahi on 28 Jun 2013

I have a binary image in a matrix that I obtained by some image processing. When I say Binary Image I mean it has zeros and ones indicating complete black and complete white pixels. The image is mostly white and has some black spots. I now want to expand this black spots by some factor. How can I do it?


Matt Kindig on 28 Jun 2013

I assume you have the image processing toolbox. In that case, I would look at the 'bwmorph' and 'imdilate' functions. Also, in general dilation is performed on the white pixels of a black and white image, so you might need to invert the image (using the ~ operator) first.

Sunil Shahi on 28 Jun 2013

thank you so much that worked very well

Sunil  Shahi

1 Answer

Answer by Chong on 28 Jun 2013
Edited by Chong on 28 Jun 2013

As suggested by Matt, you may look into the morphological operations, eg link

The two basic operators in morphological filters are dilation and erosion. In your case whereby your input is a binary image, erosion will reduce the white pixel area (foreground area) and indirectly enlarges the black pixel area (background). Dilation operator does the exact opposite operation.

Using Matlab, you may do this using imdilate( ) or imerode( ) commands

BW = imread('circbw.tiff');
SE = strel('square',3);
BW2 = imerode(BW,SE);	% or BW2 = imdilate(BW, SE);

SE are actually the structure element. It acts like a "filter region". In the example, SE is a 3x3 square "filter". You may change its shape and size according to your requirement. To learn more about structure element, you may refer to the link just now.

Applying imdilate/imerode will affect the entire foreground. If you only want to change size of only the black spots or only the white spots, you may replace the imerode( ) and try with imopen( )/ imclose( )



Contact us