Xmipp  v3.23.11-Nereus
Classes | Functions | Variables
Estimate the SSNR
Collaboration diagram for Estimate the SSNR:

Classes

class  ProgImageSSNR
 

Functions

void ProgImageSSNR::defineParams ()
 
void ProgImageSSNR::readParams ()
 
void ProgImageSSNR::preProcess ()
 
void ProgImageSSNR::processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
void ProgImageSSNR::postProcess ()
 

Variables

double ProgImageSSNR::R
 
double ProgImageSSNR::Rwidth
 
double ProgImageSSNR::fmin
 
double ProgImageSSNR::fmax
 
double ProgImageSSNR::sampling
 
double ProgImageSSNR::ssnrcut
 
double ProgImageSSNR::ssnrpercent
 
bool ProgImageSSNR::normalizessnr
 
Image< double > ProgImageSSNR::img
 
Image< double > ProgImageSSNR::imgS
 
Image< double > ProgImageSSNR::imgN
 
MultidimArray< double > ProgImageSSNR::maskS
 
MultidimArray< double > ProgImageSSNR::maskN
 
MultidimArray< double > ProgImageSSNR::spectrumS
 
MultidimArray< double > ProgImageSSNR::spectrumN
 
size_t ProgImageSSNR::imin
 
size_t ProgImageSSNR::imax
 

Detailed Description

Function Documentation

◆ defineParams()

void ProgImageSSNR::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageSSNR >.

Definition at line 32 of file program_image_ssnr.cpp.

33 {
34  produces_a_metadata = true;
36  keep_input_columns = true;
37  remove_disabled = false;
38  addUsageLine("Analyze image SSNR. For doing so, we estimate the SSNR of each particle defining as signal "\
39  "the part of the image within a certain radius, and as noise the part of the image outside.");
41  addParamsLine(" [-R <r=-1>]: Particle radius, by default, half size of the image");
42  addParamsLine(" [--Rwidth <r=3>]: Transition radius the mask is 1 till R-Rwidth, and zero from R+Rwidth");
43  addParamsLine(" [--fmin <f=40>]: Minimum frequency (in Angstroms) to measure");
44  addParamsLine(" [--fmax <f=3>]: Maximum frequency (in Angstroms) to measure");
45  addParamsLine(" [--sampling <Ts=1>]: Sampling rate in Angstroms/pixel");
46  addParamsLine(" [--ssnrcut <ssnr=-1>]: Disable images whose SSNR is below this value");
47  addParamsLine(" [--ssnrpercent <p=-1>]: Disable images whose SSNR is below this percentage");
48  addParamsLine(" [--normalizessnr]: Normalize the SSNR by dividing by the maximum SSNR");
49  addExampleLine("xmipp_image_ssnr -i images.xmd -o imagesOut.xmd ");
50 }
void addExampleLine(const char *example, bool verbatim=true)
bool remove_disabled
Remove disabled images from the input selfile.
bool keep_input_columns
Keep input metadata columns.
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
void addUsageLine(const char *line, bool verbatim=false)
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
void addParamsLine(const String &line)

◆ postProcess()

void ProgImageSSNR::postProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Definition at line 153 of file program_image_ssnr.cpp.

154 {
155  if (ssnrcut>0)
157 
158  if (ssnrpercent>0)
159  {
160  std::vector<double> ssnr;
162  std::sort(ssnr.begin(),ssnr.end());
163  auto idx=(size_t)(ssnrpercent/100.0*ssnr.size());
164  thresholdSSNR(getOutputMd(),ssnr[idx]);
165  }
166 
167  if (normalizessnr)
169  if (fn_out!="")
171  else
173 }
void thresholdSSNR(MetaData &mdOut, double ssnrcut)
void normalizeSSNR(MetaData &mdOut)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
FileName fn_in
Filenames of input and output Metadata.
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
Cumulative SSNR (double)
void getColumnValues(const MDLabel label, std::vector< MDObject > &valuesOut) const override

◆ preProcess()

void ProgImageSSNR::preProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageSSNR >.

Definition at line 65 of file program_image_ssnr.cpp.

66 {
67  size_t Xdim, Ydim, Zdim, Ndim;
68  getImageSize(*getInputMd(), Xdim, Ydim, Zdim, Ndim);
69  maskS.initZeros(Ydim,Xdim);
71 
72  if (R==-1)
73  R=0.5*Xdim-Rwidth;
74  RaisedCosineMask(maskS,R-Rwidth,R+Rwidth);
75  maskN=1-maskS;
76 
77  imin=(size_t)std::max(3.0,0.5*Xdim*(sampling/fmin));
78  imax=(size_t)std::min(Xdim-3.0,0.5*Xdim*(sampling/fmax));
79 }
void min(Image< double > &op1, const Image< double > &op2)
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
MultidimArray< double > maskS
void max(Image< double > &op1, const Image< double > &op2)
MultidimArray< double > maskN
void initZeros(const MultidimArray< T1 > &op)
void RaisedCosineMask(MultidimArray< double > &mask, double r1, double r2, int mode, double x0, double y0, double z0)
Definition: mask.cpp:36

◆ processImage()

void ProgImageSSNR::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
virtual

Implements XmippMetadataProgram.

Definition at line 81 of file program_image_ssnr.cpp.

82 {
83  // Copy Enabled
84  int enabled;
85  rowIn.getValue(MDL_ENABLED,enabled);
86  rowOut.setValue(MDL_ENABLED,enabled);
87 
88  img.read(fnImg);
89  img().setXmippOrigin();
90 
91  imgN()=imgS()=img();
92  imgS()*=maskS;
93  imgN()*=maskN;
94 
97 
98  double SSNR=0;
100  {
101  if (i>=imin && i<=imax)
102  {
103  double S=DIRECT_A1D_ELEM(spectrumS,i);
104  double N=DIRECT_A1D_ELEM(spectrumN,i);
105  if (S>0 && N>0)
106  SSNR+=log10(S)-log10(N);
107  }
108  }
109  SSNR*=10.0/(imax-imin+1); // decibels
110  rowOut.setValue(MDL_CUMULATIVE_SSNR,SSNR);
111 
112  //spectrumS.write("PPPS.txt");
113  //spectrumN.write("PPPN.txt");
114  //std::cout << fnImg << " SSNR=" << SSNR << std::endl;
115  //std::cout << "Press any key\n";
116  // char c; std::cin>> c;
117 }
Image< double > imgS
Image< double > imgN
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY1D(v)
MultidimArray< double > maskS
#define i
Is this image enabled? (int [-1 or 1])
void getSpectrum(MultidimArray< double > &Min, MultidimArray< double > &spectrum, int spectrum_type)
Definition: xmipp_fftw.cpp:752
#define DIRECT_A1D_ELEM(v, i)
T & getValue(MDLabel label)
void log10(Image< double > &op)
Cumulative SSNR (double)
void setValue(MDLabel label, const T &d, bool addLabel=true)
#define POWER_SPECTRUM
Definition: xmipp_fftw.h:668
MultidimArray< double > maskN
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Image< double > img
MultidimArray< double > spectrumN
MultidimArray< double > spectrumS

◆ readParams()

void ProgImageSSNR::readParams ( )
virtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageSSNR >.

Definition at line 52 of file program_image_ssnr.cpp.

53 {
55  R=getDoubleParam("-R");
56  Rwidth=getDoubleParam("--Rwidth");
57  fmin=getDoubleParam("--fmin");
58  fmax=getDoubleParam("--fmax");
59  sampling=getDoubleParam("--sampling");
60  ssnrcut=getDoubleParam("--ssnrcut");
61  ssnrpercent=getDoubleParam("--ssnrpercent");
62  normalizessnr=checkParam("--normalizessnr");
63 }
double getDoubleParam(const char *param, int arg=0)
bool checkParam(const char *param)

Variable Documentation

◆ fmax

double ProgImageSSNR::fmax

Definition at line 37 of file program_image_ssnr.h.

◆ fmin

double ProgImageSSNR::fmin

Definition at line 37 of file program_image_ssnr.h.

◆ imax

size_t ProgImageSSNR::imax

Definition at line 50 of file program_image_ssnr.h.

◆ img

Image<double> ProgImageSSNR::img

Definition at line 48 of file program_image_ssnr.h.

◆ imgN

Image<double> ProgImageSSNR::imgN

Definition at line 48 of file program_image_ssnr.h.

◆ imgS

Image<double> ProgImageSSNR::imgS

Definition at line 48 of file program_image_ssnr.h.

◆ imin

size_t ProgImageSSNR::imin

Definition at line 50 of file program_image_ssnr.h.

◆ maskN

MultidimArray<double> ProgImageSSNR::maskN

Definition at line 49 of file program_image_ssnr.h.

◆ maskS

MultidimArray<double> ProgImageSSNR::maskS

Definition at line 49 of file program_image_ssnr.h.

◆ normalizessnr

bool ProgImageSSNR::normalizessnr

Definition at line 40 of file program_image_ssnr.h.

◆ R

double ProgImageSSNR::R

Definition at line 36 of file program_image_ssnr.h.

◆ Rwidth

double ProgImageSSNR::Rwidth

Definition at line 36 of file program_image_ssnr.h.

◆ sampling

double ProgImageSSNR::sampling

Definition at line 38 of file program_image_ssnr.h.

◆ spectrumN

MultidimArray<double> ProgImageSSNR::spectrumN

Definition at line 49 of file program_image_ssnr.h.

◆ spectrumS

MultidimArray<double> ProgImageSSNR::spectrumS

Definition at line 49 of file program_image_ssnr.h.

◆ ssnrcut

double ProgImageSSNR::ssnrcut

Definition at line 39 of file program_image_ssnr.h.

◆ ssnrpercent

double ProgImageSSNR::ssnrpercent

Definition at line 39 of file program_image_ssnr.h.