Extract contour from an image

22 ビュー (過去 30 日間)
Bisca
Bisca 2017 年 4 月 28 日
回答済み: waleed mamdouh 2020 年 3 月 23 日
I have a problem about extrcting contours from an image. I need the same result that can i have if using imcontour but this command show me only the boundary of image. I tried with bwtraceboundary but i have a problem with selecting the point to start the tracing.
thanks in advance
  3 件のコメント
Bisca
Bisca 2017 年 5 月 1 日
Thanks for the answer...I made a simple code that extract contour
clc
clear
a = imread('logo1.png');
a_gray = rgb2gray(a);
level = 0.1;
a_bw = imbinarize(a_gray,level);
Icomp = imcomplement(a_bw);
hold on
[B,L] = bwboundaries(a_bw);
imshow(label2rgb(L, @jet, [.5 .5 .5]))
%imshow(a_bw);
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1)
end
Now, I have a doubt because i want associate coordinates in cartesian space on all point of the extrapolates contour
Image Analyst
Image Analyst 2017 年 5 月 1 日
編集済み: Image Analyst 2017 年 5 月 1 日
You again forgot to include 'logo1.png' as requested.
I'm not sure what you're asking because boundary(:,2) is the x coordinates of the boundary/perimeter of the blob, and boundary(:,1) are the y coordinates. Why don't those give you what you want?

サインインしてコメントする。

回答 (2 件)

waleed mamdouh
waleed mamdouh 2020 年 3 月 23 日
clc
clear
a = imread('logo1.png');
a_gray = rgb2gray(a);
level = 0.1;
a_bw = imbinarize(a_gray,level);
Icomp = imcomplement(a_bw);
hold on
[B,L] = bwboundaries(a_bw);
imshow(label2rgb(L, @jet, [.5 .5 .5]))
%imshow(a_bw);
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1)
end

waleed mamdouh
waleed mamdouh 2020 年 3 月 23 日
clc
clear
a = imread('logo1.png');
a_gray = rgb2gray(a);
level = 0.1;
a_bw = imbinarize(a_gray,level);
Icomp = imcomplement(a_bw);
hold on
[B,L] = bwboundaries(a_bw);
imshow(label2rgb(L, @jet, [.5 .5 .5]))
%imshow(a_bw);
hold on
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1)
end

Community Treasure Hunt

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

Start Hunting!

Translated by