Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
CT image

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 11:26:04

Message: 1 of 36

I have a question regarding extraction of lungs from CT image. Right now I am working with jpg images extracted from PACS.
I did region filling on CT image and got lungs extracted, than I find the edge of both lung, but I cannot get rid of rest of the lung tissue outside the lungs, I only want to keed the morphology inside the lung. Is imcrop solution for this?
1. So, first image is CT thorax
2. I have lungs extracted with region filling
3. Find the edge of lungs
4. I want to only keep whats inside the lungs, and get rid of rest of outside tissue, mediastinum, bones, etc...

Any solution for step #4?

Any other solution is helpful.
Also, I would like to thanks to ImageAnalyst for being alive, your comments are more that great!

Subject: CT image

From: ImageAnalyst

Date: 22 Oct, 2010 13:49:57

Message: 2 of 36

Thanks for the compliment. Sorry I can't help you more, even though I
work with industrial CT images (among lots of other modalities) every
week. You would need to provide an image for anyone to make any
suggestions. You could also try sci.image.processing - it's been
nearly destroyed by spam but there are several sharp people there who
monitor the posts and are quite helpful. Biomedical images are
notoriously difficult to segment things out of. There are literally
thousands of papers on CT segmentation so I'm sure someone has done
this before. For example, look to
http://iris.usc.edu/Vision-Notes/bibliography/contentsmedical.html#Medical%20Applications,%20CAT,%20MRI,%20Ultrasound,%20Heart%20Models,%20Brain%20Models
which is a list of virtually all medical image processing papers.
Particularly look to section
"20.7.2 Lungs, and Lung Cancer Image Analysis"

But I do know that imcrop won't help you since the lungs can't be
accurately cut out of the body using a box, which is what imcrop
uses. Lungs are not a box shape they are more amorphous.
-ImageAnalyst

Subject: CT image

From: Sean

Date: 22 Oct, 2010 14:10:05

Message: 3 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9rscb$7kh$1@fred.mathworks.com>...
> I have a question regarding extraction of lungs from CT image. Right now I am working with jpg images extracted from PACS.
> I did region filling on CT image and got lungs extracted, than I find the edge of both lung, but I cannot get rid of rest of the lung tissue outside the lungs, I only want to keed the morphology inside the lung. Is imcrop solution for this?
> 1. So, first image is CT thorax
> 2. I have lungs extracted with region filling
> 3. Find the edge of lungs
> 4. I want to only keep whats inside the lungs, and get rid of rest of outside tissue, mediastinum, bones, etc...
>
> Any solution for step #4?
>
> Any other solution is helpful.
> Also, I would like to thanks to ImageAnalyst for being alive, your comments are more that great!

Could you post a few of the (2d) jpgs or a .mat file with them combined in the 3rd dimension to http://drop.io

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 14:32:04

Message: 4 of 36

Thanks for the reply.
I will check the links that you posted.
These are my images.

http://drop.io/CTExtracted
Actualy, I am trying to extract lungs with all the morphology inside, and get rid of everything outside the edge image.

Any solution?

Subject: CT image

From: Matt J

Date: 22 Oct, 2010 14:32:04

Message: 5 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9rscb$7kh$1@fred.mathworks.com>...
> I have a question regarding extraction of lungs from CT image. Right now I am working with jpg images extracted from PACS.
> I did region filling on CT image and got lungs extracted, than I find the edge of both lung, but I cannot get rid of rest of the lung tissue outside the lungs, I only want to keed the morphology inside the lung. Is imcrop solution for this?
> 1. So, first image is CT thorax
> 2. I have lungs extracted with region filling
> 3. Find the edge of lungs
==========

You might have to clarify more in what form you have these regions expressed. The best I can assume from (2.) is that you have a binary map BW1 of the entire lung and from (3.) that you have a binary map BW2 of just its edges. In that case, a map of the interior of the lung is derivable simply as

LungInterior= BW1 & ~BW2

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 14:41:05

Message: 6 of 36

Matt, I tried this, but I just dont get the results that I want, morphology inside the lungs are missing.
Please check the images, maybe it will be clearer.

Thanks in advance.

Subject: CT image

From: Sean

Date: 22 Oct, 2010 14:58:03

Message: 7 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9s794$l7v$1@fred.mathworks.com>...
> Thanks for the reply.
> I will check the links that you posted.
> These are my images.
>
> http://drop.io/CTExtracted
> Actualy, I am trying to extract lungs with all the morphology inside, and get rid of everything outside the edge image.
>
> Any solution?

So you have the two images: edgepasa and pasaedge.

