【问题标题】:Matlab rotate image and move it to cornerMatlab旋转图像并将其移动到角落
【发布时间】:2015-11-25 19:34:09
【问题描述】:

我有旋转矩形的图像旋转代码,但当前矩形仍位于旋转图像的中心。目前我有需要旋转的图像,以便矩形角点位于左上角,以便将来可以轻松裁剪。矩形的角点是已知的。

ang = rot*pi/180;

A = [ cos(ang) -sin(ang)  0;
  sin(ang)  cos(ang)  0;
  0  0  1];

T = maketform('affine',A);

OutputImage = imtransform(I,T);

imshow(OutputImage)

图片:

【问题讨论】:

    标签: image matlab rotation


    【解决方案1】:

    imtransform 有一个特殊的行为:

    imtransform 函数会自动移动输出图像的原点,以使转换后的图像尽可能多地可见。

    这种“自动转移”使您的输出移动到不希望的位置。

    为了更好地控制转换,我建议使用tformarray

    OutputImage = tformarray( I, maketform('affine',A), ...
                              makeresampler('cubic','fill'),
                              [2 1], [2 1], size(I(:,:,1)), [], 0 );
    

    您也可以考虑使用imrotate 来围绕其中心旋转图像。示例见this answer


    可能相关的线程How to crop and rotate an image to bounding box?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-23
      相关资源
      最近更新 更多