How do I create continuous curve in image from my points?
4 次查看(过去 30 天)
显示 更早的评论
Dear all,
I would like to create continuous curve in CT scan (image) from my bwboundaries points. But if I use all of this points that was really not usable for my work. So I wanted reduce the number of bwboundaries points by inputdlg. But the curve isn´t continuous. It seems like that:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/163072/image.png)
I would like to continuous (closed) curve for my work.
This is my code:
clc; clear all;
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.
% numberOfColorBands by m?l být = 1.
% ***
[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);%
%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);
se = strel('line',5,100);
binaryImage_okoli= imdilate(binaryImage_okoli,se);
figure(4)
imshow(grayImage, []);
title('Segmentace okolí', 'FontSize', fontSize);
axis image;% Ujišt?ní, že se obraz po zv?tšení okna nezdeformuje.
hold on;
% 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 okolí', 'NumberTitle', 'Off')
tmp = bwboundaries(binaryImage_okoli);
shape.thorax = tmp{1};
% boundaries = bwboundaries(handles.binaryImage_okoli);
numberOfBoundaries = size(tmp, 1);
for k = 1 : numberOfBoundaries
thisBoundary = tmp{k};
plot(thisBoundary(:,2), thisBoundary(:,1), 'r', 'LineWidth', 2);
end
figure(5);
imshow(grayImage);
hold on
prompt = {'Nastavení po?tu komponent?:'};
dlg_title = 'Nastavení parametr? segmentace';
defaultans = {'50'};
num_lines = [ones(size(defaultans')) ones(size(defaultans'))*75];
answer = inputdlg(prompt, dlg_title,num_lines, defaultans);
% a = str2double( x{1,1} );
a = str2double(answer);
Npts1 = 35; % po?et bod? interpolovaných hranic
% Npts2 = 25; % po?et bod? interpolovaných hranic
% Npts3 = 5; % po?et bod? interpolovaných hranic
Ncomps = a; % po?et komponent?
% shape.thorax=Model(binaryImage_okoli,Ncomps,Npts1);
shape.thorax=bwboundaries(binaryImage_okoli);
tmp=shape.thorax{1};
%%do interpolation
x = tmp(:,2) ; y = tmp(:,1) ;
% select according to Ncomps
skip = ceil(length(x)/Ncomps) ;
xi = x(1:skip:end) ;
yi = y(1:skip:end) ;
plot(xi,yi, 'o-b')
legend('Okolí hrudníku')
Can you advice me? Thank you for your answers.
0 个评论
采纳的回答
KSSV
2017-4-18
You close curve. Replace
xi = x(1:skip:end) ;
yi = y(1:skip:end) ;
with
xi = [x(1:skip:end) ;x(1)] ;
yi = [y(1:skip:end) ;y(1)] ;
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!