wholepasa = imfill(pasaedge,'holes');
internalpasa = imfill(edgepada,'holes');

Map = xor(wholepasa,internalpasa);
%or
Map = wholepasa&(~internalpasa); %As Matt said I believe.

Subject: CT image

From: Matt J

Date: 22 Oct, 2010 15:02:04

Message: 8 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9s7q1$pm2$1@fred.mathworks.com>...
> Matt, I tried this, but I just dont get the results that I want, morphology inside the lungs are missing.
> Please check the images, maybe it will be clearer.
=======

No, it isn't. You said you had a map of the complete extracted lung (from step 2). Your dropbox however contains edge maps only.

If you don't have a map of the complete region of the lung, try using IMFILL on EdgePasa to obtain it.

Subject: CT image

From: Sean

Date: 22 Oct, 2010 15:04:03

Message: 9 of 36

> wholepasa = imfill(pasaedge,'holes');
> internalpasa = imfill(edgepada,'holes');
>
> Map = xor(wholepasa,internalpasa);
> %or
> Map = wholepasa&(~internalpasa); %As Matt said I believe.

Then apply the map to the original image with
original(~Map) = 0;
%or
original = uint8(Map).*original;

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:07:05

Message: 10 of 36

Sean,
I tried it, the results are just too bad. There are medical images, I cannot get blurry result.
I am trying to extract the lungs with the internal morphology.

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:14:04

Message: 11 of 36

I tried that too, but the result is horrible. Everything is blurry...
The thing that I want is, something like superimpose images only of the edge lungs (EdgePasa.jpg) over Pasa0.jpg, and then have only one image (similar to EdgePasa.jpg) with everyhing inside of the lungs.

Subject: CT image

From: Sean

Date: 22 Oct, 2010 15:15:07

Message: 12 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9s9ap$5bd$1@fred.mathworks.com>...
> Sean,
> I tried it, the results are just too bad. There are medical images, I cannot get blurry result.
> I am trying to extract the lungs with the internal morphology.

How are the results bad? I guess I don't totally understand what you want. Do you want _everything_ inside the pasaedge image? Post the results, and why you don't like them.

Subject: CT image

From: Matt J

Date: 22 Oct, 2010 15:20:05

Message: 13 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9s9ap$5bd$1@fred.mathworks.com>...
> Sean,
> I tried it, the results are just too bad. There are medical images, I cannot get blurry result.
======

Well nothing we've proposed introduces the blur you are seeing. It just sets pixels outside the lung to zero. If you have a debluring problem, try DECONVREG.

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:23:04

Message: 14 of 36

Sean,
this is what I get....Check for the PasaMap.jpg image.
I dont have anything inside, no parenchyma, and everything is boxy...

Subject: CT image

From: Sean

Date: 22 Oct, 2010 15:28:03

Message: 15 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9s9nr$1ul$1@fred.mathworks.com>...
> I tried that too, but the result is horrible. Everything is blurry...
> The thing that I want is, something like superimpose images only of the edge lungs (EdgePasa.jpg) over Pasa0.jpg, and then have only one image (similar to EdgePasa.jpg) with everyhing inside of the lungs.


If you just want to superimpose the edge on the original then:
paso0(EdgePasa) = 255; %if they're 8bit. If they're 16 bit then 2^16-1 instead of 255.

However I think we're missing something.

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:33:03

Message: 16 of 36

Sean, Matt,
I only want to extract EdgePasa.jpg from the original CT image, with everything inside.
When I try your code, that is just not it - I get the PasaMap.jpg image.

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:35:04

Message: 17 of 36

Superimposing will not help, I tried that before. I need to extract whats inside the lungs from the original image.

Subject: CT image

From: ImageAnalyst

Date: 22 Oct, 2010 15:41:54

Message: 18 of 36

On Oct 22, 10:32 am, "privatemeet none" <privatem...@yahoo.com> wrote:
> Thanks for the reply.
> I will check the links that you posted.
> These are my images.
>
> http://drop.io/CTExtracted
> Actualy, I am trying to extract lungs with all the morphology inside, and get rid of everything outside the edge image.
>
> Any solution?

--------------------------------------------------------
What morphology? Is Pasa0.jpg your original image? The lungs look
totally black inside. Did you already zero them out somehow?

Anyway, assuming it is the original, why can't you just use your
EdgePasa image and use imfill on it and multiply it by your original
image to get just the lungs with everything outside zeroed out? (Like
Matt J suggested) Something like (untested):
maskImage = imfill(edgepasa, 'holes'); % Fill holes.
maskImage = cast(maskImage, class(pasa0)); % Match integer types
maskedImage = paso0 .* maskImage; % Do the masking.

