假设我有两个点:
- P(x,y) [该点位于图像顶部]
- P'(x',y') [该点位于图像底部]
现在我想在这两个点之间画一条线...并且这条线应该出现在图像上,也就是可见的。
如何实现?
假设我有两个点:
现在我想在这两个点之间画一条线...并且这条线应该出现在图像上,也就是可见的。
如何实现?
%# 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]
)。查看线条系列属性以获取更多格式选项。从版本R2014a开始,您可以使用以下步骤使用insertShape:
img = insertShape(img,'Line',[x1 y1 x2 y2],'LineWidth',2,'Color','blue');
您还可以使用相同的命令绘制多条线,但是x1、x2、y2和y3必须是列向量,每行代表一条新线。
insertShape还允许您绘制矩形、圆形和多边形。
像这样:
figure;
hold on;
imagesc(img);
line([x1,x2],[y1,y2],'Color','r','LineWidth',2)
hold off
在图像中,y代表“下”方向,x代表“右”方向。根据需要更改颜色和宽度以使其可见。
%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);
查看属性,以了解您可以编辑什么。
load clown
image(X)
colormap(map)
c = size(X,2)
mid = round(c/2)
X(:,mid) = 1
image(X)
X(:,mid,:) = [1 1 1];
。 - André Caron您可以下载并使用hline和vline与hold on
结合使用,使用从访问Steve on Image Processing中学到的技术。或者只是使用他的技术。无论哪种方式都可以。