I would like to rotate a non-squared image with Matlab:
- without using the
imrotatefunction, since it is part of the Image Processing Toolbox, - with the
looseparameter, which means the size of the output differs from the size of the input image, - and with a not too slow function compared to
imrotate.
I have already found a function in order to do this (just replace imshow and bestblk with your own functions in order not to use the toolbox), yet it is really slow for large images. My approach would try to avoid making loops and relying as much as possible on interp2.
The signature of the function would be:
imOutput = my_imrotate(imInput, theta_degres, interpolation, bbox)
where:
interpolationwould bebilinear,bicubicornearest,bboxwould becrop, orloose.
Crop
I already have a good result with the crop parameter, but I cannot manage to find the offset for the loose parameter.
Here is the code for the crop parameter, where Z is the input and Zi is the output:
Z = double(imInput);
sz = size(Z);
[X,Y] = meshgrid(1:sz(2), 1:sz(1));
%# Center
c = sz(end:-1:1)/2;
%# Angle
t = theta_degres*pi/180;
%# 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));
%# Rotation
Zi = interp2(X, Y, Z, Xi, Yi);
Loose
My idea is to compute the size of a frame which would contain the original image as well as the rotated image, and then:
- pad the orig