how we can imfill a thing that it is very similar to a hole but in fact it is not a hole?
Show older comments
how we can imfill a thing in an binary image that it is very similar to a hole but in fact it is not a hole?

I attached a simple image that in the left side there is a thing that looks like a hole but it is not a hole
4 Comments
Sean de Wolski
on 24 Sep 2014
How did you get the binary image?
Sean de Wolski
on 25 Sep 2014
Well there might be a better method than otsu; post the pre-otsu image
Image Analyst
on 25 Sep 2014
Sean, it's been posted before. Unfortunately she's carrying on this discussion in 4 or 5 different discussions. Last I left it, I showed her how to use activecontour: http://www.mathworks.com/matlabcentral/answers/155374#comment_238290
Answers (2)
Use imclose either to seal it, or to turn it into a hole which can then be treated with imfill.
3 Comments
Matt J
on 24 Sep 2014
In the images that you've shown, the lungs are divided by an approximately vertical line. If that will always be the case, you can try using imclose with a tall, thin strel, instead of a disk. This will help imclose ignore the gap between the lungs, but still fill the other concavities. The width of the strel must be less than the separation of the lungs.
sara
on 25 Sep 2014
Matt J
on 25 Sep 2014
You could also use regionprops or bwconncomp to separate the lungs in two separate images. Then you could imclose with the original strel that was working well. Then you recombine the images.
It would also be worth attaching the challenging black and white lung image in a .mat file, so that other people can play with it.
Image Analyst
on 14 Sep 2014
0 votes
Like I said in the discussion that was this first part of this question before you started this one, you can use activecontour(). See attached demo. If you can't figure how to adapt the demo, let me know. Either way, with imclose() or activecontour(), it will smooth out the perimeter and snip off that bay/incursion.
11 Comments
sara
on 15 Sep 2014
sara
on 15 Sep 2014
sara
on 15 Sep 2014
sara
on 15 Sep 2014
Image Analyst
on 15 Sep 2014
You might need to do different size filtering than I did. I assumed there would be two blobs and I took the largest 2. But you have a white line cutting across one image so that there are 3 blobs. So you might have to take all blobs larger than a certain size rather than always taking just 2.
sara
on 15 Sep 2014
sara
on 15 Sep 2014
Image Analyst
on 15 Sep 2014
If your lungs can be comprised of some unknown number of blobs, then the ExtractNLargestBlobs() function is not good since you don't know the number in advance. And if you just pick something like 6 then for one that is only 2 blobs, you may get 4 tiny noise specks along with the 2 blobs you want.
See my Image Segmentation Tutorial to learn how you can filter blobs based on area, perimeter, or whatever else you want. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862
Image Analyst
on 17 Sep 2014
You can use imfreehand() to manually draw a line across it. Any other way will end up filling in or smoothing other little nooks and crannies at other places along the perimeter.
sara
on 24 Sep 2014
Categories
Find more on Morphological Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



