简体   繁体   English

如何在Matlab中从点坐标绘制轮廓

[英]How to plot contour from points coordinate in matlab

I have an image and four points (x1,y1),(x2,y2),(x3,y3),(x4,y4). 我有一个图像和四个点(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. 我想使用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. 第二种情况使用的事实是,根据需要,轮廓0.5将恰好位于0和1之间的边界上。 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. 但是我怀疑您的BW1图像会覆盖原始图像...很抱歉,目前无法测试,您还有很多猜测。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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