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
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
sara 2014년 9월 8일
hi Sean
my original image is .tif so I attach this in a .zip
thanks

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2014년 9월 8일

2 개 추천

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

sara
sara 2014년 9월 8일
편집: sara 2014년 9월 8일
thanks Image Analyst
but when I do this.I see just a white Square.
Image Analyst is the type of image that I use important?e.g .tif ot .jpg
my original image is .tif so I attach this.
sara: Try the m-file attached below this image that it creates:
sara
sara 2014년 9월 9일
편집: Image Analyst 2014년 9월 9일
Thanks Image Analyst
You are Fantastic
The code that I put above works for .jpg images and the code that you put works for .tif. Is there any way that help me to merge those to work for every type of images??because the code that you put when I use .jpg does not work. And the code that I put when my image is .tif does not work.
I try to use :
grayImage = imread(fullFileName);
imwrite(grayImage, 'fullFileName.tiff');
to convert this code to a program that can works for .jpg images but it just give me a black image.
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)
sara
sara 2014년 9월 9일
편집: sara 2014년 9월 9일
for min it gives me a Horizontal vector 1*512 that all of the values are zero.. and max gives me a Horizontal vector 1*512 that the values are different :for example 65535 , ...
you mean that the code that you gave me should works for .jpg images too?
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
sara 2014년 9월 9일
I said your code is very good for .tif but when I want to use this image that is .jpg all screan is black.I use im2bw() before giving image but the result is black.I put this image
sara
sara 2014년 9월 9일
편집: sara 2014년 9월 9일
I attach .tif but code is run correctly for this and result is this:
sara
sara 2014년 9월 10일
Image Analyst
my .tif's class is uint16 and my jpg class is uint8... is this difference make bad result for .jpg image??
Image Analyst
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"?
sara
sara 2014년 9월 12일
편집: sara 2014년 9월 12일
so should I find a way that give me the best threshold?
yes you are right It's best to do image analysis on high quality images, not ones with compression artifacts in them.
thanks
Image Analyst
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.
sara
sara 2014년 9월 14일
편집: sara 2014년 9월 14일
hi Image Analyst
I thouth our code is correct for every thing but when I tested it for this image that I attached I understood that the lung result should not have any holes but if you see this image and the result you can see in the bottom and left side of this lung we have a big hole...do you agree with me that if before using ExtractNLargestBlobs we use a circle mask the result can be better?
Image Analyst
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
sara 2014년 9월 11일

0 개 추천

hi Image Analyst I use otsu method instead of <45000 in this code and it gave me a good result I attach this.

댓글 수: 2

Salma Hassan
Salma Hassan 2017년 5월 20일
how did you get figure 4 (lungs only )
Image Analyst
Image Analyst 2017년 5월 20일
Who are you asking? I gave my code above in this post: click here

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Convert Image Type에 대해 자세히 알아보기

질문:

2014년 9월 8일

댓글:

2017년 5월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by