Hello, I am trying to get the X and Y values from a Plot. This plot is generated from a loop, and the plot represents the boundary of an image..
2 views (last 30 days)
Show older comments
close all
clear all
% The image I am trying to read
A = imread('Britain.png');
% The boundaries around the image
BW = im2bw(A);
[B,L] = bwboundaries(BW);
% To put the x and y values
double x1=[];
double y1=[];
%imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
% A loop to plot only the boundaries, because I only want the boundary and not the image
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1)
j=findobj(gca,'Type','line')
x1(k)=j(k).XData(k)
y1(k)=j(k).YData(k)
end
%plot(x1,y1)
0 Comments
Accepted Answer
Kevin Holly
on 18 Apr 2023
% The image I am trying to read
A = imread('Britain.png');
% The boundaries around the image
BW = im2bw(A);
[B,L] = bwboundaries(BW);
% To put the x and y values
double x1=[];
double y1=[];
%imshow(label2rgb(L, @jet, [.5 .5 .5]))
hold on
x=[];
y=[];
% A loop to plot only the boundaries, because I only want the boundary and not the image
for k = 1:length(B)
boundary = B{k};
plot(boundary(:,2), boundary(:,1), 'r', 'LineWidth', 1)
% j=findobj(gca,'Type','line');
% x1(k)=j(k).XData(k) ;
% y1(k)=j(k).YData(k);
x = [x; boundary(:,2)];
y = [y; boundary(:,1)];
end
figure
plot(x,y)
figure
scatter(x,y,'.')
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!