How can you performing imwarp about the center of an image, not the top left corner?

조회 수: 14 (최근 30일)
I am trying to transform a 2D image using an affine2D object (translation, rotation, and scale). I want to apply it about the center of the image and the output image to be the same size as the input image. When I used imwarp, it applies it at the top left corner. I did it as follows:
T = affine2d(H);
R = imref2d(size(img));
img2 = imwarp(img,T,'OutputView',R);
Can you please help?

채택된 답변

Alex Taylor
Alex Taylor 2016년 4월 7일
편집: Alex Taylor 2016년 4월 7일
There are at least two ways to do this with IMWARP. One is to use a composite geometric transformation in which you pre and post multiply your intended transformation to shift the image to the origin (0,0), apply your affine operation, and then shift the image back to its original center.
A second, and I think easier way to do it, is to put your image into a non-default coordinate system where it is defined as being centered at the origin and then just apply your intended transformation. This approach is shown below.
A = imread('pout.tif');
Rin = imref2d(size(A))
Rin.XWorldLimits = Rin.XWorldLimits-mean(Rin.XWorldLimits);
Rin.YWorldLimits = Rin.YWorldLimits-mean(Rin.YWorldLimits);
out = imwarp(A,Rin,tform);
  댓글 수: 1
Craig Russell
Craig Russell 2017년 9월 29일
Just a point
Rin.XWorldLimits = Rin.XWorldLimits-2*mean(Rin.XWorldLimits);
Rin.YWorldLimits = Rin.YWorldLimits-2*mean(Rin.YWorldLimits);
Worked for me, unsure why but whatever.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometric Transformation and Image Registration에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by