How to expand a black region in a boolean image?

12 views (last 30 days)
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?
  2 Comments
Matt Kindig
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
Sunil Shahi on 28 Jun 2013
thank you so much that worked very well

Sign in to comment.

Answers (1)

Chong
Chong on 28 Jun 2013
Edited: 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);
imshow(BW2)
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( )

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!