00001 #ifndef __FImage__ 00002 #define __FImage__ 00003 00004 00005 00024 #include <stdio.h> 00025 #include <math.h> 00026 #include <memory.h> 00027 00028 #include "AnImage.hpp" 00029 00030 #ifdef _SSE1_USED 00031 #include "sseUtil.h" 00032 #else 00033 #define SSE_PAD 4 00034 #endif 00035 00036 class FImage 00037 { 00038 private: 00039 00040 bool normalisation; // 0..1 range 00041 int width; 00042 int height; 00043 00044 int channel; 00045 00046 float* palign; 00047 float* p1; 00048 float** data; 00049 00050 float* pPlus1; 00051 float** dataPlus1; 00052 00053 float* pMin1; 00054 float** dataMin1; 00055 00056 double PI; 00057 00058 00059 public: 00060 00061 FImage( int w, int h ); 00062 FImage( int w, int h , float value); 00063 FImage( AnImage* source ); 00064 FImage( AnImage* source , int achannel ); 00065 FImage( AnImage* source, bool normalized ); 00066 FImage( FImage& im); // copy 00067 00068 ~FImage(){ delete[] palign; delete[] data; delete[] dataPlus1; delete[] dataMin1; p1=0; } 00069 00070 FImage* copy(); 00071 FImage* scaleDown(int multiplier=2); 00072 00073 float* getData(){return p1;} 00074 00075 void setAll(float val=0.0); 00076 void set(FImage& im); 00077 void set(FImage& im, int n, int* xp, int* yp); 00078 00079 void setInZeroOneBox(float minVal=0.0, float maxVal=255.0); 00080 void setOutZeroOneBox(float minVal=0.0, float maxVal=255.0); 00081 00082 bool isNormalized(){ return normalisation; } 00083 inline int getWidth(){ return width; } 00084 inline int getHeight(){ return height; } 00085 00086 00087 inline float get(int x, int y){ return data[x][y]; } 00088 inline void set(int x,int y, float value){ data[x][y]= value; } 00089 00090 inline float getHMin1(int x, int y){ return dataMin1[x][y]; } 00091 inline void setHMin1(int x,int y, float value){ dataMin1[x][y]= value; } 00092 00093 inline float getHPlus1(int x, int y){ return dataPlus1[x][y]; } 00094 inline void setHPlus1(int x,int y, float value){ dataPlus1[x][y]= value; } 00095 00096 float getSafe(int x, int y); 00097 void setSafe(int x,int y, float value); 00098 00099 void gdistance1( float value ); 00100 void gdistance2( float value ); 00101 00102 // compute simple operations 00103 00104 void operator*=( float value ); 00105 void operator/=( float value ); 00106 void operator+=( float value ); 00107 void operator-=( float value ); 00108 00109 void operator+=( FImage& image ); 00110 void operator-=( FImage& image ); 00111 00112 void mult( float rsat ); 00113 void limit( float rmin, float rmax ); 00114 00115 void convolveHV(int m1, int m2, int m3); // near inplace 00116 void convolveHV(int m1, int m2, int m3, int m4, int m5); 00117 void convolveHV(int m1, int m2, int m3, int m4, int m5, int m6, int m7); 00118 00119 void inverse(float biais=0.0000001); 00120 void ln(float biais=1.0); 00121 void exp(); 00122 void root(); 00123 void sqr(); 00124 void power(float value); 00125 00126 // Image quality 00127 // ============= 00128 00129 // Speckle Measure 00130 float sigmaMeanRatio(); // sigma/mean 00131 float logSigma(); // log sigma in (DB) 00132 00133 // Image comparisions 00134 float SNR(FImage& result) // signal to noise ratio: SNR= -10 log10(errorPLSE) 00135 { return -10.0*::log( errorPLSE(result) ); } 00136 00137 float errorPLSE(FImage& result); // Peak Least Square Error 00138 double SE(FImage& result); // square error 00139 float MSE(FImage& result) // mean square error or variance of an image 00140 { return SE(result)/(width*height); } 00141 float NMSE(FImage& result); // normalised MSE 00142 float RMSE(FImage& result) // root MSE 00143 { return ::sqrt(MSE(result)); } 00144 float PSNR(FImage& result, float maxRange=255) // max peak to noise ratio 00145 { return 20*log(maxRange/RMSE(result)); } 00146 00147 00148 float laplacian(int x, int y); 00149 float isometricLaplacian(int x, int y); 00150 float normeGradient(int x, int y, float epsilon=1e-8); 00151 00152 00153 float meanCurvature(int x, int y); 00154 float curvature(int x, int y); 00155 00156 float gij(int i, int j, int x, int y); 00157 float lambdaPlus(int x,int y); 00158 float lambdaMinus(int x,int y); 00159 float normalDirection(int x, int y); 00160 float tangentDirection(int x, int y){ return (normalDirection(x,y)+PI/2.0); } 00161 00162 // central differences 00163 float dfX_0(int x, int y); 00164 float dfY_0(int x, int y); 00165 00166 float dfX_0_div2(int x, int y, int idx, int idy); // step demi by averaging 00167 float dfY_0_div2(int x, int y, int idx, int idy); 00168 00169 float dfX_0_div2MinMod(int x, int y, int idx, int idy); // step demi by minmod 00170 float dfY_0_div2MinMod(int x, int y, int idx, int idy); 00171 00172 float dfX_0_2(int x, int y); // step 2 00173 float dfY_0_2(int x, int y); 00174 00175 // oriented differences 00176 float dfX_p1(int x, int y); 00177 float dfY_p1(int x, int y); 00178 float dfX_m1(int x, int y); 00179 float dfY_m1(int x, int y); 00180 00181 // second differential 00182 float dfX2(int x, int y); 00183 float dfY2(int x, int y); 00184 float dfXY(int x, int y); 00185 float dfXYc(int x, int y); 00186 00187 float dfX2_2(int x, int y); // step 2 00188 float dfY2_2(int x, int y); 00189 float dfXY_2(int x, int y); 00190 00191 // third differential 00192 float dfX3(int x, int y); 00193 float dfY3(int x, int y); 00194 00195 00196 // derivee 1 along normal 00197 float In(int x, int y); 00198 00199 // derivee 2 along normal 00200 float Inn(int x, int y); 00201 00202 // derivee 2 along tangent 00203 float Iee(int x, int y); 00204 00205 // general diff operators 00206 float g(int x, int y, int p=1); 00207 00208 float peronaMalikOperator(int x, int y); 00209 float meanCurvatureOperator(int x, int y); 00210 float beltramiOperator(int x, int y); 00211 00212 float gradCorrectiveViscosity(int x, int y); 00213 00214 void peronaMalikOperation(FImage& image, float coefficient); 00215 void peronaMalikRestoration(int nIterations, float coefficient); 00216 00217 void geodesicPeronaMalikOperation(FImage& image, float coefficient, float cgeod); 00218 void geodesicPeronaMalikRestoration(int nIterations, float coefficient, float cgeod); 00219 00220 void meanCurvatureOperation(FImage& image, float coefficient); 00221 void meanCurvatureRestoration(int nIterations, float coefficient); 00222 00223 void geodesicMeanCurvatureOperation(FImage& image, float coefficient, float cgeod); 00224 void geodesicMeanCurvatureRestoration(int nIterations, float coefficient, float cgeod); 00225 00226 void beltramiOperation(FImage& image, float coefficient); 00227 void beltramiRestoration(int nIterations, float coefficient); 00228 00229 void geodesicBeltramiOperation(FImage& image, float coefficient, float cgeod); 00230 void geodesicBeltramiRestoration(int nIterations, float coefficient, float cgeod); 00231 }; 00232 00233 #endif