Xmipp  v3.23.11-Nereus
Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
WaveletFilter Class Reference

#include <denoise.h>

Inheritance diagram for WaveletFilter:
Inheritance graph
[legend]
Collaboration diagram for WaveletFilter:
Collaboration graph
[legend]

Public Types

enum  DenoisingType {
  REMOVE_SCALE, SOFT_THRESHOLDING, BAYESIAN, ADAPTIVE_SOFT,
  CENTRAL
}
 

Public Member Functions

void readParams (XmippProgram *program)
 
 WaveletFilter ()
 
void produceSideInfo ()
 
void show ()
 
void apply (MultidimArray< double > &img)
 
void denoiseAvgBayesian (MultidimArray< double > &vol)
 
- Public Member Functions inherited from XmippFilter
virtual ~XmippFilter ()
 

Static Public Member Functions

static void defineParams (XmippProgram *program)
 

Public Attributes

String DWT_type
 
DenoisingType denoising_type
 
int scale
 
int output_scale
 
double threshold
 
int R
 
double SNR0
 
double SNRF
 
bool white_noise
 
bool adjust_range
 
int verbose
 
bool dont_denoise
 
Matrix1D< double > estimatedS
 

Detailed Description

Parameters for denoise program

Definition at line 36 of file denoise.h.

Member Enumeration Documentation

◆ DenoisingType

Enumerator
REMOVE_SCALE 
SOFT_THRESHOLDING 
BAYESIAN 
ADAPTIVE_SOFT 
CENTRAL 

Definition at line 39 of file denoise.h.

Constructor & Destructor Documentation

◆ WaveletFilter()

WaveletFilter::WaveletFilter ( )

Empty constructor

Definition at line 32 of file denoise.cpp.

33 {
34  DWT_type = "DAUB12";
36  scale = 0;
37  output_scale = 0;
38  threshold = 50;
39  R = -1;
40  SNR0 = 1.0 / 10;
41  SNRF = 1.0 / 5;
42  white_noise = false;
43  adjust_range = true;
44  verbose = 0;
45  dont_denoise = false;
46 }
int output_scale
Definition: denoise.h:75
bool dont_denoise
Definition: denoise.h:111
String DWT_type
Definition: denoise.h:52
bool white_noise
Definition: denoise.h:95
double SNR0
Definition: denoise.h:87
double threshold
Definition: denoise.h:79
bool adjust_range
Definition: denoise.h:99
DenoisingType denoising_type
Definition: denoise.h:59
double SNRF
Definition: denoise.h:91

Member Function Documentation

◆ apply()

void WaveletFilter::apply ( MultidimArray< double > &  img)
virtual

Denoise an image.

Implements XmippFilter.

Definition at line 149 of file denoise.cpp.