Subject: CT image

From: privatemeet none

Date: 22 Oct, 2010 15:59:04

Message: 19 of 36

Dear ImageAnallyst,
you are just a genius!

I newer thought of it, and it is working. I just couldnt see a solution from all the code I was typing in.

Thanks ImageAnalyst!
Thanks Matt!
Thanks Sean!

P.S. I will continue to with my research, and if I have some problems, is it OK to contact you guys again?

Subject: CT image

From: Sean

Date: 22 Oct, 2010 16:04:04

Message: 20 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <i9scc8$sl8$1@fred.mathworks.com>...
> Dear ImageAnallyst,
> you are just a genius!
>
> I newer thought of it, and it is working. I just couldnt see a solution from all the code I was typing in.
>
> Thanks ImageAnalyst!
> Thanks Matt!
> Thanks Sean!
>
> P.S. I will continue to with my research, and if I have some problems, is it OK to contact you guys again?

You're welcome, and please post here again. It's valuable for everyone who reads it.

Subject: CT image

From: Matt J

Date: 22 Oct, 2010 16:23:04

Message: 21 of 36

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <cfd4e67c-4af6-47e7-ad08-9bfd7dbd8ad5@a37g2000yqi.googlegroups.com>...
>
> --------------------------------------------------------
> What morphology? Is Pasa0.jpg your original image? The lungs look
> totally black inside. Did you already zero them out somehow?
>
> Anyway, assuming it is the original, why can't you just use your
> EdgePasa image and use imfill on it and multiply it by your original
> image to get just the lungs with everything outside zeroed out? (Like
> Matt J suggested) Something like (untested):
> maskImage = imfill(edgepasa, 'holes'); % Fill holes.
> maskImage = cast(maskImage, class(pasa0)); % Match integer types
> maskedImage = paso0 .* maskImage; % Do the masking.
===============

The following actually trims out the lung boundaries a bit better. I've posted theResult in the dropbox.


pasa0=double(rgb2gray(imread('Pasa0.jpg')));
edgepasa=logical(imread('EdgePasa.jpg'));

LungMap=imfill(edgepasa,'holes');
LungMap=imdilate(LungMap,ones(3));

tmp=LungMap.*pasa0;

LungMap=imfill(tmp,'holes').*(tmp<10); %Empirical threshold
LungMap=imdilate(LungMap,ones(2));
LungMap=logical(LungMap);
LungMap=imfill(LungMap,'holes');

theResult=LungMap.*pasa0;

Subject: CT image

From: privatemeet none

Date: 26 Oct, 2010 10:11:03

Message: 22 of 36

Actually Matt, I am getting a lot of blobs inside the lungs when I tried the code, did you get that when you tried?

Rgds

Subject: CT image

From: Matt J

Date: 26 Oct, 2010 13:09:04

Message: 23 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <ia69fn$q96$1@fred.mathworks.com>...
> Actually Matt, I am getting a lot of blobs inside the lungs when I tried the code, did you get that when you tried?
=======

Again, I uploaded the result I obtained to your dropbox. You'll have to be the judge of whether that's what you want. I don't believe that the code introduced anything inside the lungs that wasn't there before, if that's what you're asking.

Subject: CT image

From: privatemeet none

Date: 27 Oct, 2010 06:02:07

Message: 24 of 36

Matt,
the code that I tried gives me the morphology inside, but my image was too black from the begining. When I ectract other image from the PACS, I got the result that I want. Thanks.

One more question.
I need to calculate the surface (area) of ther lungs (Image EdgePasa.jpg). Something like height*weight.
Is the best way to use bwarea or something else?

Thanks in advance

Subject: CT image

From: Matt J

Date: 27 Oct, 2010 11:14:05

Message: 25 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <ia8f8v$m2n$1@fred.mathworks.com>...
> Matt,
> the code that I tried gives me the morphology inside, but my image was too black from the begining. When I ectract other image from the PACS, I got the result that I want. Thanks.
>
> One more question.
> I need to calculate the surface (area) of ther lungs (Image EdgePasa.jpg). Something like height*weight.
> Is the best way to use bwarea or something else?
======

If it's a 2D image EdgePasa.jpg, it will be a perimeter, not surface area. You can use bwperim.

Subject: CT image

From: privatemeet none

Date: 27 Oct, 2010 12:17:04

Message: 26 of 36

Thanks Matt!

Subject: CT image

From: privatemeet none

Date: 27 Oct, 2010 12:22:04

Message: 27 of 36

