【问题标题】:Problems with performing image translation in MATLAB在 MATLAB 中执行图像翻译的问题
【发布时间】:2023-04-10 15:00:01
【问题描述】:

我正在尝试使用 MATLAB 进行图像翻译,但图像根本不动。我的代码是:

myPic = imread('pic.jpg');
x = 250;
y = 375;

trans = affine2d([1 0 0; 0 1 0; x y 1]);

outputPic = imwarp(myPic, trans);

imshow(myPic)
axis on
figure()
imshow(outputPic)
axis on
isequal(myPic,outputPic) %evaluates to 1!!!

当我对旋转仿射矩阵执行相同操作时,它起作用了。为什么这不起作用?

当我打印两张照片时会发生以下情况:

【问题讨论】:

  • 你确定它不起作用吗?你是怎么检查的?
  • 我检查它是因为我知道 outputPic 轴上的数字应该不同于 myPic 的数字。是的,。轴上相等是matlab代码
  • 你能展示一个输入/输出的例子吗?
  • 我添加了一个发生了什么的示例和更多代码来证明发生了什么

标签: matlab matrix matrix-transform


【解决方案1】:

为了使其工作,您需要定义一个“OutputView”参数。 该参数设置输出图像在世界坐标系中的大小和位置,使用imref2d函数。

例子:

myPic = imread('peppers.png');
x = 250;
y = 375;

%defines transformations
trans = affine2d([1 0 0; 0 1 0; x y 1]);
eyeTrans= affine2d([1 0 0; 0 1 0; 0 0 1]);

%initializes imref2d object
outView = imref2d([size(myPic,1)+y,size(myPic,2)+x]);

outputPic1 = imwarp(I,trans,'OutputView',outView)
outputPic2 = imwarp(I,eyeTrans,'OutputView',outView)

%display result
figure,
subplot(1,2,1); imshow(outputPic2); title('original')
subplot(1,2,2); imshow(outputPic1); title('translated')

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2013-05-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多