150 {
151  if (img.getDim()==2)
152  {
153  // 2D image denoising
155  img.rangeAdjust(0, 1);
156 
157  double size2 = log10((double)XSIZE(img)) / log10(2.0);
158  if (ABS(size2 - ROUND(size2)) > 1e-6)
159  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Input image must be of a size power of 2");
160  size2 = log10((double)YSIZE(img)) / log10(2.0);
161  if (ABS(size2 - ROUND(size2)) > 1e-6)
162  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Input image must be of a size power of 2");
163  DWT(img, img);
164  Histogram1D hist;
165  switch (denoising_type)
166  {
167  case REMOVE_SCALE:
168  clean_quadrant2D(img, scale, "01");
169  clean_quadrant2D(img, scale, "10");
170  clean_quadrant2D(img, scale, "11");
171  break;
172  case SOFT_THRESHOLDING:
173  compute_hist(img, hist, 100);
175  break;
176  case BAYESIAN:
179  break;
180  case ADAPTIVE_SOFT:
182  break;
183  case CENTRAL:
184  DWT_keep_central_part(img, R);
185  break;
186  }
187  if (output_scale != 0)
188  {
189  auto reduction = (int)pow(2.0, output_scale);
190  img.resize(YSIZE(img) / reduction, XSIZE(img) / reduction);
191  }
192  IDWT(img, img);
193  }
194  else
195  {
196  // 3D image denoising
197  double size2 = log10((double)XSIZE(img)) / log10(2.0);
198  if (ABS(size2 - ROUND(size2)) > 1e-6)
199  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Input volume must be of a size power of 2");
200  size2 = log10((double)YSIZE(img)) / log10(2.0);
201  if (ABS(size2 - ROUND(size2)) > 1e-6)
202  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Input volume must be of a size power of 2");
203  size2 = log10((double)ZSIZE(img)) / log10(2.0);
204  if (ABS(size2 - ROUND(size2)) > 1e-6)
205  REPORT_ERROR(ERR_MULTIDIM_SIZE, "Input volume must be of a size power of 2");
206 
207  DWT(img, img);
208  Histogram1D hist;
209  switch (denoising_type)
210  {
211  case REMOVE_SCALE:
212  clean_quadrant3D(img, scale, "001");
213  clean_quadrant3D(img, scale, "010");
214  clean_quadrant3D(img, scale, "011");
215  clean_quadrant3D(img, scale, "100");
216  clean_quadrant3D(img, scale, "101");
217  clean_quadrant3D(img, scale, "110");
218  clean_quadrant3D(img, scale, "111");
219  break;
220  case SOFT_THRESHOLDING:
221  compute_hist(img, hist, 100);
223  break;
224  case BAYESIAN:
227  break;
228  case ADAPTIVE_SOFT:
229  std::cout << "Adaptive soft-thresholding not implemented for imgumes\n";
230  break;
231  case CENTRAL:
232  std::cout << "Keep central part not implemented for volumes\n";
233  break;
234  }
235 
236  if (output_scale != 0)
237  {
238  auto reduction = (int)pow(2.0, output_scale);
239  img.resizeNoCopy(ZSIZE(img) / reduction, YSIZE(img) / reduction, XSIZE(img) / reduction);
240  }
241  IDWT(img, img);
242 
243  }
244 }
int output_scale
Definition: denoise.h:75
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
bool dont_denoise
Definition: denoise.h:111
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void resizeNoCopy(const MultidimArray< T1 > &v)
void clean_quadrant3D(MultidimArray< double > &I, int scale, const std::string &quadrant)
Definition: wavelet.cpp:297
bool white_noise
Definition: denoise.h:95
double SNR0
Definition: denoise.h:87
void rangeAdjust(T minF, T maxF)
double percentil(double percent_mass)
Definition: histogram.cpp:160
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
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, double SNRF, bool white_noise, int tell, bool denoise)
Definition: wavelet.cpp:603
double threshold
Definition: denoise.h:79
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
Definition: wavelet.h:83
bool adjust_range
Definition: denoise.h:99
#define XSIZE(v)
void adaptive_soft_thresholding2D(MultidimArray< double > &I, int scale)
Definition: wavelet.cpp:384
#define ABS(x)
Definition: xmipp_macros.h:142
#define ZSIZE(v)
#define ROUND(x)
Definition: xmipp_macros.h:210
void log10(Image< double > &op)
Matrix1D< double > bayesian_wiener_filtering3D(MultidimArray< double > &WI, int allowed_scale, double SNR0, double SNRF, bool white_noise, int tell, bool denoise)
Definition: wavelet.cpp:726
DenoisingType denoising_type
Definition: denoise.h:59
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
double SNRF
Definition: denoise.h:91
Matrix1D< double > estimatedS
Definition: denoise.h:119

◆ defineParams()

void WaveletFilter::defineParams ( XmippProgram program)
static

Definition at line 49 of file denoise.cpp.

50 {
51  program->addParamsLine("== Wavelet ==");
52  program->addParamsLine(" [--wavelet <DWT_type=DAUB12> <mode=remove_scale>] : Different types of filters using wavelets");
53  program->addParamsLine(" where <DWT_type>");
54  program->addParamsLine(" DAUB4 DAUB12 DAUB20 : Discrete Wavelet Transform");
55  program->addParamsLine(" where <mode>");
56  program->addParamsLine(" remove_scale");
57  program->addParamsLine(" bayesian <SNR0=0.1> <SNRF=0.2> : Smallest(SNR0) and largest(SNRF) SNR.");
58  program->addParamsLine(" soft_thresholding");
59  program->addParamsLine(" adaptive_soft");
60  program->addParamsLine(" central");
61  program->addParamsLine(" alias -w;");
62  program->addParamsLine(" [--scale+ <s=0>] : scale");
63  program->addParamsLine(" [--output_scale+ <s=0>] : output_scale");
64  program->addParamsLine(" [--th+ <th=50>] : threshold of values (%) to remove");
65  program->addParamsLine(" [-R+ <r=-1>] : Radius to keep, by default half the size");
66  program->addParamsLine(" [--white_noise+] : Select if the noise is white. Used by Bayesian filter.");
67 }
void addParamsLine(const String &line)

