使用垂直分隔符绘制两个图像的子图

Subplot two images with a vertical separator

我正在尝试创建一个图形,左侧有一个图像(原始图像),右侧有一个图像(变形图像),并且用垂直线分隔它们,如下所示:

我已经通过创建没有刻度和标签的轴来尝试这个。然后从下到上画一条线并应用 hold on 最后 subplot 两个图像。

我的代码:

origImage = imread('F-original.png');
tform = affine2d([1 0 0; .5 1 0; 0 0 1]);
warpedImage = imwarp(origImage, tform, 'interp', 'bilinear');

axes('Position', [0 0 1 1], 'XTick', NaN, 'YTick', NaN);
line([1/2 1/2], [0 1], 'Color', 'k')
axes(gca)
hold on

subplot(1, 2, 1)
imshow(origImage)

subplot(1, 2, 2)
imshow(warpedImage)

但实际上发生的是:线条闪了一下,然后就消失了,能看到的都是支线。

如何进行这项工作?

要实现该结果,您应该使用 annotation,它是 图形级别 上的图形对象(即不限于特定轴,所以不不需要 hold on 等)。

这是一个例子:

function q54617073
% Prepare images:
origImage = imread('ngc6543a.jpg');
tform = affine2d([1 0 0; .5 1 0; 0 0 1]);
warpedImage = imwarp(origImage, tform, 'interp', 'bilinear');
% Create a figure with a white background:
figure('Color','w');
% Plot the two images:
subplot(1, 2, 1); imshow(origImage);
subplot(1, 2, 2); imshow(warpedImage);
% Add the Line
annotation('line', [0.52 0.52], [0.2 0.8], 'Color', 'r', 'LineWidth', 3);

导致: