00001 #ifndef __RImage__ 00002 #define __RImage__ 00003 00004 00005 00027 #include <stdio.h> 00028 #include <math.h> 00029 #include <memory.h> 00030 00031 #include "AnImage.hpp" 00032 00033 #include "AbsLimiter.hpp" 00034 00035 class FImage; 00036 00037 class RImage 00038 { 00039 private: 00040 00041 bool normalisation; // 0..1 range 00042 int width; 00043 int height; 00044 00045 int channel; 00046 00047 double* p1; 00048 double** data; 00049 00050 double PI; 00051 00052 00053 public: 00054 00055 RImage( int w, int h ); 00056 RImage( int w, int h , double value); 00057 RImage( AnImage* source ); 00058 RImage( AnImage* source , int achannel ); 00059 RImage( AnImage* source, bool normalized ); 00060 RImage( RImage& im); // copy 00061 RImage( FImage& im); 00062 00063 ~RImage(){ delete[] data; delete[] p1; } 00064 00065 RImage* copy(); 00066 RImage* scaleDown(int multiplier=2); 00067 00068 00069 double* getData(){return p1;} 00070 00071 void setAll(double val=0.0); 00072 void set(RImage& im); 00073 void set(RImage& im, int n, int* xp, int* yp); 00074 00075 bool isNormalized(){ return normalisation; } 00076 inline int getWidth(){ return width; } 00077 inline int getHeight(){ return height; } 00078 00079 00080 inline double get(int x, int y){ return data[x][y]; } 00081 inline void set(int x,int y, double value){ data[x][y]= value; } 00082 00083 double getSafe(int x, int y); 00084 void setSafe(int x,int y, double value); 00085 00086 void gdistance1( double value ); 00087 void gdistance2( double value ); 00088 00089 // compute simple operations 00090 00091 void operator*=( double value ); 00092 void operator/=( double value ); 00093 void operator+=( double value ); 00094 void operator-=( double value ); 00095 00096 void operator+=( RImage& image ); 00097 void operator-=( RImage& image ); 00098 00099 void mult( double rsat ); 00100 void limit( double rmin, double rmax ); 00101 00102 void convolveHV(int m1, int m2, int m3); // near inplace 00103 00104 void inverse(double biais=0.0000001); 00105 void ln(double biais=0.0); 00106 void exp(); 00107 void root(); 00108 void sqr(); 00109 void power(double value); 00110 00111 double HG(int x,int y); // Godunov hamiltonian approximating |grad u| 00112 00113 double laplacian(int x, int y); 00114 double isometricLaplacian(int x, int y); 00115 double normeGradient(int x, int y, double epsilon=1e-8); 00116 00117 double TVnormCentral(); 00118 double TVnormMinmod(); // mostly used to preserve boundaries of image features (! is diffusive) 00119 double TVnorm(AbsLimiter* alimiter); // support for less diffuse limiters 00120 00121 // Adaptive tv norm is reduced at edges and increased in noise 00122 // "Adaptive Total Variation Minimizing Image Restoration", David Moroni Strong, Thesis, UCLA 1997 00123 double adaptiveTVnormCentral(); 00124 double adaptiveTVnormMinmod(); // mostly used to preserve boundaries of image features (! is diffusive) 00125 double adaptiveTVnorm(AbsLimiter* alimiter); // support for less diffuse limiters 00126 00127 // Image quality 00128 // ============= 00129 00130 // Speckle Measure 00131 double sigmaMeanRatio(); // sigma/mean 00132 double logSigma(); // log sigma in (DB) 00133 00134 // Image comparisions 00135 double SNR(RImage& result) // signal to noise ratio: SNR= -10 log10(errorPLSE) 00136 { return -10.0*::log( errorPLSE(result) ); } 00137 00138 double errorPLSE(RImage& result); // Peak Least Square Error 00139 double SE(RImage& result); // square error or variance of an image 00140 double MSE(RImage& result) // mean square error or variance of an image 00141 { return SE(result)/(width*height); } 00142 double NMSE(RImage& result); // normalised MSE 00143 double RMSE(RImage& result) // root MSE 00144 { return ::sqrt(MSE(result)); } 00145 double PSNR(RImage& result, double maxRange=255) // max peak to noise ratio 00146 { return 20*log(maxRange/RMSE(result)); } 00147 00148 00149 double meanCurvature(int x, int y); 00150 double curvature(int x, int y); 00151 00152 double gij(int i, int j, int x, int y); 00153 double lambdaPlus(int x,int y); 00154 double lambdaMinus(int x,int y); 00155 double normalDirection(int x, int y); 00156 double tangentDirection(int x, int y){ return (normalDirection(x,y)+PI/2.0); } 00157 00158 // central differences 00159 double dfX_0(int x, int y); 00160 double dfY_0(int x, int y); 00161 00162 double dfX_0_div2(int x, int y, int idx, int idy); // step demi by averaging 00163 double dfY_0_div2(int x, int y, int idx, int idy); 00164 00165 double dfX_0_div2MinMod(int x, int y, int idx, int idy); // step demi by minmod 00166 double dfY_0_div2MinMod(int x, int y, int idx, int idy); 00167 00168 double dfX_0_div2Limiter(AbsLimiter* limiter, int x, int y, int idx, int idy); 00169 double dfY_0_div2Limiter(AbsLimiter* limiter, int x, int y, int idx, int idy); 00170 00171 double dfX_0_2(int x, int y); // step 2 00172 double dfY_0_2(int x, int y); 00173 00174 // oriented differences FO 00175 double dfX_p1(int x, int y); 00176 double dfY_p1(int x, int y); 00177 double dfX_m1(int x, int y); 00178 double dfY_m1(int x, int y); 00179 00180 // diff of ENO order 2 00181 // "Numerical Methods for Advancing Interfaces.", Seongjai Kim, Report 2000, University of Kentucky. 00182 double dfX_ENO2_p1(int x, int y); 00183 double dfY_ENO2_p1(int x, int y); 00184 double dfX_ENO2_m1(int x, int y); 00185 double dfY_ENO2_m1(int x, int y); 00186 00187 // diff of Upwind ENO order 2 00188 // "Numerical Methods for Advancing Interfaces.", Seongjai Kim, Report 2000, University of Kentucky. 00189 double dfX_UpwindENO2(int x, int y); 00190 double dfY_UpwindENO2(int x, int y); 00191 00192 // diff of ENO order 3 00193 // "Numerical Methods for Advancing Interfaces.", Seongjai Kim, Report 2000, University of Kentucky. 00194 double dfX_ENO3_p1(int x, int y); 00195 double dfY_ENO3_p1(int x, int y); 00196 double dfX_ENO3_m1(int x, int y); 00197 double dfY_ENO3_m1(int x, int y); 00198 00199 // diff of Upwind ENO order 3 00200 // "Numerical Methods for Advancing Interfaces.", Seongjai Kim, Report 2000, University of Kentucky. 00201 double dfX_UpwindENO3(int x, int y); 00202 double dfY_UpwindENO3(int x, int y); 00203 00204 00205 // diff if WENO 3 00206 // "An Adaptive Finit Difference Method for Traveltime and Amplitude", J Qian & W. W. Symes, Report of Rice Univ. 00207 double dfX_WENO3_p1(int x, int y, double eps=1e-12); 00208 double dfY_WENO3_p1(int x, int y, double eps=1e-12); 00209 double dfX_WENO3_m1(int x, int y, double eps=1e-12); 00210 double dfY_WENO3_m1(int x, int y, double eps=1e-12); 00211 00212 // second differential 00213 double dfX2(int x, int y); 00214 double dfY2(int x, int y); 00215 double dfXY(int x, int y); 00216 double dfXYc(int x, int y); 00217 00218 double dfX2pp(int x, int y); 00219 double dfY2pp(int x, int y); 00220 double dfX2pm(int x, int y); 00221 double dfY2pm(int x, int y); 00222 double dfX2mp(int x, int y); 00223 double dfY2mp(int x, int y); 00224 double dfX2mm(int x, int y); 00225 double dfY2mm(int x, int y); 00226 00227 double dfX2_2(int x, int y); // step 2 00228 double dfY2_2(int x, int y); 00229 double dfXY_2(int x, int y); 00230 00231 // third differential 00232 double dfX3(int x, int y); 00233 double dfY3(int x, int y); 00234 00235 double dfX3ppp(int x, int y); 00236 double dfY3ppp(int x, int y); 00237 double dfX3ppm(int x, int y); 00238 double dfY3ppm(int x, int y); 00239 double dfX3pmm(int x, int y); 00240 double dfY3pmm(int x, int y); 00241 double dfX3mmm(int x, int y); 00242 double dfY3mmm(int x, int y); 00243 00244 00245 // derivee 1 along normal 00246 double In(int x, int y); 00247 double In(AbsLimiter* limiter, int x, int y); 00248 double InMinmod(int x, int y); 00249 00250 // derivee 2 along normal 00251 double Inn(int x, int y); 00252 00253 // derivee 2 along tangent 00254 double Iee(int x, int y); 00255 00256 // general diff operators 00257 double g(int x, int y, int p=1); 00258 00259 double peronaMalikOperator(int x, int y); 00260 double meanCurvatureOperator(int x, int y); 00261 double beltramiOperator(int x, int y); 00262 00263 double gradCorrectiveViscosity(int x, int y); 00264 00265 void peronaMalikOperation(RImage& image, double coefficient); 00266 void peronaMalikRestoration(int nIterations, double coefficient); 00267 00268 void geodesicPeronaMalikOperation(RImage& image, double coefficient, double cgeod); 00269 void geodesicPeronaMalikRestoration(int nIterations, double coefficient, double cgeod); 00270 00271 void meanCurvatureOperation(RImage& image, double coefficient); 00272 void meanCurvatureRestoration(int nIterations, double coefficient); 00273 00274 void geodesicMeanCurvatureOperation(RImage& image, double coefficient, double cgeod); 00275 void geodesicMeanCurvatureRestoration(int nIterations, double coefficient, double cgeod); 00276 00277 void beltramiOperation(RImage& image, double coefficient); 00278 void beltramiRestoration(int nIterations, double coefficient); 00279 00280 void geodesicBeltramiOperation(RImage& image, double coefficient, double cgeod); 00281 void geodesicBeltramiRestoration(int nIterations, double coefficient, double cgeod); 00282 }; 00283 00284 #endif