◆ denoiseAvgBayesian()

void WaveletFilter::denoiseAvgBayesian ( MultidimArray< double > &  vol)

Denoise a volume using a precalculated estimate of the bayesian parameters.

Definition at line 246 of file denoise.cpp.

247 {
248  DWT(vol, vol);
250 
251  if (output_scale != 0)
252  {
253  auto reduction = (int)pow(2.0, output_scale);
254  vol.resizeNoCopy(ZSIZE(vol) / reduction, YSIZE(vol) / reduction, XSIZE(vol) / reduction);
255  }
256  IDWT(vol, vol);
257 }
int output_scale
Definition: denoise.h:75
#define YSIZE(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
Definition: wavelet.h:83
#define XSIZE(v)
#define ZSIZE(v)
Matrix1D< double > bayesian_wiener_filtering3D(MultidimArray< double > &WI, int allowed_scale, double SNR0, double SNRF, bool white_noise, int tell, bool denoise)
Definition: wavelet.cpp:726
void IDWT(const MultidimArray< double > &v, MultidimArray< double > &result)
Definition: wavelet.cpp:159
Matrix1D< double > estimatedS
Definition: denoise.h:119

◆ produceSideInfo()

void WaveletFilter::produceSideInfo ( )

Produce side info.

The DWT type is translated and set

Definition at line 103 of file denoise.cpp.

104 {
105  if (DWT_type == "DAUB4")
107  else if (DWT_type == "DAUB12")
109  else if (DWT_type == "DAUB20")
111  else
112  REPORT_ERROR(ERR_VALUE_INCORRECT, "Unknown DWT type");
113 }
void set_DWT_type(int DWT_type)
Definition: wavelet.cpp:154
String DWT_type
Definition: denoise.h:52
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define DAUB20
Definition: wavelet.h:40
#define DAUB12
Definition: wavelet.h:39
#define DAUB4
Definition: wavelet.h:38
Incorrect value received.
Definition: xmipp_error.h:195

◆ readParams()

void WaveletFilter::readParams ( XmippProgram program)
virtual

Read params from a program

Reimplemented from XmippFilter.

Definition at line 70 of file denoise.cpp.

71 {
72 
73  DWT_type = program->getParam("--wavelet", 0);
74  String mode = program->getParam("--wavelet", 1);
75 
76  if (mode == "remove_scale")
78  else if (mode == "soft_thresholding")
80  else if (mode == "bayesian")
81  {
82  SNR0 = program->getDoubleParam("--wavelet", 2);
83  SNRF = program->getDoubleParam("--wavelet", 3);
85  }
86  else if (mode == "adaptive_soft")
88  else if (mode == "central")
90  else
91  REPORT_ERROR(ERR_DEBUG_IMPOSIBLE, "Bad argument type, this couldn't happens, check arguments parser!!!");
92 
93  scale = program->getIntParam("--scale");
94  output_scale = program->getIntParam("--output_scale");
95  threshold = program->getDoubleParam("--th");
96  R = program->getIntParam("-R");
97  white_noise = program->checkParam("--white_noise");
98  verbose = program->verbose;
100 }
int output_scale
Definition: denoise.h:75
double getDoubleParam(const char *param, int arg=0)
String DWT_type
Definition: denoise.h:52
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Just for debugging, situation that can&#39;t happens.
Definition: xmipp_error.h:120
bool white_noise
Definition: denoise.h:95
double SNR0
Definition: denoise.h:87
double threshold
Definition: denoise.h:79
const char * getParam(const char *param, int arg=0)
int verbose
Verbosity level.
void mode
void produceSideInfo()
Definition: denoise.cpp:103
std::string String
Definition: xmipp_strings.h:34
DenoisingType denoising_type
Definition: denoise.h:59
bool checkParam(const char *param)
double SNRF
Definition: denoise.h:91
int getIntParam(const char *param, int arg=0)

