Xmipp  v3.23.11-Nereus
wavelet.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  * Antonio Jose Rodriguez Sanchez (ajr@cnb.csic.es)
5  * Arun Kulshreshth (arun_2000_iitd@yahoo.com)
6  *
7  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22  * 02111-1307 USA
23  *
24  * All comments concerning this program package may be sent to the
25  * e-mail address 'xmipp@cnb.csic.es'
26  ***************************************************************************/
27 
28 #ifndef CORE_WAVELET_H
29 #define CORE_WAVELET_H
30 
31 #include <core/multidim_array.h>
32 #include <core/numerical_recipes.h>
33 
36 
37 #define HAAR 2
38 #define DAUB4 4
39 #define DAUB12 12
40 #define DAUB20 20
41 
43 
44 
54 void Bilib_DWT(const MultidimArray< double >& input,
56  int iterations,
57  int isign = 1);
58 
64 void set_DWT_type(int DWT_type);
65 
71 inline int Get_Max_Scale(int size)
72 {
73  return ROUND(log10(static_cast< double >(size)) / log10(2.0));
74 }
75 
82 template<typename T>
83 void DWT(const MultidimArray< T >& v, MultidimArray< double >& result, int isign = 1)
84 {
85  unsigned long int nn[3];
86  unsigned long int *ptr_nn = nn - 1;
87  int dim;
88  nn[2] = ZSIZE(v);
89  nn[1] = YSIZE(v);
90  nn[0] = XSIZE(v);
91 
92  if (YSIZE(v) == 1 && ZSIZE(v) == 1)
93  dim = 1;
94  else if (ZSIZE(v) == 1)
95  dim = 2;
96  else
97  dim = 3;
98 
99  typeCast(v, result);
100  double* ptr_result = MULTIDIM_ARRAY(result) - 1;
101  wtn(ptr_result, ptr_nn, dim, isign, pwt);
102 }
103 
111 
113 
114 
121 
122 #define DWT_Imin(s, smax, l) static_cast< int >(((l == '0') ? 0 : \
123  pow(2.0, smax - s - 1)))
124 #define DWT_Imax(s, smax, l) static_cast< int>(((l == '0') ? \
125  pow(2.0, smax - s - 1) - 1 : pow(2.0, smax - s) - 1))
126 
133 template<typename T>
134 void SelectDWTBlock(int scale,
135  const MultidimArray< T >& I,
136  const std::string& quadrant,
137  int& x1,
138  int& x2)
139 {
140  double Nx = Get_Max_Scale(XSIZE(I));
141  I.toLogical(DWT_Imin(scale, Nx, quadrant[0]), x1);
142  I.toLogical(DWT_Imax(scale, Nx, quadrant[0]), x2);
143 }
144 
152 template<typename T>
153 void SelectDWTBlock(int scale,
154  const MultidimArray< T >& I,
155  const std::string& quadrant,
156  int& x1,
157  int& x2,
158  int& y1,
159  int& y2)
160 {
161  double Nx = Get_Max_Scale(XSIZE(I));
162  double Ny = Get_Max_Scale(YSIZE(I));
163 
164  x1 = DWT_Imin(scale, Nx, quadrant[0]);
165  y1 = DWT_Imin(scale, Ny, quadrant[1]);
166  x2 = DWT_Imax(scale, Nx, quadrant[0]);
167  y2 = DWT_Imax(scale, Ny, quadrant[1]);
168 
169  I.toLogical(y1, x1, y1, x1);
170  I.toLogical(y2, x2, y2, x2);
171 }
172 
173 
181 template<typename T>
182 void SelectDWTBlock(int scale,
183  const MultidimArray< T >& I,
184  const std::string& quadrant,
185  int& x1,
186  int& x2,
187  int& y1,
188  int& y2,
189  int& z1,
190  int& z2)
191 {
192  double Nx = Get_Max_Scale(XSIZE(I));
193  double Ny = Get_Max_Scale(YSIZE(I));
194  double Nz = Get_Max_Scale(ZSIZE(I));
195 
196  x1 = DWT_Imin(scale, Nx, quadrant[0]);
197  y1 = DWT_Imin(scale, Ny, quadrant[1]);
198  z1 = DWT_Imin(scale, Nz, quadrant[2]);
199  x2 = DWT_Imax(scale, Nx, quadrant[0]);
200  y2 = DWT_Imax(scale, Ny, quadrant[1]);
201  z2 = DWT_Imax(scale, Nz, quadrant[2]);
202 
203  I.toLogical(z1, y1, x1, z1, y1, x1);
204  I.toLogical(z2, y2, x2, z2, y2, x2);
205 }
206 
207 
212 std::string Quadrant2D(int q);
213 
218 std::string Quadrant3D(int q);
219 
225 void Get_Scale_Quadrant(int size_x, int x, int& scale, std::string& quadrant);
226 
232 void Get_Scale_Quadrant(int size_x,
233  int size_y,
234  int x,
235  int y,
236  int& scale,
237  std::string& quadrant);
238 
244 void Get_Scale_Quadrant(int size_x,
245  int size_y,
246  int size_z,
247  int x,
248  int y,
249  int z,
250  int& scale,
251  std::string& quadrant);
253 
255 
256 
260  int scale,
261  const std::string& quadrant);
262 
266  int scale,
267  const std::string& quadrant);
268 
274 void soft_thresholding(MultidimArray< double >& I, double th);
275 
281 
287 
299  int allowed_scale,
300  double SNR0 = 0.1,
301  double SNRF = 0.2,
302  bool white_noise = false,
303  int tell = 0,
304  bool denoise = true);
305 
311  int allowed_scale,
312  Matrix1D< double >& estimatedS);
313 
325  int allowed_scale,
326  double SNR0 = 0.1,
327  double SNRF = 0.2,
328  bool white_noise = false,
329  int tell = 0,
330  bool denoise = true);
331 
337  int allowed_scale,
338  Matrix1D< double >& estimatedS);
339 
377  MultidimArray< double >& Energy,
378  MultidimArray< double >& lowPass,
379  MultidimArray< double >& Radius,
380  MultidimArray< std::complex <double> >& H,
381  int nScale,
382  double minWaveLength,
383  double mult,
384  double sigmaOnf
385  );
386 
388 
389 #endif
void phaseCongMono(MultidimArray< double > &I, MultidimArray< double > &PC, MultidimArray< double > &FT, MultidimArray< double > &Energy, MultidimArray< double > &lowPass, MultidimArray< double > &Radius, MultidimArray< std::complex< double > > &H, int nScale, double minWaveLength, double mult, double sigmaOnf)
Definition: wavelet.cpp:850
#define YSIZE(v)
void Bilib_DWT(const MultidimArray< double > &input, MultidimArray< double > &result, int iterations, int isign=1)
Definition: wavelet.cpp:43
void set_DWT_type(int DWT_type)
Definition: wavelet.cpp:154
int Get_Max_Scale(int size)
Definition: wavelet.h:71
void wtn(double a[], unsigned long nn[], int ndim, int isign, void(*wtstep)(double [], unsigned long, int))
void DWT_lowpass2D(const MultidimArray< double > &v, MultidimArray< double > &result)
Definition: wavelet.cpp:165
#define DWT_Imax(s, smax, l)
Definition: wavelet.h:124
void clean_quadrant3D(MultidimArray< double > &I, int scale, const std::string &quadrant)
Definition: wavelet.cpp:297
static double * y
#define MULTIDIM_ARRAY(v)
i<=ncnstr;i++) cs[i].mult=0.e0;if(nfsip) for(i=1;i<=nob;i++) { ob[i].mult=0.e0;ob[i].mult_L=0.e0;} for(i=1;i<=nqpram;i++) { ii=k+i;if(clamda[ii]==0.e0 &&clamda[ii+nqpram]==0.e0) continue;else if(clamda[ii] !=0.e0) clamda[ii]=-clamda[ii];else clamda[ii]=clamda[ii+nqpram];} nqnp=nqpram+ncnstr;for(i=1;i<=nqpram;i++) param-> mult[i]
doublereal * x
void clean_quadrant2D(MultidimArray< double > &I, int scale, const std::string &quadrant)
Definition: wavelet.cpp:288
Matrix1D< double > bayesian_wiener_filtering2D(MultidimArray< double > &WI, int allowed_scale, double SNR0=0.1, double SNRF=0.2, bool white_noise=false, int tell=0, bool denoise=true)
Definition: wavelet.cpp:603
#define DWT_Imin(s, smax, l)
Definition: wavelet.h:122
std::string Quadrant3D(int q)
Definition: wavelet.cpp:208
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
Definition: wavelet.h:83
#define XSIZE(v)
void adaptive_soft_thresholding2D(MultidimArray< double > &I, int scale)
Definition: wavelet.cpp:384
#define ZSIZE(v)
double z
#define ROUND(x)
Definition: xmipp_macros.h:210
void log10(Image< double > &op)
void SelectDWTBlock(int scale, const MultidimArray< T > &I, const std::string &quadrant, int &x1, int &x2)
Definition: wavelet.h:134
Matrix1D< double > bayesian_wiener_filtering3D(MultidimArray< double > &WI, int allowed_scale, double SNR0=0.1, double SNRF=0.2, bool white_noise=false, int tell=0, bool denoise=true)
Definition: wavelet.cpp:726
void toLogical(int k_phys, int i_phys, int j_phys, int &k_log, int &i_log, int &j_log) const
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227
std::string Quadrant2D(int q)
Definition: wavelet.cpp:187
void DWT_keep_central_part(MultidimArray< double > &I, double R)
Definition: wavelet.cpp:396
void IDWT(const MultidimArray< double > &v, MultidimArray< double > &result)
Definition: wavelet.cpp:159
void soft_thresholding(MultidimArray< double > &I, double th)
Definition: wavelet.cpp:308
void pwt(double a[], unsigned long n, int isign)
void Get_Scale_Quadrant(int size_x, int x, int &scale, std::string &quadrant)
Definition: wavelet.cpp:248