Why can´t I binarization left lung?

1 view (last 30 days)
Veronika
Veronika on 16 Mar 2017
Commented: Veronika on 19 Mar 2017
Dear all,
I have code for segmentation parts of image. And I would like to binarization left lung, but I don´t know, why this code isn´t working. This is my code:
fontSize = 15;
baseFileName = '110.jpg';
% baseFileName = 'thorax-mdl.jpg';
folder = pwd
fullFileName = fullfile(folder, baseFileName);
% Načtení obrazu.
grayImage = imread(fullFileName);
grayImage_pater = imread (fullFileName);
% Dimenze obrazu.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
%grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%ekvalizace pomocí histogramu obrazu
% Zobrazení obrazu.
figure(1)
imshow(grayImage, []);
axis on;
caption = sprintf('Originální černobílý obraz, %s', baseFileName);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Nastavení obrazu.
% Zvětšení obrazu na celou obrazovku.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Odstranění panelu nástrojů a rozbalovacího menu.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Přidání titulku okna.
set(gcf, 'Name', 'Segmentace', 'NumberTitle', 'Off')
thresholdValue = 120;
binaryImage = grayImage < thresholdValue;
% Odstranění okolí.
binaryImage = imclearborder(binaryImage);
% Vyplnění otvorů.
binaryImage = imfill(binaryImage, 'holes');
labeledImage = bwlabel(binaryImage);
rightLung = ismember(labeledImage, 1);
leftLung = ismember(labeledImage, 2);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
rightLung= imdilate(rightLung,se);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
leftLung= imdilate(leftLung,se);
subplot (2, 3, 3)
imshow(binaryImage, []);
axis on;
caption = sprintf('Binární obraz plic');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
labeledImage = bwlabel(binaryImage);
rightLung = ismember(labeledImage, 1);
leftLung = ismember(labeledImage, 2);
subplot (2, 3, 4)
imshow(leftLung, []);
axis on;
caption = sprintf('Binární obraz levé plíce');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
subplot (2, 3, 5)
imshow(rightLung, []);
axis on;
caption = sprintf('Binární obraz pravé plíce');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
Can you advise me? Thank you for your answers.

Answers (1)

John BG
John BG on 16 Mar 2017
Veronika
to remove the MATLAB syntax errors, ignoring the image segmentation itself, I have simplified filenames and file paths.
May be you'd want to consider changing MATLAB to the folder where the image is,
cd('filepath1')
process image ..
cd('filepath2')
then your code runs ok, from the syntax point of view.
You also missed defining fontSize
The image I used as test doesn't really matter, or do you now want to further ask regarding the image processing?
try the following:
grayImage = imread('affine_im2.jpg');
grayImage_pater = imread ('affine_im2.jpg');
baseFileName='baseFileName';
% Dimenze obrazu.
% ***
[rows, columns, numberOfColorChannels] = size(grayImage);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage = grayImage(:, :, 2); % zelený kanál
end
eq_grayImage = histeq(grayImage);%ekvalizace pomocí histogramu obrazu
[rows, columns, numberOfColorChannels] = size(grayImage_pater);
if numberOfColorChannels > 1
% Máme barevný obraz, musíme ho převést na černobílý = vybereme zelený kanál
grayImage_pater = grayImage_pater(:, :, 2); % zelený kanál
%grayImage_pater(425:end, :) = 0;
end
eq_grayImage_pater = histeq(grayImage_pater);%ekvalizace pomocí histogramu obrazu
% Zobrazení obrazu.
figure(1)
imshow(grayImage, []);
axis on;
caption = sprintf('Originální černobílý obraz, %s', baseFileName);
fontSize=12
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
drawnow;
hp = impixelinfo();
% Nastavení obrazu.
% Zvětšení obrazu na celou obrazovku.
set(gcf, 'Units', 'Normalized', 'OuterPosition', [0 0 1 1]);
% Odstranění panelu nástrojů a rozbalovacího menu.
set(gcf, 'Toolbar', 'none', 'Menu', 'none');
% Přidání titulku okna.
set(gcf, 'Name', 'Segmentace', 'NumberTitle', 'Off')
thresholdValue = 120;
binaryImage = grayImage < thresholdValue;
% Odstranění okolí.
binaryImage = imclearborder(binaryImage);
% Vyplnění otvorů.
binaryImage = imfill(binaryImage, 'holes');
labeledImage = bwlabel(binaryImage);
rightLung = ismember(labeledImage, 1);
leftLung = ismember(labeledImage, 2);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
rightLung= imdilate(rightLung,se);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
leftLung= imdilate(leftLung,se);
subplot (2, 3, 3)
imshow(binaryImage, []);
axis on;
caption = sprintf('Binární obraz plic');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
labeledImage = bwlabel(binaryImage);
rightLung = ismember(labeledImage, 1);
leftLung = ismember(labeledImage, 2);
subplot (2, 3, 4)
imshow(leftLung, []);
axis on;
caption = sprintf('Binární obraz levé plíce');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
subplot (2, 3, 5)
imshow(rightLung, []);
axis on;
caption = sprintf('Binární obraz pravé plíce');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
if you find this answer useful would you please be so kind to mark my answer as Accepted Answer?
To any other reader, please if you find this answer
please click on the thumbs-up vote link
thanks in advance
John BG
  1 Comment
Veronika
Veronika on 19 Mar 2017
I forget attached the original image, now it´s okay.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!