◆ show()

void WaveletFilter::show ( )
virtual

Show some info before running

Show specific options

Reimplemented from XmippFilter.

Definition at line 116 of file denoise.cpp.

117 {
118  if (!verbose)
119  return;
121  std::cout << "DWT type: " << DWT_type << std::endl;
122  std::cout << "Denoising: ";
123  switch (denoising_type)
124  {
125  case REMOVE_SCALE:
126  std::cout << " Remove scale " << scale << std::endl;
127  break;
128  case SOFT_THRESHOLDING:
129  std::cout << " Soft thresholding " << threshold << std::endl;
130  break;
131  case BAYESIAN:
132  std::cout << " Bayesian\n";
133  std::cout << " SNR between " << SNR0 << " and " << SNRF << std::endl
134  << " up to scale " << scale << std::endl;
135  if (white_noise)
136  std::cout << " Imposing white noise\n";
137  break;
138  case ADAPTIVE_SOFT:
139  std::cout << " Adaptive soft thresholding\n";
140  break;
141  case CENTRAL:
142  std::cout << " Keeping central part " << R << " pixels\n";
143  break;
144  }
145  std::cout << "Output scale: " << output_scale << std::endl;
146 }
int output_scale
Definition: denoise.h:75
String DWT_type
Definition: denoise.h:52
bool white_noise
Definition: denoise.h:95
double SNR0
Definition: denoise.h:87
double threshold
Definition: denoise.h:79
DenoisingType denoising_type
Definition: denoise.h:59
double SNRF
Definition: denoise.h:91

Member Data Documentation

◆ adjust_range

bool WaveletFilter::adjust_range

Adjust range in Bayesian denoising.

Definition at line 99 of file denoise.h.

◆ denoising_type

DenoisingType WaveletFilter::denoising_type

Denoising type.

Valid types are REMOVE_SCALE, SOFT_THRESHOLDING, BAYESIAN, ADAPTIVE_SOFT, CENTRAL.

Definition at line 59 of file denoise.h.

◆ dont_denoise

bool WaveletFilter::dont_denoise

Don't denoise.

This is used in the Bayesian method, where the estimatedS parameters can be averaged.

Definition at line 111 of file denoise.h.

◆ DWT_type

String WaveletFilter::DWT_type

Wavelet type.

Valid types DAUB4, DAUB12, DAUB20

Definition at line 52 of file denoise.h.

◆ estimatedS

Matrix1D< double > WaveletFilter::estimatedS

EstimatedS of the Bayesian method.

Definition at line 119 of file denoise.h.

◆ output_scale

int WaveletFilter::output_scale

Output scale.

All wavelet coefficients up to this output scale will be removed. Thus, the output image is reduced by a factor that is related to this output scale. For instance, if the output scale is 0, then no reduction is done. If the output scale is 1, then the output image is reduced by 1/2, if the output scale is 2, then it is reduced by 1/4, ...

Definition at line 75 of file denoise.h.

◆ R

int WaveletFilter::R

Radius for central

Definition at line 83 of file denoise.h.

◆ scale

int WaveletFilter::scale

Scale to which the denoising is applied.

It is used by remove scale, adaptive soft

Definition at line 65 of file denoise.h.

◆ SNR0

double WaveletFilter::SNR0

Smallest SNR

Definition at line 87 of file denoise.h.

◆ SNRF

double WaveletFilter::SNRF

Largest SNR

Definition at line 91 of file denoise.h.

◆ threshold

double WaveletFilter::threshold

Threshold for soft thresholding.

Definition at line 79 of file denoise.h.

◆ verbose

int WaveletFilter::verbose

Verbosity used by denoiser. By default will be 0, programs using denoiser should set this

Definition at line 104 of file denoise.h.

◆ white_noise

bool WaveletFilter::white_noise

White noise

Definition at line 95 of file denoise.h.


The documentation for this class was generated from the following files: