Save plotted lines in an matrix

6 ビュー (過去 30 日間)
Bruno Neto
Bruno Neto 2022 年 6 月 14 日
コメント済み: Kevin Holly 2022 年 6 月 22 日
Here's my code to obtain these two lines:
[B,L,N,A] = bwboundaries(ImgClosed);
figure
imshow(ImgClosed)
hold on;
% Loop through object boundaries
for k = 1:N
% Boundary k is the parent of a hole if the k-th column of the adjacency matrix A contains a non-zero element
if (nnz(A(:,k)) > 0)
boundary = B{k};
plot(boundary(:,2),boundary(:,1),'r','LineWidth',2);
% Loop through the children of boundary k
for l = find(A(:,k))'
boundary = B{l};
plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
end
end
end
As ImgClosed is the binary image of the object I'm analysing.
And this is the result:
I want to save both lines (red and green) in an unique matrix so i can plot them again on top of another image. How can i save them?

採用された回答

Kevin Holly
Kevin Holly 2022 年 6 月 14 日
You can save the plot and extract the XData and YData from it's subfields as shown below.
[B,L,N,A] = bwboundaries(ImgClosed);
figure
imshow(ImgClosed)
hold on;
% Loop through object boundaries
for k = 1:N
% Boundary k is the parent of a hole if the k-th column of the adjacency matrix A contains a non-zero element
if (nnz(A(:,k)) > 0)
boundary = B{k};
redline = plot(boundary(:,2),boundary(:,1),'r','LineWidth',2);
% Loop through the children of boundary k
for l = find(A(:,k))'
boundary = B{l};
greenline = plot(boundary(:,2),boundary(:,1),'g','LineWidth',2);
end
end
end
figure
axes
plot(redline.XData,redline.YData,'r','LineWidth',2)
hold on
plot(greenline.XData,greenline.YData,'g','LineWidth',2);
  4 件のコメント
Bruno Neto
Bruno Neto 2022 年 6 月 17 日
Thank you so much! Is there anyway I can densify the triangles inside the object? So I can get something like the delaunay triangulation I showed above?
Kevin Holly
Kevin Holly 2022 年 6 月 22 日
I was able to do so and posted the results here.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurface and Mesh Plots についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by