【问题标题】:Error trying to rotate an image in Matlab using INTERP2 funcion尝试使用 INTERP2 函数在 Matlab 中旋转图像时出错
【发布时间】:2018-03-17 18:57:09
【问题描述】:

我正在尝试在没有嵌入 Matlab 功能的情况下执行图像旋转。 但我仍然收到此错误: 使用错误。' 未定义 ND 阵列上的转置。请改用 PERMUTE。

interp2 中的错误(第 130 行) V = V.';

但我不知道为什么会出现这样的错误,同样我不知道如何自定义函数 interp2PERMUTE 以使其正常运行(我在 Matlab 中使用过 help)。

您能帮忙定制一下代码吗?

提前致谢!

clc; clear all; close all;

input_image = imread('mri.png');
Z = double(input_image);

Size = size(Z);
[X,Y] = meshgrid(1:Size(2), 1:Size(1));

%Center of an image
c = Size(end:-1:1)/2;

%Angle of rotation
angle = 45;
t = angle*pi/180;

%Making the rotation
ct = cos(t);
st = sin(t);
Xi = c(1) + ct*(X - c(1)) - st*(Y - c(2));
Yi = c(2) + st*(X - c(1)) + ct*(Y - c(2));

%Interpolation
Zi = interp2(X, Y, Z, Xi, Yi);

figure()
subplot(121); imshow(I); title('Original image');
subplot(122); imshow(uint8(Zi)); title('Rotated image without embedded 
function');

【问题讨论】:

    标签: image matlab matlab-figure


    【解决方案1】:

    Z 是 3D 矩阵,interp2 仅适用于 2D 矩阵。所以你必须分别对每种颜色进行插值,然后重新组合它们:

    %Interpolation
    Zir = interp2(X, Y, Z(:,:,1), Xi, Yi);
    Zig = interp2(X, Y, Z(:,:,2), Xi, Yi);
    Zib = interp2(X, Y, Z(:,:,3), Xi, Yi);
    Zi = cat(3, Zir, Zig, Zib);
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 2021-02-27
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2020-08-17
      • 1970-01-01
      • 2017-03-07
      • 2010-11-14
      相关资源
      最近更新 更多