how we can imfill a thing that it is very similar to a hole but in fact it is not a hole?

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

hi Sean
it is lung..I use otsu method and after that I use bwareaopen(binaryImage, 4800);
imclearborder(binaryImage);
to remove the things that we don't want..and then I use imfiil() to close holes.I could close this hole but now my problem is this:
it is a different image but my code should work for every images...
thanks Sean
Well there might be a better method than otsu; post the pre-otsu image
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

Sign in to comment.

Answers (2)

Use imclose either to seal it, or to turn it into a hole which can then be treated with imfill.

3 Comments

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.
yes Matt
I tried this before but my result was not good ... thanks a lot
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.

Sign in to comment.

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

Thanks Matt and Image Analyst
I tried to use activecontour() but I couldn't obtain a good result....I will use imclose() and say you the result.
oh Thanks Matt and Image Analyst
imclose() gives me a good result... but I should try it for other images. thanks
hi
I try imclose() for this image and the result is this
it is a good result I think...but I test imclose for this i
mage: that you can see this is a very bad result...I couldn't get a good result when I use activecountor...I attach my code and the image ... can you guide me if there is a better way for this... thanks
and the image that I can't get a good result is this ,that I attached
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.
wow Image Analyst
you are so intelligent... I do not know how to thank you... the result is better .I modify it and I will come back.. thanks a lot
Image Analyst
I changed the number of blobs :
if true
binaryImage = ExtractNLargestBlobs(binaryImage,6); end
and my result is like this:
it is better but left lung is defective.. I tried different number for blobs but the result was not change.. I tested imclose() but the result was not change.. when you say "You might need to do different size filtering than I did" what do you mean I didn't understand.. thank you Image Analyst.
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
thanks dear Image Analyst because of all your helpful guidance
after some researches I understood that two lung can not be Connected to each other so after modification I obtain this image that you can see it isn't connected
Is any way with strel command in matlab that can help me to fill the holes that we see in the left side of this lung..I used strel('disk',...) but I can't obtain a good result.
thanks a lot
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.
thanks Image Analyst I cant do it manually... you said :"Any other way will end up filling in or smoothing other little nooks and crannies at other places along the perimeter" do you mean using imclose() or smoothing filter?? can you explain it more??
thanks a lot

Sign in to comment.

Asked:

on 14 Sep 2014

Commented:

on 25 Sep 2014

Community Treasure Hunt

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

Start Hunting!