Clear Filters
Clear Filters

How to binarization this part of image?

1 view (last 30 days)
Veronika
Veronika on 15 Mar 2017
Dear all,
I did binarization and segmentation of this image for this part of image:
I would like to do the same for this image:
I think, that it will be helpful to change the threshold value, but I don´t know how. I attach original image. This is my code:
% Zvolení souboru, který chceme použít.
fontSize = 15;
baseFileName = '110.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')
%Práh pro vytvoření binárního obrazu okolí
thresholdValue = 120;
binaryImage_okoli = grayImage < thresholdValue;
% binaryImage_okoli = handles.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);
figure(3)
imshow(binaryImage_okoli, []);
axis on;
caption = sprintf('Binární obraz okolí');
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
Can you advise me? Thank you for your answers.

Answers (0)

Community Treasure Hunt

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

Start Hunting!