简体   繁体   中英

How to plot contour from points coordinate in matlab

I have an image and four points (x1,y1),(x2,y2),(x3,y3),(x4,y4). They are pixel coordinates of image. I want to generate one contour from points around image using Matlab. I try to make it but it does not accuracy. Which does implement better?

X=[x1 x2 x3 x4];
Y=[y1 y2 y3 y4];
BW1 = roipoly(I,X,Y); % I is an image
figure, 
imagesc(uint8(I),[0 255]),colormap(gray);axis equal;axis off;
hold on,[c1,h1] = contour(BW1,[0 0],'r','linewidth',1.4); hold off

Maybe this is what you are trying to do (I am guessing here…):

X=[x1 x2 x3 x4];
Y=[y1 y2 y3 y4];
BW1 = roipoly(I,X,Y); % I is an image
figure
imagesc(uint8(I),[0 255])
colormap(gray);
axis equal;axis off;
hold on;
plot([X X(1)], [Y Y(1)], 'r', 'linewidth', 1.4); % <<<<< using plot instead of contour

or perhaps you need

[c1,h1] = contour(BW1,[0 0] + 0.5,'r','linewidth',1.4); hold off

This second case uses the fact that a contour of 0.5 will sit right on the boundary between 0 and 1, as needed. But I suspect that your BW1 image will overwrite the original image… sorry can't test right now and you left a lot to be guessed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM