Identify shape in binary picture make it smooth and ignore rest

3 views (last 30 days)
i am trying to identify forged parts of an image and i am having results like the picture below.
How can i :
  • identify the bigest object in the picture
  • make borders for the object and fill it in, in order to be smooth
  • remove any remaining part from the image
in which direction should i go?
check.bmp

Accepted Answer

Matt J
Matt J on 14 Dec 2018
Edited: Matt J on 14 Dec 2018
newImage = imclose(bwareafilt(yourImage,1), ones(20));
untitled.png

More Answers (2)

Image Analyst
Image Analyst on 14 Dec 2018
Call imfill() and bwareafilt(). This will not change the shape of the object like imclose() will
mask = imfill(mask, 'holes');
mask = bwareafilt(mask, 1);
where mask is your binary image.
  2 Comments
Matt J
Matt J on 14 Dec 2018
Edited: Matt J on 14 Dec 2018
Be mindful, however, that this will leave the edges unsmoothed, in case that matters.
Image Analyst
Image Analyst on 15 Dec 2018
Another way to make the boundary smooth is to blur the image and threshold it:
windowSize = 5; % Whatever
kernel = ones(windowSize)/windowSize^2;
newMask = conv2(double(mask), kernel, 'same') > 0.5;
Has a somewhat different shape than imclose(), especially for larger kernel sizes.
If you need to "make borders for the object", then you can bwboundaries():
boundaries = bwboundaries(mask);

Sign in to comment.


lvas
lvas on 15 Dec 2018
thank you for your answers, i used the
newImage = imclose(bwareafilt(yourImage,1), ones(20));
it appears to be working fine for now
  2 Comments
Image Analyst
Image Analyst on 15 Dec 2018
I would still use imfill(). You can do that before your call to imclose(). The reason is, if you have large holes (more than 40 pixels across), the 20 pixel dilation may not be enough to cover that hole. Then you'd still have holes remaining in your region, whereas imfill() will never leave any holes -- it will ALWAYS fill all holes regardless if they are 40 or more pixels in diameter.
You can still use imclose() on it, which will still smooth the boundaries. The closing number will control how smooth the boundaries are - bigger for more smoothing, smaller for less smoothing. Sometimes, for larger numbers, using imclose to smooth boundaries will give artifacts related to the shape of the structuring element, and the blurring might be better. So I'd try it both ways.
lvas
lvas on 15 Dec 2018
thank you very much for this information, i am making tests on the pictures currently and i do have in some cases some holes, i will use the imfill accordingly

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!