21

我有两点可以说:

  • P(x,y) [点位于图像顶部]
  • P'(x',y') [点位于图像底部]

现在我想在这两点之间画一条线......并且这条线应该出现在图像上意味着应该是可见的。

这个怎么做????

4

6 回答 6

19

在图像上画线的最简单方法是使用PLOT

%# read and display image
img = imread('autumn.tif');
figure,imshow(img)

%# make sure the image doesn't disappear if we plot something else
hold on

%# define points (in matrix coordinates)
p1 = [10,100];
p2 = [100,20];

%# plot the points.
%# Note that depending on the definition of the points,
%# you may have to swap x and y
plot([p1(2),p2(2)],[p1(1),p2(1)],'Color','r','LineWidth',2)

如果您想要不同的颜色,请将字母更改为rgbcmykw,或使用 RGB 三元组(红色为[1 0 0])。查看lineseries 属性以获取更多格式选项。

于 2010-08-21T14:40:21.337 回答
12

从版本 R2014a 开始,您可以使用 insertShape,如下所示:

img = insertShape(img,'Line',[x1 y1 x2 y2],'LineWidth',2,'Color','blue');

您也可以使用相同的命令绘制多条线,但 x1,x2,y2,y3 必须是列向量,每行代表一条新线。

insertShape还允许您绘制矩形、圆形和多边形。

于 2016-11-25T20:04:25.927 回答
6

像这样:

figure;
hold on;
imagesc(img);
line([x1,x2],[y1,y2],'Color','r','LineWidth',2)
hold off

其中 y 是图像中的“向下”方向,x 是“右”方向。根据需要更改颜色和宽度以使其可见。

于 2013-11-12T01:31:44.040 回答
1
load clown
image(X)
colormap(map)
c = size(X,2)
mid = round(c/2)
X(:,mid) = 1
image(X)
于 2010-12-30T16:11:51.623 回答
1

If you have the Computer Vision toolbox. You can simply use shapeInserter.

Check out http://www.mathworks.com/help/vision/ref/vision.shapeinserter-class.html

To specify lines, you have to use the line below. Otherwise, you may get a rectangle

Example:

%draw a line from point (100,100) to (200,200) on an image saved as nextFrame

line = int32([100 100  200 200]);
shapeInserter = vision.ShapeInserter('Shape', 'Lines');
nextFrame = step(shapeInserter, nextFrame, line);

Take a look at the properties to see what you can edit.

于 2016-01-29T21:50:48.870 回答
0

您可以下载并结合使用hline 和 vlinehold on,使用访问Steve on Image Processing的技术。或者只是使用他的技术。无论哪种方式都有效。

于 2010-12-30T16:11:24.320 回答