【问题标题】:Subplot two images with a vertical separator使用垂直分隔符绘制两个图像
【发布时间】:2019-07-04 03:38:00
【问题描述】:

我正在尝试创建一个图形,左侧有一个图像(原始图像),右侧有一个图像(扭曲的图像),并用一条垂直线将它们分开,如下所示:

我已经通过创建没有刻度和标签的轴来尝试这个。然后从下到上画一条线并应用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添加线。
  • @Dev-iL 解决了!我什至可以摆脱axeshold on 等。非常感谢。我可以请您发表您的评论作为答案,以便我接受吗?
  • 不客气!感谢您的接受:)
  • 也可以看看montage()。没有垂直分隔符,但您可以指定边框大小等等...

标签: image matlab line matlab-figure subplot


【解决方案1】:

要实现该结果,您应该使用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);

导致:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2015-01-22
    相关资源
    最近更新 更多