00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00032 #include "operator/GeometricOperators.hpp"
00033
00034 #include <cmath>
00035
00036 using namespace Millie;
00037
00038 void Millie::rotationOperator(Image& out, Image & in, float degree)
00039 {
00040 if(out.getNumComponents() != in.getNumComponents())
00041 throw IllegalArgument("rotationOperator");
00042
00043
00044 float angle_radian = -degree * M_PI / 180.0;
00045
00046
00047 float tcos = cos(angle_radian);
00048 float tsin = sin(angle_radian);
00049
00050
00051 int largeurdest= (int) ceil(in.getWidth() * fabs(tcos) + in.getHeight()* fabs(tsin));
00052 int hauteurdest= (int) ceil(in.getWidth()* fabs(tsin) + in.getHeight() * fabs(tcos));
00053
00054
00055 out.resize(largeurdest, hauteurdest);
00056
00057
00058 int mxdest = out.getWidth()/2;
00059 int mydest = out.getHeight()/2;
00060 int mx = in.getWidth()/2;
00061 int my = in.getHeight()/2;
00062
00063 for(int canal=0; canal<in.getNumComponents(); canal++)
00064 for(int j=0;j< out.getHeight();j++)
00065 for(int i=0;i< out.getWidth();i++)
00066 {
00067
00068
00069
00070
00071
00072
00073
00074 int bx = (int) (ceil (tcos * (i-mxdest) + tsin * (j-mydest) + mx));
00075 int by = (int) (ceil (-tsin * (i-mxdest) + tcos * (j-mydest) + my));
00076
00077 if (bx>=0 && bx< in.getWidth() && by>=0 && by< in.getHeight())
00078 {
00079 out.setPixel(i,j, canal, in.getPixel(bx, by, canal));
00080 }
00081 }
00082 }
00083
00084 void Millie::verticalFlipOperator(Image& out, const Image& in)
00085 {
00086
00087
00088
00089 if(out.getNumComponents() != in.getNumComponents())
00090 throw IllegalArgument("verticalFlipOperator");
00091
00092
00093
00094
00095 out.resize(in.getWidth(), in.getHeight());
00096
00097 int largeur = out.getWidth();
00098 int hauteur = out.getHeight();
00099
00100
00101 for(int canal=0; canal< out.getNumComponents(); canal++)
00102 for(int j = 0; j< hauteur; j++)
00103 for(int i = 0; i< largeur; i++)
00104 out.setPixel(i,hauteur-j, canal, in.getPixel(i,j, canal));
00105
00106 }
00107
00108
00109 void Millie::horizontalFlipOperator(Image& out, const Image& in)
00110 {
00111 if(out.getNumComponents() != in.getNumComponents())
00112 throw IllegalArgument("horizontalFlipOperator");
00113
00114 out.resize(in.getWidth(), in.getHeight());
00115
00116 int largeur = out.getWidth();
00117 int hauteur = out.getHeight();
00118
00119 for(int canal=0; canal< out.getNumComponents(); canal++)
00120 for(int j = 0; j< hauteur; j++)
00121 for(int i = 0; i< largeur; i++)
00122 out.setPixel(largeur- i,j, canal, in.getPixel(i,j, canal));
00123
00124 }
00125
00126