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:
removing every thing but the lungs boundaries

Subject: removing every thing but the lungs boundaries

From: nancy

Date: 30 Mar, 2011 20:22:05

Message: 1 of 12

  i am processing a CT image of the lungs i manged to extract the boundaries of the lungs but the problem is that the extraction results in some white dots scattered randomly around the lungs. i have been trying to remove these pixels and i am running out of ideas can anyone plz urgently help me with that.

Subject: removing every thing but the lungs boundaries

From: Matt J

Date: 30 Mar, 2011 20:39:05

Message: 2 of 12

"nancy" wrote in message <in03dc$7ff$1@fred.mathworks.com>...
> i am processing a CT image of the lungs i manged to extract the boundaries of the lungs but the problem is that the extraction results in some white dots scattered randomly around the lungs. i have been trying to remove these pixels and i am running out of ideas can anyone plz urgently help me with that.
=============

Sounds like it calls for IMERODE

Subject: removing every thing but the lungs boundaries

From: nancy

Date: 30 Mar, 2011 20:54:04

Message: 3 of 12

"Matt J" wrote in message <in04d9$ofq$1@fred.mathworks.com>...
> "nancy" wrote in message <in03dc$7ff$1@fred.mathworks.com>...
> > i am processing a CT image of the lungs i manged to extract the boundaries of the lungs but the problem is that the extraction results in some white dots scattered randomly around the lungs. i have been trying to remove these pixels and i am running out of ideas can anyone plz urgently help me with that.
> =============
>
> Sounds like it calls for IMERODE

 i preformed the imerode but it didnt remove them all here is the code would you plz help me with it



k=imread('C:\Users\sarah\Pictures\CT0050.bmp');
%calculating the size of the image and transforming it from a 3d image to
%2d and calaculating and plotting thr histogram
[m,n]=size(k);
b4=ndims(k);
f=rgb2gray(k);
after=ndims(f);
%figure;imshow(f)
%h=imhist(f);
%figure;stairs(h)

se=strel('diamond',20);
a3=imerode(f,se);
a4=imopen(a3,se);
d1=imreconstruct(a3,f);
[g,t]=edge(d1,'sobel','both');
%figure;imshow(g)
d2=imclearborder(g,8);
figure;imshow(d2);
labeledimage=bwlabel(d2,8);
circles= regionprops(labeledimage,'all');
numberOfcircles = size(circles);
bound=bwboundaries(labeledimage);


    
    
    

savedPrim=size(circles);
cP=size(circles);
level=255*graythresh(labeledimage);



for h = 1 : numberOfcircles
    
    cP(h)=circles(h).Perimeter;
    if cP(h)>=level
    savedPrim(h)=cP(h);
    end
end

OP=sort(savedPerim,'descend');
RangeMax=max(OP(:));

for j= 2: length(OP)+1
    if (OP(j-1)~=0 && OP(j+1)==0)
        RangeMin=OP(j);
    end
    if (RangeMin<40)
        RangeMin=RangeMin+10;
    end
    
end

savedArea=size(circles);
averageArea=mean(AreasTotal1);


for h = 1 : numberOfcircles
    
    cA=circles(h).Area;
    
    if cA>=level
        savedArea(h)=cA;
    end
   
end



RangeMaxA=max(savedArea(:));


for l= 2: length(savedArea)-1
    if (savedArea(l-1)~=0 && savedArea(l+1)==0)
        RangeMinA=savedArea(l);
    end
    if (RangeMinA<35)
        RangeMinA=RangeMinA+10;
    end
    
end
cleaned=labeledimage;

for region=1:numberOfcircles
    if (circles(region).Area<RangeMinA) && (circles(region).Perimeter<RangeMin)
        cleaned(circles(region).PixelIdxList)=0;
    end
end


AreasTotal1 = [circles.Area];
CPTotal = [circles.Perimeter];
organizedPerim=find(CPTotal<=RangeMin & AreasTotal1<=RangeMinA);
counter=length(organizedPerim);
cleanedImage=labeledimage;

for i= 1 : counter

      cleaned(labeledimage==organizedPerim(i))=0;
   
end



figure;imshow(cleaned)

Subject: removing every thing but the lungs boundaries

From: ImageAnalyst

Date: 31 Mar, 2011 02:12:07

Message: 4 of 12

You forgot to include the URL to your image. No one can try this with
your image unless you post your image somewhere (on your favorite file
hosting web site, preferably one where we can immediately see the
image with no additional clicks, and where we can also download it
easily).

Subject: removing every thing but the lungs boundaries

From: nancy

Date: 31 Mar, 2011 08:43:04

Message: 5 of 12

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c4f6c509-39fe-471f-bdd5-3181a9c37b72@y31g2000vbp.googlegroups.com>...
> You forgot to include the URL to your image. No one can try this with
> your image unless you post your image somewhere (on your favorite file
> hosting web site, preferably one where we can immediately see the
> image with no additional clicks, and where we can also download it
> easily).



thnx ImageAnalyst here is the URL:http://www.4shared.com/photo/OX5uGJZV/CT0020.html

Subject: removing every thing but the lungs boundaries

From: Sean de

Date: 31 Mar, 2011 13:46:05

Message: 6 of 12

"nancy" wrote in message <in1eqo$8ng$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <c4f6c509-39fe-471f-bdd5-3181a9c37b72@y31g2000vbp.googlegroups.com>...
> > You forgot to include the URL to your image. No one can try this with
> > your image unless you post your image somewhere (on your favorite file
> > hosting web site, preferably one where we can immediately see the
> > image with no additional clicks, and where we can also download it
> > easily).
>
>
>
> thnx ImageAnalyst here is the URL:http://www.4shared.com/photo/OX5uGJZV/CT0020.html

In one shot:
%%%
I = imread('CT0020.bmp');
I = I(:,:,1);

M = shrinkWrap(I,'objthresh',3000,'biggest'); %Mask

imshow(uint8(M).*I); %view

http://www.mathworks.com/matlabcentral/fileexchange/?term=shrinkWrap

Subject: removing every thing but the lungs boundaries

From: Sean de

Date: 31 Mar, 2011 13:52:05

Message: 7 of 12

"Sean de " <sean.dewolski@nospamplease.umit.maine.edu> wrote in message
> In one shot:
> %%%
> I = imread('CT0020.bmp');
> I = I(:,:,1);
>
> M = shrinkWrap(I,'objthresh',3000,'biggest'); %Mask
>
> imshow(uint8(M).*I); %view
>
> http://www.mathworks.com/matlabcentral/fileexchange/?term=shrinkWrap

I'm sorry, you wanted the edge:
%%%
[M, Me] = shrinkWrap(I,'objthresh',3000,'biggest'); %Mask
imshow(uint8(Me).*I); %view

Subject: removing every thing but the lungs boundaries

From: ImageAnalyst

Date: 31 Mar, 2011 15:09:16

Message: 8 of 12

Sean:
That extracts just the outer body. She wanted the two lungs without
the bright objects in them. The code below will do that.

nancy:
Copy, paste, fix line breaks, fix folder location to represent the
folder where your image lives, then run.


% IMPORTANT: The newsreader may break long lines into multiple lines.
% Be sure to join any long lines that got split into multiple single
lines.
% These can be found by the red lines on the left side of your
% text editor, which indicate syntax errors, or else just run the
% code and it will stop at the split lines with an error.
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures.
clear; % Erase all existing variables.
workspace; % Make sure the workspace panel is showing.
fontSize = 14;

% Change the current folder to the folder of this m-file.
if(~isdeployed)
cd(fileparts(which(mfilename)));
end

% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
        % User does not have the toolbox installed.
        message = sprintf('Sorry, but you do not seem to have the
Image Processing Toolbox.\nDo you want to try to continue anyway?');
        reply = questdlg(message, 'Toolbox missing', 'Yes', 'No',
'Yes');
        if strcmpi(reply, 'No')
                % User said No, so exit.
                return;
        end
end
% Read in a standard MATLAB gray scale demo image.
folder = 'C:\Documents and Settings\user\My Documents\Downloads';
baseFileName = 'CT0020.bmp';
fullFileName = fullfile(folder, baseFileName);
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 1.
[rows columns numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
grayImage = rgb2gray(grayImage);
end
% Display the original gray scale image.
subplot(3, 3, 1);
imshow(grayImage, []);
title('Original Grayscale Image', 'FontSize', fontSize);
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')

% Let's compute and display the histogram.
[pixelCount grayLevels] = imhist(grayImage);
subplot(3, 3, 2);
bar(pixelCount);
title('Histogram of original image', 'FontSize', fontSize);
xlim([0 grayLevels(end)]); % Scale x axis manually.

binaryImage = grayImage < 150;
% Display the image.
subplot(3, 3, 3);
imshow(binaryImage, []);
title('Binary Image', 'FontSize', fontSize);

% Remove objects touching the border
binaryImage = imclearborder(binaryImage);
% Display the image.
subplot(3, 3, 4);
imshow(binaryImage, []);
title('Border cleared', 'FontSize', fontSize);

% Fill the blobs and take the largest two
binaryImage = imfill(binaryImage, 'holes');
% Label each blob so we can make measurements of it
[labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
% Get all the blob properties. Can only pass in originalImage in
version R2008a and later.
blobMeasurements = regionprops(labeledImage, grayImage, 'all');
% Now I'll demonstrate how to select certain blobs based using the
ismember function.
allBlobAreas = [blobMeasurements.Area];
[sortedAreas sortedIndexes] = sort(allBlobAreas, 'descend');

% Get a list of the blobs that meet our criteria and we need to keep.
keeperIndexes = sortedIndexes(1:2);
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% keeperBlobsImage now has values of 2 and 5 which are the blob
numbers.
% Binarize is
keeperBlobsImage = keeperBlobsImage > 0;
% Now we're done. We have a labeled image of blobs that meet our
specified criteria.
subplot(3, 3, 5);
imshow(keeperBlobsImage, []);
title('Lungs Mask', 'FontSize', fontSize);

% Now make measurements of the extracted lungs.
% Re-label with only the keeper blobs kept.
labeledLungImage = bwlabel(keeperBlobsImage, 8); % Label each blob
so we can make measurements of it
% Get all the blob properties. Can only pass in originalImage in
version R2008a and later.
blobMeasurements = regionprops(labeledLungImage, grayImage, 'all');

% Mask the lungs out of the original image.
lungsOnly = grayImage .* uint8(keeperBlobsImage);
subplot(3, 3, 6);
imshow(lungsOnly, [0 255]);
title('Lungs extracted', 'FontSize', fontSize);

% Get the small bright things in the lungs
binaryImage = lungsOnly > 125;
subplot(3, 3, 7);
imshow(binaryImage, []);
title('Bright Objects in Lungs', 'FontSize', fontSize);

% Get an image of only the lungs without the bright objects in it.
lungsOnly(binaryImage) = 0;
subplot(3, 3, 8);
imshow(lungsOnly, [0 255]);
title('Lungs with no bright objects', 'FontSize', fontSize);

msgbox('Done');

Subject: removing every thing but the lungs boundaries

From: nancy

Date: 1 Apr, 2011 10:29:04

Message: 9 of 12

ImageAnalyst <imageanalyst@mailinator.com> wrote in message <81c0e3fb-5e6d-41f1-be78-f0fc30551595@r6g2000vbo.googlegroups.com>...
> Sean:
> That extracts just the outer body. She wanted the two lungs without
> the bright objects in them. The code below will do that.
>
> nancy:
> Copy, paste, fix line breaks, fix folder location to represent the
> folder where your image lives, then run.
>
>
> % IMPORTANT: The newsreader may break long lines into multiple lines.
> % Be sure to join any long lines that got split into multiple single
> lines.
> % These can be found by the red lines on the left side of your
> % text editor, which indicate syntax errors, or else just run the
> % code and it will stop at the split lines with an error.
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 14;
>
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> % Check that user has the Image Processing Toolbox installed.
> hasIPT = license('test', 'image_toolbox');
> if ~hasIPT
> % User does not have the toolbox installed.
> message = sprintf('Sorry, but you do not seem to have the
> Image Processing Toolbox.\nDo you want to try to continue anyway?');
> reply = questdlg(message, 'Toolbox missing', 'Yes', 'No',
> 'Yes');
> if strcmpi(reply, 'No')
> % User said No, so exit.
> return;
> end
> end
> % Read in a standard MATLAB gray scale demo image.
> folder = 'C:\Documents and Settings\user\My Documents\Downloads';
> baseFileName = 'CT0020.bmp';
> fullFileName = fullfile(folder, baseFileName);
> % Get the full filename, with path prepended.
> fullFileName = fullfile(folder, baseFileName);
> if ~exist(fullFileName, 'file')
> % Didn't find it there. Check the search path for it.
> fullFileName = baseFileName; % No path this time.
> if ~exist(fullFileName, 'file')
> % Still didn't find it. Alert user.
> errorMessage = sprintf('Error: %s does not exist.', fullFileName);
> uiwait(warndlg(errorMessage));
> return;
> end
> end
> grayImage = imread(fullFileName);
> % Get the dimensions of the image. numberOfColorBands should be = 1.
> [rows columns numberOfColorBands] = size(grayImage);
> if numberOfColorBands > 1
> grayImage = rgb2gray(grayImage);
> end
> % Display the original gray scale image.
> subplot(3, 3, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', fontSize);
> % Enlarge figure to full screen.
> set(gcf, 'Position', get(0,'Screensize'));
> set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
>
> % Let's compute and display the histogram.
> [pixelCount grayLevels] = imhist(grayImage);
> subplot(3, 3, 2);
> bar(pixelCount);
> title('Histogram of original image', 'FontSize', fontSize);
> xlim([0 grayLevels(end)]); % Scale x axis manually.
>
> binaryImage = grayImage < 150;
> % Display the image.
> subplot(3, 3, 3);
> imshow(binaryImage, []);
> title('Binary Image', 'FontSize', fontSize);
>
> % Remove objects touching the border
> binaryImage = imclearborder(binaryImage);
> % Display the image.
> subplot(3, 3, 4);
> imshow(binaryImage, []);
> title('Border cleared', 'FontSize', fontSize);
>
> % Fill the blobs and take the largest two
> binaryImage = imfill(binaryImage, 'holes');
> % Label each blob so we can make measurements of it
> [labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledImage, grayImage, 'all');
> % Now I'll demonstrate how to select certain blobs based using the
> ismember function.
> allBlobAreas = [blobMeasurements.Area];
> [sortedAreas sortedIndexes] = sort(allBlobAreas, 'descend');
>
> % Get a list of the blobs that meet our criteria and we need to keep.
> keeperIndexes = sortedIndexes(1:2);
> % Extract only those blobs that meet our criteria, and
> % eliminate those blobs that don't meet our criteria.
> % Note how we use ismember() to do this.
> keeperBlobsImage = ismember(labeledImage, keeperIndexes);
> % keeperBlobsImage now has values of 2 and 5 which are the blob
> numbers.
> % Binarize is
> keeperBlobsImage = keeperBlobsImage > 0;
> % Now we're done. We have a labeled image of blobs that meet our
> specified criteria.
> subplot(3, 3, 5);
> imshow(keeperBlobsImage, []);
> title('Lungs Mask', 'FontSize', fontSize);
>
> % Now make measurements of the extracted lungs.
> % Re-label with only the keeper blobs kept.
> labeledLungImage = bwlabel(keeperBlobsImage, 8); % Label each blob
> so we can make measurements of it
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledLungImage, grayImage, 'all');
>
> % Mask the lungs out of the original image.
> lungsOnly = grayImage .* uint8(keeperBlobsImage);
> subplot(3, 3, 6);
> imshow(lungsOnly, [0 255]);
> title('Lungs extracted', 'FontSize', fontSize);
>
> % Get the small bright things in the lungs
> binaryImage = lungsOnly > 125;
> subplot(3, 3, 7);
> imshow(binaryImage, []);
> title('Bright Objects in Lungs', 'FontSize', fontSize);
>
> % Get an image of only the lungs without the bright objects in it.
> lungsOnly(binaryImage) = 0;
> subplot(3, 3, 8);
> imshow(lungsOnly, [0 255]);
> title('Lungs with no bright objects', 'FontSize', fontSize);
>
> msgbox('Done');




ImageAnalyst:
 Thanks a lot its working on all the images that i have. thank you really i appreciate your help.

Subject: removing every thing but the lungs boundaries

From: nancy

Date: 1 Apr, 2011 15:38:04

Message: 10 of 12

"nancy" wrote in message <in49dg$odd$1@fred.mathworks.com>...
> ImageAnalyst <imageanalyst@mailinator.com> wrote in message <81c0e3fb-5e6d-41f1-be78-f0fc30551595@r6g2000vbo.googlegroups.com>...
> > Sean:
> > That extracts just the outer body. She wanted the two lungs without
> > the bright objects in them. The code below will do that.
> >
> > nancy:
> > Copy, paste, fix line breaks, fix folder location to represent the
> > folder where your image lives, then run.
> >
> >
> > % IMPORTANT: The newsreader may break long lines into multiple lines.
> > % Be sure to join any long lines that got split into multiple single
> > lines.
> > % These can be found by the red lines on the left side of your
> > % text editor, which indicate syntax errors, or else just run the
> > % code and it will stop at the split lines with an error.
> > clc; % Clear the command window.
> > close all; % Close all figures (except those of imtool.)
> > imtool close all; % Close all imtool figures.
> > clear; % Erase all existing variables.
> > workspace; % Make sure the workspace panel is showing.
> > fontSize = 14;
> >
> > % Change the current folder to the folder of this m-file.
> > if(~isdeployed)
> > cd(fileparts(which(mfilename)));
> > end
> >
> > % Check that user has the Image Processing Toolbox installed.
> > hasIPT = license('test', 'image_toolbox');
> > if ~hasIPT
> > % User does not have the toolbox installed.
> > message = sprintf('Sorry, but you do not seem to have the
> > Image Processing Toolbox.\nDo you want to try to continue anyway?');
> > reply = questdlg(message, 'Toolbox missing', 'Yes', 'No',
> > 'Yes');
> > if strcmpi(reply, 'No')
> > % User said No, so exit.
> > return;
> > end
> > end
> > % Read in a standard MATLAB gray scale demo image.
> > folder = 'C:\Documents and Settings\user\My Documents\Downloads';
> > baseFileName = 'CT0020.bmp';
> > fullFileName = fullfile(folder, baseFileName);
> > % Get the full filename, with path prepended.
> > fullFileName = fullfile(folder, baseFileName);
> > if ~exist(fullFileName, 'file')
> > % Didn't find it there. Check the search path for it.
> > fullFileName = baseFileName; % No path this time.
> > if ~exist(fullFileName, 'file')
> > % Still didn't find it. Alert user.
> > errorMessage = sprintf('Error: %s does not exist.', fullFileName);
> > uiwait(warndlg(errorMessage));
> > return;
> > end
> > end
> > grayImage = imread(fullFileName);
> > % Get the dimensions of the image. numberOfColorBands should be = 1.
> > [rows columns numberOfColorBands] = size(grayImage);
> > if numberOfColorBands > 1
> > grayImage = rgb2gray(grayImage);
> > end
> > % Display the original gray scale image.
> > subplot(3, 3, 1);
> > imshow(grayImage, []);
> > title('Original Grayscale Image', 'FontSize', fontSize);
> > % Enlarge figure to full screen.
> > set(gcf, 'Position', get(0,'Screensize'));
> > set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
> >
> > % Let's compute and display the histogram.
> > [pixelCount grayLevels] = imhist(grayImage);
> > subplot(3, 3, 2);
> > bar(pixelCount);
> > title('Histogram of original image', 'FontSize', fontSize);
> > xlim([0 grayLevels(end)]); % Scale x axis manually.
> >
> > binaryImage = grayImage < 150;
> > % Display the image.
> > subplot(3, 3, 3);
> > imshow(binaryImage, []);
> > title('Binary Image', 'FontSize', fontSize);
> >
> > % Remove objects touching the border
> > binaryImage = imclearborder(binaryImage);
> > % Display the image.
> > subplot(3, 3, 4);
> > imshow(binaryImage, []);
> > title('Border cleared', 'FontSize', fontSize);
> >
> > % Fill the blobs and take the largest two
> > binaryImage = imfill(binaryImage, 'holes');
> > % Label each blob so we can make measurements of it
> > [labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
> > % Get all the blob properties. Can only pass in originalImage in
> > version R2008a and later.
> > blobMeasurements = regionprops(labeledImage, grayImage, 'all');
> > % Now I'll demonstrate how to select certain blobs based using the
> > ismember function.
> > allBlobAreas = [blobMeasurements.Area];
> > [sortedAreas sortedIndexes] = sort(allBlobAreas, 'descend');
> >
> > % Get a list of the blobs that meet our criteria and we need to keep.
> > keeperIndexes = sortedIndexes(1:2);
> > % Extract only those blobs that meet our criteria, and
> > % eliminate those blobs that don't meet our criteria.
> > % Note how we use ismember() to do this.
> > keeperBlobsImage = ismember(labeledImage, keeperIndexes);
> > % keeperBlobsImage now has values of 2 and 5 which are the blob
> > numbers.
> > % Binarize is
> > keeperBlobsImage = keeperBlobsImage > 0;
> > % Now we're done. We have a labeled image of blobs that meet our
> > specified criteria.
> > subplot(3, 3, 5);
> > imshow(keeperBlobsImage, []);
> > title('Lungs Mask', 'FontSize', fontSize);
> >
> > % Now make measurements of the extracted lungs.
> > % Re-label with only the keeper blobs kept.
> > labeledLungImage = bwlabel(keeperBlobsImage, 8); % Label each blob
> > so we can make measurements of it
> > % Get all the blob properties. Can only pass in originalImage in
> > version R2008a and later.
> > blobMeasurements = regionprops(labeledLungImage, grayImage, 'all');
> >
> > % Mask the lungs out of the original image.
> > lungsOnly = grayImage .* uint8(keeperBlobsImage);
> > subplot(3, 3, 6);
> > imshow(lungsOnly, [0 255]);
> > title('Lungs extracted', 'FontSize', fontSize);
> >
> > % Get the small bright things in the lungs
> > binaryImage = lungsOnly > 125;
> > subplot(3, 3, 7);
> > imshow(binaryImage, []);
> > title('Bright Objects in Lungs', 'FontSize', fontSize);
> >
> > % Get an image of only the lungs without the bright objects in it.
> > lungsOnly(binaryImage) = 0;
> > subplot(3, 3, 8);
> > imshow(lungsOnly, [0 255]);
> > title('Lungs with no bright objects', 'FontSize', fontSize);
> >
> > msgbox('Done');
>
>
>
>
> ImageAnalyst:
> Thanks a lot its working on all the images that i have. thank you really i appreciate your help.



ImageAnalyst: i want to ask you a question in the code you wrote:
binaryImage = grayImage < 150;
binaryImage = lungsOnly > 125
my question is what do these numbers represent... and you got them based on what would you plz explain!! thnx

Subject: removing every thing but the lungs boundaries

From: ImageAnalyst

Date: 1 Apr, 2011 16:07:26

Message: 11 of 12

On Apr 1, 11:38 am, "nancy " <sharkattack...@hotmail.com> wrote:
> ImageAnalyst: i want to ask you a question in the code you wrote:
> binaryImage = grayImage < 150;
> binaryImage = lungsOnly > 125
> my question is what do these numbers represent... and you got them based on what would you plz explain!! thnx
----------------------------------------------------------
nancy:
Those are threshold values that divide the images into foreground and
background, or objects we're interested in and objects we're not
interested in. I just picked those based on the histogram of that one
image. You'll have to come up with some algorithm to automatically
pick those if you want it to be more automatic and robust for
different images.
ImageAnalyst

Subject: removing every thing but the lungs boundaries

From: Karthik

Date: 9 Oct, 2012 04:12:08

Message: 12 of 12

Hi sir,

I went through your code .
I want to know how to extract the blobs(white tissues inside the lung) that are present inside the lung region.
1.How to extract all blobs (alone)
2.How to extract blobs selectively ??

I ve posted my image in the following link:
http://www.4shared.com/photo/oWe1hVqu/lungimg.html?
Thanks,
Karthik.





ImageAnalyst <imageanalyst@mailinator.com> wrote in message <81c0e3fb-5e6d-41f1-be78-f0fc30551595@r6g2000vbo.googlegroups.com>...
> Sean:
> That extracts just the outer body. She wanted the two lungs without
> the bright objects in them. The code below will do that.
>
> nancy:
> Copy, paste, fix line breaks, fix folder location to represent the
> folder where your image lives, then run.
>
>
> % IMPORTANT: The newsreader may break long lines into multiple lines.
> % Be sure to join any long lines that got split into multiple single
> lines.
> % These can be found by the red lines on the left side of your
> % text editor, which indicate syntax errors, or else just run the
> % code and it will stop at the split lines with an error.
> clc; % Clear the command window.
> close all; % Close all figures (except those of imtool.)
> imtool close all; % Close all imtool figures.
> clear; % Erase all existing variables.
> workspace; % Make sure the workspace panel is showing.
> fontSize = 14;
>
> % Change the current folder to the folder of this m-file.
> if(~isdeployed)
> cd(fileparts(which(mfilename)));
> end
>
> % Check that user has the Image Processing Toolbox installed.
> hasIPT = license('test', 'image_toolbox');
> if ~hasIPT
> % User does not have the toolbox installed.
> message = sprintf('Sorry, but you do not seem to have the
> Image Processing Toolbox.\nDo you want to try to continue anyway?');
> reply = questdlg(message, 'Toolbox missing', 'Yes', 'No',
> 'Yes');
> if strcmpi(reply, 'No')
> % User said No, so exit.
> return;
> end
> end
> % Read in a standard MATLAB gray scale demo image.
> folder = 'C:\Documents and Settings\user\My Documents\Downloads';
> baseFileName = 'CT0020.bmp';
> fullFileName = fullfile(folder, baseFileName);
> % Get the full filename, with path prepended.
> fullFileName = fullfile(folder, baseFileName);
> if ~exist(fullFileName, 'file')
> % Didn't find it there. Check the search path for it.
> fullFileName = baseFileName; % No path this time.
> if ~exist(fullFileName, 'file')
> % Still didn't find it. Alert user.
> errorMessage = sprintf('Error: %s does not exist.', fullFileName);
> uiwait(warndlg(errorMessage));
> return;
> end
> end
> grayImage = imread(fullFileName);
> % Get the dimensions of the image. numberOfColorBands should be = 1.
> [rows columns numberOfColorBands] = size(grayImage);
> if numberOfColorBands > 1
> grayImage = rgb2gray(grayImage);
> end
> % Display the original gray scale image.
> subplot(3, 3, 1);
> imshow(grayImage, []);
> title('Original Grayscale Image', 'FontSize', fontSize);
> % Enlarge figure to full screen.
> set(gcf, 'Position', get(0,'Screensize'));
> set(gcf,'name','Demo by ImageAnalyst','numbertitle','off')
>
> % Let's compute and display the histogram.
> [pixelCount grayLevels] = imhist(grayImage);
> subplot(3, 3, 2);
> bar(pixelCount);
> title('Histogram of original image', 'FontSize', fontSize);
> xlim([0 grayLevels(end)]); % Scale x axis manually.
>
> binaryImage = grayImage < 150;
> % Display the image.
> subplot(3, 3, 3);
> imshow(binaryImage, []);
> title('Binary Image', 'FontSize', fontSize);
>
> % Remove objects touching the border
> binaryImage = imclearborder(binaryImage);
> % Display the image.
> subplot(3, 3, 4);
> imshow(binaryImage, []);
> title('Border cleared', 'FontSize', fontSize);
>
> % Fill the blobs and take the largest two
> binaryImage = imfill(binaryImage, 'holes');
> % Label each blob so we can make measurements of it
> [labeledImage numberOfBlobs] = bwlabel(binaryImage, 8);
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledImage, grayImage, 'all');
> % Now I'll demonstrate how to select certain blobs based using the
> ismember function.
> allBlobAreas = [blobMeasurements.Area];
> [sortedAreas sortedIndexes] = sort(allBlobAreas, 'descend');
>
> % Get a list of the blobs that meet our criteria and we need to keep.
> keeperIndexes = sortedIndexes(1:2);
> % Extract only those blobs that meet our criteria, and
> % eliminate those blobs that don't meet our criteria.
> % Note how we use ismember() to do this.
> keeperBlobsImage = ismember(labeledImage, keeperIndexes);
> % keeperBlobsImage now has values of 2 and 5 which are the blob
> numbers.
> % Binarize is
> keeperBlobsImage = keeperBlobsImage > 0;
> % Now we're done. We have a labeled image of blobs that meet our
> specified criteria.
> subplot(3, 3, 5);
> imshow(keeperBlobsImage, []);
> title('Lungs Mask', 'FontSize', fontSize);
>
> % Now make measurements of the extracted lungs.
> % Re-label with only the keeper blobs kept.
> labeledLungImage = bwlabel(keeperBlobsImage, 8); % Label each blob
> so we can make measurements of it
> % Get all the blob properties. Can only pass in originalImage in
> version R2008a and later.
> blobMeasurements = regionprops(labeledLungImage, grayImage, 'all');
>
> % Mask the lungs out of the original image.
> lungsOnly = grayImage .* uint8(keeperBlobsImage);
> subplot(3, 3, 6);
> imshow(lungsOnly, [0 255]);
> title('Lungs extracted', 'FontSize', fontSize);
>
> % Get the small bright things in the lungs
> binaryImage = lungsOnly > 125;
> subplot(3, 3, 7);
> imshow(binaryImage, []);
> title('Bright Objects in Lungs', 'FontSize', fontSize);
>
> % Get an image of only the lungs without the bright objects in it.
> lungsOnly(binaryImage) = 0;
> subplot(3, 3, 8);
> imshow(lungsOnly, [0 255]);
> title('Lungs with no bright objects', 'FontSize', fontSize);
>
> msgbox('Done');

Tags for 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