给出两个坐标点A和B及其坡度“ slopes”。现在,我想在图像上绘制一条线(使用linspace
-函数),该图像适用于渐变为〜1的线。该行停止在图像边界处(由于xlims和ylims)。
imshow(I)
xlims = xlim(gca);
ylims = ylim(gca);
现在是问题:我尝试重复另一条几乎垂直且没有在图像边界处停止的线(参见图片):
任何解决方案如何使用y = mx + c方程画一条直线,该方程在与梯度无关的图像边界处停止?
编辑:
img = uint8(zeros(382, 382));
pointA = [181.4594, 129.7092];
pointB = [185.3411, 251.6005];
imshow(img)
hold on
plot(pointA(1), pointA(2), 'ro')
plot(pointB(1), pointB(2), 'bo')
hold off
% From y = mx + x
slope = 31.4015;
intercept = -5.5684e+03;
xlims = xlim(gca);
ylims = ylim(gca);
y = xlims*slope + intercept;
Xline = linspace(xlims(1), xlims(2), 382);
Xline_pole1 = linspace(xlims(1), pointA(1), 382/2);
Xline_pole2 = linspace(xlims(2), pointB(1), 382/2);
Yline = Xline*slope + intercept;
Yline_pole1 = Xline_pole1*slope + intercept;
Yline_pole2 = Xline_pole2*slope + intercept;
hold on
plot( Xline_pole1, Yline_pole1, 'Color', 'b', 'LineWidth', 3 );
hold off
% Check how many coordinates are within image frame
for zz=1:length(Xline_pole1)
hold on
plot(Xline_pole1(zz),Yline_pole1(zz), 'm+');
end
答案 0 :(得分:0)
简便的解决方法: 绘制线条后,只需重置极限即可
imshow(I)
xlims = xlim(gca);
ylims = ylim(gca);
% plot your lines
xlim(xlims)
ylim(ylims)