MATLAB Answers

"Fill" Binary Image

4 views (last 30 days)
Hi,
Is there a way to "fill" a binary image such that textured regions become black? As an example, I would like to make this first image:
Look like this second image:
Note how the wall towards the left of the image appears mainly white in the first image. Is there a way to darken it so that it becomes more like that shown in the second image?
I have tried using morphological operators such as:
filled = bwmorph(img, 'fill', 100);
But this doesn't seem to have any affect. I am desperate to hear your thoughts.
Thanks for your help!

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 2 Jun 2011
I believe you would want to either erode the white or dilate the black, (possibly followed by the reverse operation), so as to remove small features.
Or alternately, you could bwlabel() and regionprops() and remove the regions of sufficiently small area. That might not get all of the texture lines though.

  0 Comments

Sign in to comment.

More Answers (2)

Image Analyst
Image Analyst on 3 Jun 2011
You can try imopen if you want to maintain the size - this does an erosion (local min) followed by a dilation (local max). To enlarge the black area, just use imerode. To get rid of small things, use bwareaopen, which does labeling and regionprops internally like Walter said. But your images were not created by any morphological operation of the first one to produce the second one. I'm virtually certain that they were produced by thresholding with different threshold values, because there's no other way to produce the texture in the sky region of the second image - it simply isn't in the first image and there's no way to get that out of a uniform white area. I'd bet my next paycheck on it.

  0 Comments

Sign in to comment.


Philip
Philip on 2 Jun 2011
Thanks for your help! I really must read the literature for morphological operations... The erode and dilate methodology seems to have done the trick here!
Thanks again!!

  16 Comments

Walter Roberson
Walter Roberson on 3 Jun 2011
Longest straightest boundary, or longest straightest edge? An edge could, for example, be part of a texture. A band of ventilation grills running along a building that had an irregular rough could find the band to be the longest straight edge ?
Philip
Philip on 3 Jun 2011
My terminology is poor. The edge must be the edge of an object; so a boundary. It shouldn't be an edge of anything in the texture. I have therefore been using erode and dilate to remove some of this detail first... I'm not sure if that is the best strategy though.
Image Analyst
Image Analyst on 4 Jun 2011
Have you considered using Hough or houghlines for finding lines? Like I said before your images were binarized from a gray scale image. I don't think they are the result of different exposures unless your gain is so incredibly high that the different exposures cause binarization in the first place. Why don't you post the original gray scale or color images and say what you are really trying to find instead of saying things like I want to find the longest line. If you want to find a horizon, say so. Because maybe the longest line won't get you that in all situations.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!

Translated by