创建图形时 MATLAB 自动缩放到特定点
MATLAB auto zoom to specific point when figure is created
我已经编写了一些代码,这些代码将遵循附图中显示的黑边。每次选择下一个点时,都会重新绘制图形以显示更新。这样做是为了以动画方式演示代码。
我想自动放大特定点(红色方块包围的中心青色点)。希望自动缩放区域会跟随该点追踪黑色边缘。
下面的代码是作为一个函数编写的,每次检测到下一个边缘像素时,我都会在我的主脚本中调用它。
我已经尝试将轴的范围设置为 POI 周围的范围,但是我无法让它工作。
function draw_point2(BinaryImage, P, P_r, P_c)
%P is a 1x2 array for the position of the current black pixel.
%P_r is nx1 list of all the row values for the detected pixels.
%P_c is nx1 list of all the column values for the detected pixels.
cla
r = P(1,1);
c = P(1,2);
figure (100)
imshow(BinaryImage) , title('Binary image')
hold on;
plot(P_c, P_r, 'c.', 'LineWidth', 2); hold on
%Current Black Pixel
plot(c, r, 'c.', 'LineWidth', 2); hold on;
% Possible Black Pixel - Next
plot(c, r+1, 'rs', 'LineWidth', 2); hold on
plot(c, r-1, 'rs', 'LineWidth', 2); hold on
plot(c-1, r, 'rs', 'LineWidth', 2); hold on
plot(c+1, r, 'rs', 'LineWidth', 2); hold on
plot(c-1, r+1, 'rs', 'LineWidth', 2); hold on
plot(c-1, r-1, 'rs', 'LineWidth', 2); hold on
plot(c+1, r+1, 'rs', 'LineWidth', 2); hold on
plot(c+1, r-1, 'rs', 'LineWidth', 2); hold on
axis equal
truesize;
end
谢谢
EDIT1
下图显示了当前输出旁边的所需输出。 (它显示了我希望图形在绘制时的样子。它显示了 POI 的缩放(和居中)。在理想情况下,POI 也将始终在图中居中
使用函数axis
。
您可以使用 axis([xmin xmax ymin ymax])
定义限制。在您的情况下,xmin
类似于 c-20
和 xmax=c+20
。
我已经编写了一些代码,这些代码将遵循附图中显示的黑边。每次选择下一个点时,都会重新绘制图形以显示更新。这样做是为了以动画方式演示代码。
我想自动放大特定点(红色方块包围的中心青色点)。希望自动缩放区域会跟随该点追踪黑色边缘。
下面的代码是作为一个函数编写的,每次检测到下一个边缘像素时,我都会在我的主脚本中调用它。
我已经尝试将轴的范围设置为 POI 周围的范围,但是我无法让它工作。
function draw_point2(BinaryImage, P, P_r, P_c)
%P is a 1x2 array for the position of the current black pixel.
%P_r is nx1 list of all the row values for the detected pixels.
%P_c is nx1 list of all the column values for the detected pixels.
cla
r = P(1,1);
c = P(1,2);
figure (100)
imshow(BinaryImage) , title('Binary image')
hold on;
plot(P_c, P_r, 'c.', 'LineWidth', 2); hold on
%Current Black Pixel
plot(c, r, 'c.', 'LineWidth', 2); hold on;
% Possible Black Pixel - Next
plot(c, r+1, 'rs', 'LineWidth', 2); hold on
plot(c, r-1, 'rs', 'LineWidth', 2); hold on
plot(c-1, r, 'rs', 'LineWidth', 2); hold on
plot(c+1, r, 'rs', 'LineWidth', 2); hold on
plot(c-1, r+1, 'rs', 'LineWidth', 2); hold on
plot(c-1, r-1, 'rs', 'LineWidth', 2); hold on
plot(c+1, r+1, 'rs', 'LineWidth', 2); hold on
plot(c+1, r-1, 'rs', 'LineWidth', 2); hold on
axis equal
truesize;
end
谢谢
EDIT1
下图显示了当前输出旁边的所需输出。 (它显示了我希望图形在绘制时的样子。它显示了 POI 的缩放(和居中)。在理想情况下,POI 也将始终在图中居中
使用函数axis
。
您可以使用 axis([xmin xmax ymin ymax])
定义限制。在您的情况下,xmin
类似于 c-20
和 xmax=c+20
。