How can I segment part of image?

4 ビュー (過去 30 日間)
Veronika
Veronika 2017 年 3 月 20 日
Dear all,
I have image of thorax and I would like to create binarization image of lungs, but separately for right and for left lung. I have been successful only for right lung. I would like to binarization separately also left lung, but I don´t know, where I did mistake.
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);
thresholdValue = 199;
% thresholdValue = 220;
binaryImage_pater = grayImage_pater > thresholdValue;
% Odstranění okolí.
binaryImage_pater = imclearborder(binaryImage_pater);
% Vyplnění otvorů
binaryImage_pater = imfill(binaryImage_pater, 'holes');
%Práh pro vytvoření binárního obrazu okolí
% Práh pro vytvoření binárního obrazu okolí
thresholdValue = 180;
binaryImage_okoli = eq_grayImage > thresholdValue;
% Odstranění okolí.
binaryImage_okoli = imclearborder(binaryImage_okoli);
% Vyplnění otvorů.
binaryImage_okoli = imfill(binaryImage_okoli, 'holes');
% Vymazání menších otvorů.
binaryImage_okoli = bwareaopen(binaryImage_okoli, 750);
%Roztažení binárního obrazu pro přesnější segmentaci
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,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');
subplot (2, 3, 1)
imshow(binaryImage_okoli, []);
axis on;
caption = sprintf('Binární obraz okolí');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
save binaryImage_okoli binaryImage_okoli
subplot (2, 3, 2)
imshow(binaryImage_pater, []);
axis on;
caption = sprintf('Binární obraz páteře');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
I attach my original image. Thank you for your answers.

回答 (0 件)

カテゴリ

Help Center および File ExchangeVisual Exploration についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by