00001 #ifndef __RWaveletDenoisingOp__ 00002 #define __RWaveletDenoisingOp__ 00003 00004 00005 00052 #include <stdio.h> 00053 00054 #include "AbsRImageFilter.hpp" 00055 00056 00064 enum WvltDenoising 00065 { 00066 SureShrink=0, 00067 VisuShrink=1, 00068 Brownian=2 00069 }; 00070 00071 #define ABS(x) (((x) < 0) ? -(x) : (x)) 00072 #define MAX(x,y) (((x) < (y)) ? (y) : (x)) 00073 #define MIN(x,y) (((x) < (y)) ? (x) : (y)) 00074 #define WAVELETS 6 /* The number of different wavelets available */ 00075 00076 typedef double dtype; 00077 typedef unsigned char byte; 00078 00079 00080 /* Data type for the wavelet filters */ 00081 #define MAX_COEFS 25 /* maximum number of filter taps allowed */ 00082 typedef struct 00083 { 00084 int length; /* number of coefficients in the filter */ 00085 int offset; /* location of the z0 tap */ 00086 double coefs[MAX_COEFS]; /* the filter coefficents */ 00087 } Filter; 00088 00089 class RWaveletDenoisingOp : public AbsRImageFilter 00090 { 00091 private: 00092 00093 int arg; // array index for processing command line 00094 00095 WvltDenoising algorithm; // denoising algorithm to apply 00096 float alpha; // level of confidence for brownian shrinkage 00097 00098 int cols; // number of columns in 2-D data 00099 int rows; // number of rows in 2-D data 00100 double *data; // array of input data 00101 int dimensions; // dimensions in input data (1 or 2) WE USE 2D images 00102 double **image; // image input data 00103 00104 int levels; // number of times to apply wavelet transform 00105 int longest; // length of longest filter in QMF chosen 00106 int maxLevels; // maximum levels of transform allowable 00107 int n; // number of data points 00108 00109 int verbose; // flag to print out extra information 00110 00111 int wavelet; // id of the wavelet QMF to use 00112 00113 /* Wavelet filters */ 00114 Filter* flo; // Forward lowpass filters 00115 Filter* fhi; // Forward highpass filters 00116 Filter* ilo; // Inverse lowpass filters 00117 Filter* ihi; // Inverse highpass filters 00118 00119 private: 00120 00121 /* function prototypes local to denoise.c */ 00122 double bpThreshold2D(RImage* data, int rows, int cols, float criticalPt); 00123 void brownianBridge2D(RImage* data, int rows, int cols); 00124 double estimateNoise2D(RImage* data, int rows, int cols); 00125 00126 double sureThreshold(double *data, int n); 00127 void thresholdDetail(RImage* data, int rows, int cols, int level, int detail, double threshold); 00128 00129 protected: 00130 00131 /* initialize the wavelet subband filters filters.c */ 00132 void InitializeFilters(); 00133 00134 /* utils.c */ 00135 void BoundingBox(int rows, int cols, int level, int detail, int *left, int *right, int *top, int *bottom); 00136 RImage* ExtractDetail(RImage* m, int rows, int cols, int level, int detail); 00137 int isDyadic(int x); 00138 int myLog2(int x); 00139 int power2(int x); 00140 00141 /* denoise.c */ 00142 void bpShrink2D(RImage* data, int rows, int cols, int levels, float alpha); 00143 void sureShrink2D(RImage* data, int rows, int cols, int levels); 00144 void visuShrink2D(RImage* data, int rows, int cols, int levels); 00145 00146 /* wavelet.c forward/backward transforms */ 00147 void FwtMatrix(RImage* source, RImage* dest, int rows, int cols, int levels, 00148 Filter *lowpass, Filter *hipass); 00149 void IwtMatrix(RImage* source, RImage* dest, int rows, int cols, int levels, 00150 Filter *lowpass, Filter *hipass); 00151 00152 void FwtVector(double *source, double *dest, int length, int levels, 00153 Filter *lowpass, Filter *hipass); 00154 void IwtVector(double *source, double *dest, int length, int levels, 00155 Filter *lowpass, Filter *hipass); 00156 00157 public: 00158 00159 RWaveletDenoisingOp(); 00160 RWaveletDenoisingOp(WvltDenoising type, int levels, int waveletId=0); 00161 virtual ~RWaveletDenoisingOp(); 00162 00163 // single shot filtering 00164 virtual RImage* filter(RImage* src, RImage* dest=0); 00165 virtual RImage* selectedFilter(AnImage* mask, RImage* src, RImage* dest) 00166 { return filter(src, dest); } 00167 00168 virtual void report(FILE* file){ fprintf(file,"Real Gradient Operator\n"); } 00169 }; 00170 00171 00172 #endif