how can imfill an image with a lot of edge?
古いコメントを表示
hi
I want to imfill an image of lung to have an image that shows me just left and right lung.. I obtain boundary of lung wit this cod that I attach
if true
function [perimImage] = filling( I )
s = uint8(255 * mat2gray(I));
s = im2bw(s);
perimImage = xor(s,imerode(s, true(3)));
figure, imshow(perimImage)
end end
when I use this code my result is like the image that I put.

I think it is a good result but when I use imfill, the result is this:

do you have any suggestion for me to have an image like this after using imfill?

be black or white is not important for me I just want to segment lung to the result that I say.. thanks
2 件のコメント
Sean de Wolski
2014 年 9 月 8 日
編集済み: Sean de Wolski
2014 年 9 月 8 日
Show us the original image; it might be easier to start with that for the original segmentation.
sara
2014 年 9 月 8 日
回答 (2 件)
Image Analyst
2014 年 9 月 8 日
Draw lines around the border of your binary image:
binaryImage(:,1) = true;
binaryImage(:,end) = true;
binaryImage(1,:) = true;
binaryImage(end,:) = true;
Now do a fill to fill the region between the border and the body.
binaryImage = imfill(binaryImage, 'holes');
Now do an imclearborder to get rid of all that and leave just the lung edges
binaryImage = imclearborder(binaryImage);
Now do a fill again to get the lungs filled.
lungsMask = imfill(binaryImage, 'holes');
And you're basically done. If there is any small blobs remaining, use my ExtractNLargestBlobs function (attached) to extract just the 2 largest blobs, which will be the lungs.
14 件のコメント
Image Analyst
2014 年 9 月 8 日
sara: Try the m-file attached below this image that it creates:

sara
2014 年 9 月 9 日
編集済み: Image Analyst
2014 年 9 月 9 日
Image Analyst
2014 年 9 月 9 日
There is no reason why my code, or yours, should not read in a jpg image and use it the way we coded. For your code, what does this show in the command window:
recalledImage = imread('fullFileName.tiff');
min(recalledImage) % No semicolon.
max(recalledImage)
Image Analyst
2014 年 9 月 9 日
So it's a 16 bit image. Why is it all black? Where is it all black? Because when we see that the max is around 65 thousand, that's clearly not saying it's all black. Attach your tiff image.
sara
2014 年 9 月 9 日
sara
2014 年 9 月 10 日
Image Analyst
2014 年 9 月 11 日
編集済み: Image Analyst
2014 年 9 月 11 日
You'll have to come up with a way to threshold it properly, but other than that it should work. I don't know why you have jpg images though. Who degraded the original images by storing as jpg? And WHY? Why do that? It's best to do image analysis on high quality images, not ones with compression artifacts in them.
Do you think the answer was good enough for you to officially "Accept"?
Image Analyst
2014 年 9 月 12 日
It should not be too hard since there should be a huge hump around black. Let me know if you have trouble.
Image Analyst
2014 年 9 月 14 日
It's not a "hole" but more of a "bay" because that region is actually a white region that is an incursion from the bright outer body into the lung. If you want to smooth the boundary you need to use active contours. This will "cut off" that bay. I'm attaching an example.
sara
2014 年 9 月 11 日
0 投票
2 件のコメント
Salma Hassan
2017 年 5 月 20 日
how did you get figure 4 (lungs only )
Image Analyst
2017 年 5 月 20 日
カテゴリ
ヘルプ センター および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