Is there a posibility to get area for the lungs extracted with bwperim? For example, area of the lungs is 47sq. cm?

Subject: CT image

From: Matt J

Date: 27 Oct, 2010 14:00:05

Message: 28 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <ia95hc$7eg$1@fred.mathworks.com>...
> Is there a posibility to get area for the lungs extracted with bwperim? For example, area of the lungs is 47sq. cm?
============

No, I don't think so. You'll first have to develop a surface map from EdgePasa over all slices. Then you might use delaunay() to triangulate the surface and count up the areas of all the triangles.

Subject: CT image

From: privatemeet none

Date: 28 Oct, 2010 14:15:07

Message: 29 of 36

Dear Matt, can you check the image imgKika, with the red area of the lungs? I am trying to get an area of the lungs segmented from my image? is there no chance to get an area of the red surface??

Subject: CT image

From: Matt J

Date: 28 Oct, 2010 15:42:05

Message: 30 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <iac0hb$ldl$1@fred.mathworks.com>...
> Dear Matt, can you check the image imgKika, with the red area of the lungs? I am trying to get an area of the lungs segmented from my image? is there no chance to get an area of the red surface??
===========

OK. well when you said 'surface area', it confused me. The area shown in imgKika is a 2D cross-sectional area of the lung's interior, not its surface.

Yes, you can use bwarea, or possibly regionprops(...,'Area') depending on how you like the area computed.

Subject: CT image

From: privatemeet none

Date: 28 Oct, 2010 20:34:03

Message: 31 of 36

"Matt J " <mattjacREMOVE@THISieee.spam> wrote in message <iac5kd$3o2$1@fred.mathworks.com>...
> "privatemeet none" <privatemeet@yahoo.com> wrote in message <iac0hb$ldl$1@fred.mathworks.com>...
> > Dear Matt, can you check the image imgKika, with the red area of the lungs? I am trying to get an area of the lungs segmented from my image? is there no chance to get an area of the red surface??
> ===========
>
> OK. well when you said 'surface area', it confused me. The area shown in imgKika is a 2D cross-sectional area of the lung's interior, not its surface.
>
> Yes, you can use bwarea, or possibly regionprops(...,'Area') depending on how you like the area computed.
Thanks a lot!

Subject: CT image

From: privatemeet none

Date: 29 Oct, 2010 07:32:03

Message: 32 of 36

I need help with area calculation. Look at these images. Obviously Big.jpg is bigger than Small.jpg. However, when I calculate bwarea on the images, I get the result that the smaller one is bigger than the big one.
Big = 1.1095e+005
Small = 1.137e+005
http://drop.io/CTExtracted

What am I missing????

Subject: CT image

From: Sean

Date: 29 Oct, 2010 12:40:04

Message: 33 of 36

"privatemeet none" <privatemeet@yahoo.com> wrote in message <iadt9j$8ak$1@fred.mathworks.com>...
> I need help with area calculation. Look at these images. Obviously Big.jpg is bigger than Small.jpg. However, when I calculate bwarea on the images, I get the result that the smaller one is bigger than the big one.
> Big = 1.1095e+005
> Small = 1.137e+005
> http://drop.io/CTExtracted
>
> What am I missing????

When I run this:
%%%%%%
 I = imread('/users/sean/downloads/big.jpg');

>> I = I./255;
>> sum(I(:))

ans =

      100462

>> I = imread('/users/sean/downloads/small.jpg');
>> I = I./255;
>> sum(I(:))

ans =

       85007
%%%%%
I get the smaller one being smaller and the bigger one being bigger. The BWAREA results aren't much different.

I believe your problem is that: though your image looks like binary it is actually uint8; so the white areas are valued at 255. BWAREA expects binary images.

Subject: CT image

From: privatemeet none

Date: 29 Oct, 2010 13:22:03

Message: 34 of 36

Thanks for the reply, I will check it right now.

Subject: CT image

From: tenaya santika

Date: 12 Nov, 2013 08:45:53

Message: 35 of 36

Hi Privatemeet none~

How about the rest, to solve problem on 1,2,and 3 itself ?!
Its seems i need to learn from you and other, (since we are in similar cases i guess, except i just beginning of my work) - on segmentation especially.

Thank you!~

santika

Subject: CT image

From: tenaya santika

Date: 12 Nov, 2013 08:48:28

Message: 36 of 36

Hi ImageAnalyst,

I have observe some the links, its really useful thought i need more focus on
Lung CT Segmentation, "Spicule and Lobulation" cases. In case do you have some more strong references and various sources code to learn by.

Thank you!~

santika

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us