00001
00002
00003 #include "Rotation.h"
00004
00005 template void Rotate< int >(Image< int >&, float, Image< int >&);
00006 template void Rotate< byte >(Image< byte >&, float, Image< byte >&);
00007 template void Rotate< float >(Image< float >&, float, Image< float >&);
00008 template void Rotate< int >(Image< int >&, float);
00009 template void Rotate< byte >(Image< byte >&, float);
00010 template void Rotate< float >(Image< float >&, float);
00011
00012 template< class T > void Rotate(Image< T >& input, float angle, Image< T >& output)
00013 {
00014 double xc, yc, xn, yn, xo, yo, theta;
00015 double alfa, beta;
00016 int ir, jr;
00017 Image< T > res;
00018 res = input;
00019 res = 0;
00020 theta = -angle*acos(-1)/180;
00021 xc = ((double)(input.getWidth()-1))/2;
00022 yc = ((double)(input.getHeight()-1))/2;
00023 for (int i = 0; i < input.getHeight(); i++)
00024 for (int j = 0; j < input.getWidth(); j++){
00025 xn = j - xc; yn = i - yc;
00026 xo = xn*cos(theta) + yn*sin(theta);
00027 yo = yn*cos(theta) - xn*sin(theta);
00028 xo += xc; yo += yc;
00029
00030
00031
00032 alfa = xo - floor(xo);
00033 beta = yo - floor(yo);
00034 jr = (int)floor(xo); ir = (int)floor(yo);
00035 if (jr >= 0 && jr < input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00036 res[i][j] = (T)((1-alfa)*(1-beta)*input[ir][jr] + alfa*(1-beta)*input[ir][jr+1] +
00037 (1-alfa)*beta*input[ir+1][jr] + alfa*beta*input[ir+1][jr+1]);
00038 if (jr == -1 && jr < input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00039 res[i][j] = (T)((1-beta)*input[ir][jr+1] + beta*input[ir+1][jr+1]);
00040 if (jr >= 0 && jr == input.getWidth()-1 && ir >= 0 && ir < input.getHeight()-1)
00041 res[i][j] = (T)((1-beta)*input[ir][jr] + beta*input[ir+1][jr]);
00042 if (jr >= 0 && jr < input.getWidth()-1 && ir == -1 && ir < input.getHeight()-1)
00043 res[i][j] = (T)((1-alfa)*input[ir+1][jr] + alfa*input[ir+1][jr+1]);
00044 if (jr >= 0 && jr < input.getWidth()-1 && ir >= 0 && ir == input.getHeight()-1)
00045 res[i][j] = (T)((1-alfa)*input[ir][jr] + alfa*input[ir][jr+1]);
00046 }
00047 output = res;
00048 }
00049
00050 template< class T > void Rotate(Image< T >& input, float angle)
00051 {
00052 Rotate(input, angle, input);
00053 }