imwarp and affine2d problem with image orthogonality / skew
2 次查看(过去 30 天)
显示 更早的评论
I submitted this to support staff but wanted to probe the users for any input. I consider myself pretty knowledgeable about Affine transformation - I use it often with respect to mapping a set of coordinates (x,y pairs) to another using Affine transformation. The most common form of the transform involves scaleX, scaleY, angleX and angleY and two translations. For the rest of this thread let's ignore the translations. It's sometimes desirable to express the Affine components as mag, aspect, rotation and orthogonality. In that formalism, scaleX = mag * aspect and scaleY = mag / aspect. The Affine transform matrix can be computed by two methods, both giving same results:
sx = m * asp; sy = m / asp;
% Matrix computation
scale = [sx 0; 0 sy];
rot = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
ortho = [cosd(phi) 0; sind(phi) 1];
T = [[rot*ortho*scale, [0;0]];[0 0 1]];
% Direct computation
a = sx * cosd(theta+phi);
b = -1 * sy * sind(theta);
c = sx * sind(theta+phi);
d = sy * cosd(theta);
A = [a b 0;
c d 0;
0 0 1];
['Matrix and direct computation methods are equal : ' num2str(isequal(A,T))];
t_aff = affine2d(T);
I_affine = imwarp(padarray(I,floor([nRows/10,nCols/10])),t_aff,InterpA{InterpIndex},'FillValues',0);
It all works fine except for the ortogonality. I have a means of computing the warping in an image (locating grid points and computing the transformation that relates the found grid points to a perfectly square grid). So, I read an image, compute the baseline warping, which gives me scaleX, scaleY - or mag/aspect - and rotation and orthogonality angles. Then I apply imwarp as shown above. When I apply mag / aspect or rotation in any combination, I get correct answer. When I apply orthogonality (in combination with other terms or by itself), I get not only the orthogonality but I also get same angle in rotation.
To see the problem, you can run the attached file with following arguments:
AffineTest(1, 1, 0.0, 0.5); % keep the first two parameters in the 0.98 - 1.02 range and the next two in the -2 to +2 range
on the attached image (the function is hardcoded for this image at the same folder as the script).
imwarp with ortogonality only gives a warped image that has BOTH rotation and ortogonality.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/150591/image.bmp)
0 个评论
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!