Xmipp  v3.23.11-Nereus
Public Member Functions | Public Attributes | List of all members

#include <resolution_ssnr.h>

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

Public Member Functions

void defineParams ()
 
void readParams ()
 
void show ()
 
void produceSideInfo ()
 
void run ()
 
void estimateSSNR (int dim, Matrix2D< double > &output)
 
void radialAverage (Matrix2D< double > &output)
 
- Public Member Functions inherited from XmippProgram
const char * getParam (const char *param, int arg=0)
 
const char * getParam (const char *param, const char *subparam, int arg=0)
 
int getIntParam (const char *param, int arg=0)
 
int getIntParam (const char *param, const char *subparam, int arg=0)
 
double getDoubleParam (const char *param, int arg=0)
 
double getDoubleParam (const char *param, const char *subparam, int arg=0)
 
float getFloatParam (const char *param, int arg=0)
 
float getFloatParam (const char *param, const char *subparam, int arg=0)
 
void getListParam (const char *param, StringVector &list)
 
int getCountParam (const char *param)
 
bool checkParam (const char *param)
 
bool existsParam (const char *param)
 
void addParamsLine (const String &line)
 
void addParamsLine (const char *line)
 
ParamDefgetParamDef (const char *param) const
 
virtual void quit (int exit_code=0) const
 
virtual int tryRun ()
 
void initProgress (size_t total, size_t stepBin=60)
 
void setProgress (size_t value=0)
 
void endProgress ()
 
void processDefaultComment (const char *param, const char *left)
 
void setDefaultComment (const char *param, const char *comment)
 
virtual void initComments ()
 
void setProgramName (const char *name)
 
void addUsageLine (const char *line, bool verbatim=false)
 
void clearUsage ()
 
void addExampleLine (const char *example, bool verbatim=true)
 
void addSeeAlsoLine (const char *seeAlso)
 
void addKeywords (const char *keywords)
 
const char * name () const
 
virtual void usage (int verb=0) const
 
virtual void usage (const String &param, int verb=2)
 
int version () const
 
virtual void show () const
 
virtual void read (int argc, const char **argv, bool reportErrors=true)
 
virtual void read (int argc, char **argv, bool reportErrors=true)
 
void read (const String &argumentsLine)
 
 XmippProgram ()
 
 XmippProgram (int argc, const char **argv)
 
virtual ~XmippProgram ()
 

Public Attributes

FileName fn_S
 Signal reconstructed volume. More...
 
FileName fn_N
 Noise reconstructed volume. More...
 
FileName fn_SNsel
 Selfile with all the experimental and noise images. More...
 
FileName fn_S_sel
 
FileName fn_N_sel
 
FileName fn_VSSNR
 Filename of the Volumetric SSNR, used only for radial averaging. More...
 
bool fourierProjections
 Fourier projections. More...
 
double ring_width
 Ringwidth. More...
 
double Tm
 Sampling rate. More...
 
FileName fn_out
 
FileName fn_out_images
 
String sym
 
bool generate_VSSNR
 
bool radial_avg
 
double min_power
 
int Nthreads
 
Image< double > S
 
Image< double > N
 
MetaDataVec SF_SN
 
MetaDataVec SF_S
 
MetaDataVec SF_N
 
Image< double > VSSNR
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Additional Inherited Members

- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 
- Protected Attributes inherited from XmippProgram
int errorCode
 
ProgramDefprogDef
 Program definition and arguments parser. More...
 
std::map< String, CommentListdefaultComments
 
int argc
 Original command line arguments. More...
 
const char ** argv
 

Detailed Description

SSNR parameters.

Definition at line 40 of file resolution_ssnr.h.

Member Function Documentation

◆ defineParams()

void ProgSSNR::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 35 of file resolution_ssnr.cpp.

36 {
37  addUsageLine("Evaluate the reconstruction quality using SSNR or its volumetric distribution VSSNR.");
38  addUsageLine("+You must produce a reconstruction with gaussian white noise with exactly the same angles and");
39  addUsageLine("+reconstruction parameters as the signal reconstruction. Our ART program can produce this noisy");
40  addUsageLine("+reconstruction. If you don't use ART as reconstruction algorithm, you will have to produce the");
41  addUsageLine("+noisy reconstruction by yourself (see our demo in order to learn how to do this). Finally, the");
42  addUsageLine("+VSSNR can be visualized using any volume viewer.");
43  addUsageLine("+++ %BR% %BR%");
44  addUsageLine("+++* Do not use any mask during the reconstruction since the resolution estimate is biased");
45  addUsageLine("+++* Before applying this measure make sure that the noise images and the background in the experimental" \
46  " images have zero average. It is also assumed that the projection of the reconstructed volumes matches the" \
47  " experimental or the noisy projections (i.e., check that both projections are within the same range");
48  addUsageLine("+++* The VSSNR is stored in the file as 10*log10(1+VSSNR). Thus, if you want a threshold of VSSNR=1, the" \
49  " threshold in the visualizer must be set to =10*log10(1+1)=3=");
50  addUsageLine("+++* If the reconstruction algorithm linearly scales the reconstructed volume so that the reprojected" \
51  " images do not match the gray values of the experimental images, use adjust_volume to correct for the linear" \
52  " transformation before computing the SSNR images");
53 
54  addSeeAlsoLine("resolution_fsc");
55 
56  addParamsLine("== SSNR or VSSNR Estimation ==");
57  addParamsLine(" [--signal <signal_file>] : Signal volume");
58  addParamsLine(" alias -S;");
59  addParamsLine(" requires --noise;");
60  addParamsLine(" [--noise <noise_file>] : Noise volume");
61  addParamsLine(" alias -N;");
62  addParamsLine(" [--sel_signal <signal_mdfile>] : Metadata file with the images used for the signal reconstruction");
63  addParamsLine(" alias -selS;");
64  addParamsLine(" [--sel_noise <noise_mdfile>] : Metadata file with the images used for the noise reconstruction");
65  addParamsLine(" alias -selN;");
66  addParamsLine(" [-o <SSNR_file=\"\">] : Output file with the SSNR estimation");
67  addParamsLine(" :+++If the output filename is not given, then the input filename is taken");
68  addParamsLine(" :+++from the -S parameter by inserting _SSNR before the extension.");
69  addParamsLine(" [--fourierProjections] : perform projections in Fourier space");
70  addParamsLine(" [--ring <w=4>] : Ring width for the SSNR averaging computation (Measured in Fourier pixels)");
71  addParamsLine(" [--sampling_rate <Ts=1>] : Pixel size (Angstrom)");
72  addParamsLine(" alias -s;");
73  addParamsLine(" [--min_power <th=1e-10>] : Minimum power in Fourier space. If at any moment, the SSNR must divide by something");
74  addParamsLine(" : smaller than this value, then the SSNR at that frequency is assumed to be 0. High ");
75  addParamsLine(" : values of this threshold result on speckled images. If this is the case, lower ");
76  addParamsLine(" : this threshold (it must always be positive) ");
77  addParamsLine(" [--gen_VSSNR] : (Allowed global options: --ring, --sampling_rate, --min_power)");
78  addParamsLine(" :+++ %BR%");
79  addParamsLine(" : Generate the individual estimations of the SSNR for each particle and build an ");
80  addParamsLine(" : interpolation volume (VSSNR) that is compatible with the individual SSNRs.");
81  addParamsLine(" :+ In fact, the VSSNR is stored as 10*log10(1+SSNR). Thus, after interpolating the threshold");
82  addParamsLine(" :+ at SSNR = 1 must be shown as the threshold of the output interpolated volume at 3.01 ");
83  addParamsLine(" :+ (10*log10(1+1)). The threshold at SSNR = 4 must be shown as the threshold of the output");
84  addParamsLine(" :+ interpolated volume at 6.99 (10*log10(1+4)). The 1D SSNR is also generated as a side-product");
85  addParamsLine(" requires --signal,--noise,--VSSNR;");
86  addParamsLine(" [--sym <sym=c1>] : Symmetry for constructing the VSSNR");
87  addParamsLine(" [--thr <n=1>] : Number of threads to construct the VSSNR");
88  addParamsLine(" [--VSSNR <fn_vol_file>] : Volume with the Volumetric SSNR");
89  addParamsLine(" [--oroot <root=\"\">] : Root name for individual SSNR estimations");
90  addParamsLine("== Estimation by radial averaging of the VSSNR ==");
91  addParamsLine(" [--radial_avg] : Do radial averaging estimation");
92  addParamsLine(" : (Allowed global options: --ring, --sampling_rate, --min_power, -o)");
93  addParamsLine(" requires --VSSNR;");
94 
95  addExampleLine("SSNR Resolution of a reconstructed volume:", false);
96  addExampleLine("xmipp_resolution_ssnr -S recFourierSignal.vol -N recFourierNoise.vol -selS projections.xmd -selN noiseProjections.xmd");
97  addExampleLine("VSSNR Resolution of a reconstructed volume:", false);
98  addExampleLine("xmipp_resolution_ssnr -S recFourierSignal.vol -N recFourierNoise.vol -selS projections.xmd -selN noiseProjections.xmd --gen_VSSNR --VSSNR volumeout.vol");
99 }
void addSeeAlsoLine(const char *seeAlso)
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ estimateSSNR()

void ProgSSNR::estimateSSNR ( int  dim,
Matrix2D< double > &  output 
)

Estimate SSNR 2D. Generate images with the particular SSNR. The output filename is used as a rootname

Definition at line 207 of file resolution_ssnr.cpp.

208 {
209  // These vectors are for 1D
210  Matrix1D<double> S_S21D((int)(XSIZE(S()) / 2 - ring_width)),
211  S_N21D((int)(XSIZE(S()) / 2 - ring_width)),
212  K1D((int)(XSIZE(S()) / 2 - ring_width)),
213  S_SSNR1D;
214  Matrix1D<double> N_S21D((int)(XSIZE(S()) / 2 - ring_width)),
215  N_N21D((int)(XSIZE(S()) / 2 - ring_width)),
216  N_SSNR1D;
217 
218  // Selfile of the 2D images
219  MetaDataVec SF_individual;
220 
221  std::cerr << "Computing the SSNR ...\n";
223  int imgno = 1;
224  Image<double> Is, In;
225  Projection Iths, Ithn;
226  MultidimArray< std::complex<double> > FFT_Is, FFT_Iths, FFT_In, FFT_Ithn;
227  MultidimArray<double> S2s, N2s, S2n, N2n;
228  FileName fn_img;
229  FourierTransformer FT(FFTW_BACKWARD);
230  FourierProjector *Sprojector=nullptr;
231  FourierProjector *Nprojector=nullptr;
232  if (fourierProjections)
233  {
234  Sprojector=new FourierProjector(S(),2,0.5,xmipp_transformation::LINEAR);
235  Nprojector=new FourierProjector(N(),2,0.5,xmipp_transformation::LINEAR);
236  }
237 
238  auto iterIdS = SF_S.ids().begin();
239  auto iterIdN = SF_N.ids().begin();
240  const auto totalSize = SF_S.ids().end();
241  for (; iterIdS != totalSize; ++iterIdS, ++iterIdN)
242  {
243  double rot, tilt, psi;
244  SF_S.getValue(MDL_ANGLE_ROT,rot, *iterIdS);
245  SF_S.getValue(MDL_ANGLE_TILT,tilt, *iterIdS);
246  SF_S.getValue(MDL_ANGLE_PSI,psi, *iterIdS);
247  SF_S.getValue(MDL_IMAGE,fn_img, *iterIdS);
248  Is.read(fn_img);
249  Is().setXmippOrigin();
250  SF_N.getValue(MDL_IMAGE,fn_img, *iterIdN);
251  In.read(fn_img);
252  In().setXmippOrigin();
253 
254  if (fourierProjections)
255  {
256  projectVolume(*Sprojector, Iths, YSIZE(Is()), XSIZE(Is()), rot, tilt, psi);
257  projectVolume(*Nprojector, Ithn, YSIZE(Is()), XSIZE(Is()), rot, tilt, psi);
258  }
259  else
260  {
261  projectVolume(S(), Iths, YSIZE(Is()), XSIZE(Is()), rot, tilt, psi);
262  projectVolume(N(), Ithn, YSIZE(Is()), XSIZE(Is()), rot, tilt, psi);
263  }
264 
265 #ifdef DEBUG
266 
267  Image<double> save;
268  save() = Is();
269  save.write("PPPread_signal.xmp");
270  save() = In();
271  save.write("PPPread_noise.xmp");
272  save() = Iths();
273  save.write("PPPtheo_signal.xmp");
274  save() = Ithn();
275  save.write("PPPtheo_noise.xmp");
276 #endif
277 
278  Is() -= Iths();
279  In() -= Ithn(); // According to the article: should we not subtract here (simply remove this line)
280  // "...except that there is no subtraction in the denominator because the
281  // underlying signal is zero by definition."
282 
283  if (dim == 2)
284  {
285  FT.completeFourierTransform(Is(), FFT_Is);
286  FT.completeFourierTransform(Iths(), FFT_Iths);
287  FT.completeFourierTransform(In(), FFT_In);
288  FT.completeFourierTransform(Ithn(), FFT_Ithn);
289  }
290  else
291  {
292  FT.FourierTransform(Is(), FFT_Is);
293  FT.FourierTransform(Iths(), FFT_Iths);
294  FT.FourierTransform(In(), FFT_In);
295  FT.FourierTransform(Ithn(), FFT_Ithn);
296  }
297 
298 #ifdef DEBUG
299 
301  savec() = FFT_Is;
302  savec.write("PPPFFTread_signal.xmp");
303  savec() = FFT_In;
304  savec.write("PPPFFTread_noise.xmp");
305  savec() = FFT_Iths;
306  savec.write("PPPFFTtheo_signal.xmp");
307  savec() = FFT_Ithn;
308  savec.write("PPPFFTtheo_noise.xmp");
309 #endif
310 
311  // Compute the amplitudes
312  S2s.resizeNoCopy(FFT_Iths);
313  N2s.resizeNoCopy(FFT_Iths);
314  S2n.resizeNoCopy(FFT_Iths);
315  N2n.resizeNoCopy(FFT_Iths);
317  {
318  DIRECT_MULTIDIM_ELEM(S2s, n) = abs(DIRECT_MULTIDIM_ELEM(FFT_Iths, n));
320  DIRECT_MULTIDIM_ELEM(N2s, n) = abs(DIRECT_MULTIDIM_ELEM(FFT_Is, n));
322  DIRECT_MULTIDIM_ELEM(S2n, n) = abs(DIRECT_MULTIDIM_ELEM(FFT_Ithn, n));
324  DIRECT_MULTIDIM_ELEM(N2n, n) = abs(DIRECT_MULTIDIM_ELEM(FFT_In, n));
326  }
327 
328 #ifdef DEBUG
329 
330  save() = S2s();
331  save.write("PPPS2s.xmp");
332  save() = N2s();
333  save.write("PPPN2s.xmp");
334  save() = S2n();
335  save.write("PPPS2n.xmp");
336  save() = N2n();
337  save.write("PPPN2n.xmp");
338 #endif
339 
340  if (dim == 2)
341  {
342  // Compute the SSNR image
343  Image<double> SSNR2D;
344  SSNR2D().initZeros(S2s);
345  const MultidimArray<double> & SSNR2Dmatrix=SSNR2D();
347  {
348  double ISSNR = 0, alpha = 0, SSNR = 0;
349  double aux = DIRECT_MULTIDIM_ELEM(N2s,n);
350  if (aux > min_power)
351  ISSNR = DIRECT_MULTIDIM_ELEM(S2s,n) / aux;
352  aux = DIRECT_MULTIDIM_ELEM(N2n,n);
353  if (aux > min_power)
354  alpha = DIRECT_MULTIDIM_ELEM(S2n,n) / aux;
355  if (alpha > min_power)
356  {
357  aux = ISSNR / alpha - 1.0;
358  SSNR = XMIPP_MAX(aux, 0.0);
359  }
360  if (SSNR > min_power)
361  DIRECT_MULTIDIM_ELEM(SSNR2Dmatrix,n) = 10.0 * log10(SSNR + 1.0);
362  }
363  CenterFFT(SSNR2D(), true);
364 #ifdef DEBUG
365 
366  save() = SSNR2Dmatrix;
367  save.write("PPPSSNR2D.xmp");
368 #endif
369 
370  // Save image
371  FileName fn_img_out;
372  fn_img_out.compose(imgno, fn_out_images, "stk");
373  SSNR2D.write(fn_img_out);
374  size_t objId = SF_individual.addObject();
375  SF_individual.setValue(MDL_IMAGE,fn_img_out,objId);
376  SF_individual.setValue(MDL_ANGLE_ROT,rot,objId);
377  SF_individual.setValue(MDL_ANGLE_TILT,tilt,objId);
378  SF_individual.setValue(MDL_ANGLE_PSI,psi,objId);
379  }
380 
381  // Average over rings
382  Matrix1D<int> idx(2);
383  Matrix1D<double> freq(2);
384 
385  STARTINGX(S2s) = STARTINGY(S2s) = 0;
386  STARTINGX(N2s) = STARTINGY(N2s) = 0;
387  STARTINGX(S2n) = STARTINGY(S2n) = 0;
388  STARTINGX(N2n) = STARTINGY(N2n) = 0;
389  double Xdim=XSIZE(S());
390  double maxwidx=VEC_XSIZE(S_S21D);
392  {
393  XX(idx) = j;
394  YY(idx) = i;
395  FFT_idx2digfreq(FFT_Is, idx, freq);
396  if (XX(freq) < 0)
397  continue;
398 
399  // Look for the index corresponding to this frequency
400  double w = freq.module();
401  double widx = w * Xdim;
402  if (widx >= maxwidx)
403  continue;
404  int l0 = CEIL(widx - ring_width);
405  l0=XMIPP_MAX(0, l0);
406  int lF = FLOOR(widx);
407 
408  double S_signal = A2D_ELEM(S2s, i, j);
409  double S_noise = A2D_ELEM(N2s, i, j);
410  double N_signal = A2D_ELEM(S2n, i, j);
411  double N_noise = A2D_ELEM(N2n, i, j);
412  for (int l = l0; l <= lF; l++)
413  {
414  VEC_ELEM(S_S21D,l) += S_signal;
415  VEC_ELEM(S_N21D,l) += S_noise;
416  VEC_ELEM(N_S21D,l) += N_signal;
417  VEC_ELEM(N_N21D,l) += N_noise;
418  VEC_ELEM(K1D,l)++;
419  }
420  }
421 
422  // Finished with this image
423  if (++imgno % 50 == 0)
424  progress_bar(imgno);
425  }
427  if (fourierProjections)
428  {
429  delete Sprojector;
430  delete Nprojector;
431  Sprojector=nullptr;
432  Nprojector=nullptr;
433  }
434 
435  // Compute the SSNRsym
436  S_SSNR1D = S_S21D / S_N21D;
437  S_S21D *= 1.0/K1D;
438  S_N21D *= 1.0/K1D;
439  N_SSNR1D = N_S21D / N_N21D;
440  N_S21D *= 1.0/K1D;
441  N_N21D *= 1.0/K1D;
442 
443  output.resize(VEC_XSIZE(S_SSNR1D), 9);
444  int imax = 0;
446  {
447  double w;
448  FFT_IDX2DIGFREQ(i, XSIZE(S()), w);
449  if (w < 0)
450  {
451  imax = i;
452  break;
453  }
454  output(i, 0) = i;
455  output(i, 1) = w * 1 / Tm;
456  double SSNR = S_SSNR1D(i) / N_SSNR1D(i);
457  if (SSNR > 1)
458  output(i, 2) = 10 * log10(SSNR - 1); // Corrected SSNR
459  else
460  output(i, 2) = -1000; // In fact it should be -inf
461  output(i, 3) = S_SSNR1D(i);
462  output(i, 4) = 10 * log10(S_S21D(i) / imgno);
463  output(i, 5) = 10 * log10(S_N21D(i) / imgno);
464  output(i, 6) = N_SSNR1D(i);
465  output(i, 7) = 10 * log10(N_S21D(i) / imgno);
466  output(i, 8) = 10 * log10(N_N21D(i) / imgno);
467  imax++;
468  }
469  output.resize(imax, 9);
470 
471  // Produce VSSNR ........................................................
472  if (dim == 2)
473  {
474  std::cerr << "Interpolating the VSSNR ...\n";
475  SF_individual.write(fn_out_images + ".xmd");
476 
477  ProgReconsART artRecons;
478  artRecons.read(formatString("-i %s.xmd -o %s -l 0.1 -R %i --ray_length 1 -n 5 --sym %s --thr %d",fn_out_images.c_str(),
479  fn_VSSNR.c_str(), ROUND(XSIZE(S()) / 3), sym.c_str(),Nthreads));
480  artRecons.run();
481 
482  remove(fn_out_images.addExtension("xmd").c_str());
483  remove(fn_out_images.addExtension("stk").c_str());
484  }
485 }
void init_progress_bar(long total)
MetaDataVec SF_N
Rotation angle of an image (double,degrees)
#define YSIZE(v)
#define A2D_ELEM(v, i, j)
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
String sym
virtual void read(int argc, const char **argv, bool reportErrors=true)
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
void resizeNoCopy(const MultidimArray< T1 > &v)
Tilting angle of an image (double,degrees)
FileName addExtension(const String &ext) const
Image< double > N
void write(const FileName &name="", size_t select_img=ALL_IMAGES, bool isStack=false, int mode=WRITE_OVERWRITE, CastWriteMode castMode=CW_CAST, int _swapWrite=0)
void compose(const String &str, const size_t no, const String &ext="")
Special label to be used when gathering MDs in MpiMetadataPrograms.
doublereal * w
void abs(Image< double > &op)
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
virtual IdIteratorProxy< false > ids()
void FFT_idx2digfreq(T &v, const Matrix1D< int > &idx, Matrix1D< double > &freq)
Definition: xmipp_fft.h:80
#define STARTINGX(v)
size_t size() const override
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
double Tm
Sampling rate.
#define STARTINGY(v)
void CenterFFT(MultidimArray< T > &v, bool forward)
Definition: xmipp_fft.h:291
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define XX(v)
Definition: matrix1d.h:85
bool setValue(const MDObject &mdValueIn, size_t id)
#define CEIL(x)
Definition: xmipp_macros.h:225
size_t addObject() override
double ring_width
Ringwidth.
#define XSIZE(v)
void progress_bar(long rlen)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
#define ROUND(x)
Definition: xmipp_macros.h:210
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
void log10(Image< double > &op)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define j
double min_power
#define YY(v)
Definition: matrix1d.h:93
bool getValue(MDObject &mdValueOut, size_t id) const override
MetaDataVec SF_S
double psi(const double x)
String formatString(const char *format,...)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
FileName fn_out_images
FileName fn_VSSNR
Filename of the Volumetric SSNR, used only for radial averaging.
bool fourierProjections
Fourier projections.
Image< double > S
int * n
Name of an image (std::string)
void resize(size_t Ydim, size_t Xdim, bool noCopy=false)
Definition: matrix2d.cpp:1022

◆ produceSideInfo()

void ProgSSNR::produceSideInfo ( )

Definition at line 146 of file resolution_ssnr.cpp.

147 {
148  if (!radial_avg)
149  {
150  S.read(fn_S);
151  S().setXmippOrigin();
152  N.read(fn_N);
153  N().setXmippOrigin();
154  if (!S().sameShape(N()))
156  "SSNR: Signal and Noise volumes are not of the same size");
157 
158  SF_S.read(fn_S_sel);
159  SF_N.read(fn_N_sel);
160 
161  if (fn_out_images == "")
162  fn_out_images = "individualSSNR";
163  }
164  else
165  {
167  VSSNR().setXmippOrigin();
168  }
169 }
FileName fn_N
Noise reconstructed volume.
MetaDataVec SF_N
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=nullptr, bool decomposeStack=true) override
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
Image< double > N
Incorrect MultidimArray size.
Definition: xmipp_error.h:174
FileName fn_N_sel
Image< double > VSSNR
FileName fn_S_sel
MetaDataVec SF_S
FileName fn_S
Signal reconstructed volume.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
FileName fn_out_images
FileName fn_VSSNR
Filename of the Volumetric SSNR, used only for radial averaging.
Image< double > S
bool radial_avg

◆ radialAverage()

void ProgSSNR::radialAverage ( Matrix2D< double > &  output)

Radial average of a Volumetric SSNR. The Volumetric SSNR is stored as 10*log10(VSSNR+1). To perform a radial average that is consistent with the one produced by the 1D estimation the +1 must be properly eliminated.

The columns of output are the following: Column 0: sample number in Fourier Space, Column 1: corresponding frequency in continuous freq (1/A), Column 2: corrected radial_avg

Definition at line 488 of file resolution_ssnr.cpp.

489 {
490  // Compute the radial average ...........................................
491  Matrix1D<double> VSSNR_avg((int)(XSIZE(VSSNR()) / 2 - ring_width));
492  Matrix1D<double> K1D(VSSNR_avg);
493  Matrix1D<int> idx(3);
494  Matrix1D<double> freq(3);
496  {
497  VECTOR_R3(idx, j, i, k);
498  FFT_idx2digfreq(VSSNR(), idx, freq);
499  if (XX(freq) < 0)
500  continue;
501 
502  // Look for the index corresponding to this frequency
503  double w = freq.module();
504  double widx = w * XSIZE(VSSNR());
505  if (widx >= VEC_XSIZE(VSSNR_avg))
506  continue;
507  int l0 = XMIPP_MAX(0, CEIL(widx - ring_width));
508  int lF = FLOOR(widx);
509 
510  double VSSNRkij = pow(10, VSSNR(k, i, j) / 10) - 1;
511 
512  for (int l = l0; l <= lF; l++)
513  {
514  VSSNR_avg(l) += VSSNRkij;
515  K1D(l)++;
516  }
517  }
518 
520  if (K1D(i) != 0)
521  VSSNR_avg(i) /= K1D(i);
522 
523  // Produce output .......................................................
524  output.resize(VEC_XSIZE(VSSNR_avg), 3);
525  for (size_t i = 0; i < VEC_XSIZE(VSSNR_avg); i++)
526  {
527  double w;
528  FFT_IDX2DIGFREQ(i, XSIZE(VSSNR()), w);
529  output(i, 0) = i;
530  output(i, 1) = w * 1 / Tm;
531  double SSNR = VSSNR_avg(i);
532  if (SSNR > 1)
533  output(i, 2) = 10 * log10(SSNR - 1); // Corrected SSNR
534  else
535  output(i, 2) = -1000; // In fact it should be -inf
536  }
537 }
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
#define VEC_XSIZE(m)
Definition: matrix1d.h:77
doublereal * w
void FFT_idx2digfreq(T &v, const Matrix1D< int > &idx, Matrix1D< double > &freq)
Definition: xmipp_fft.h:80
#define i
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
double Tm
Sampling rate.
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define XX(v)
Definition: matrix1d.h:85
#define CEIL(x)
Definition: xmipp_macros.h:225
Image< double > VSSNR
double ring_width
Ringwidth.
#define XSIZE(v)
void log10(Image< double > &op)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define j
#define VECTOR_R3(v, x, y, z)
Definition: matrix1d.h:124
void resize(size_t Ydim, size_t Xdim, bool noCopy=false)
Definition: matrix2d.cpp:1022

◆ readParams()

void ProgSSNR::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 XmippProgram.

Definition at line 102 of file resolution_ssnr.cpp.

103 {
104  radial_avg = checkParam("--radial_avg");
105  fourierProjections = checkParam("--fourierProjections");
106  if (!radial_avg)
107  {
108  fn_S = getParam("-S");
109  fn_N = getParam("-N");
110  fn_S_sel = getParam("--sel_signal");
111  fn_N_sel = getParam("--sel_noise");
112  generate_VSSNR = checkParam("--gen_VSSNR");
113  if (generate_VSSNR)
114  {
115  fn_VSSNR = getParam("--VSSNR");
116  fn_out_images = getParam("--oroot");
117  sym=getParam("--sym");
118  Nthreads=getIntParam("--thr");
119  }
120  }
121  else
122  fn_VSSNR = getParam("--VSSNR");
123 
124  ring_width = getDoubleParam("--ring");
125  Tm = getDoubleParam("--sampling_rate");
126  min_power = getDoubleParam("--min_power");
127  fn_out = getParam("-o");
128 }
FileName fn_N
Noise reconstructed volume.
FileName fn_out
String sym
double getDoubleParam(const char *param, int arg=0)
bool generate_VSSNR
FileName fn_N_sel
double Tm
Sampling rate.
const char * getParam(const char *param, int arg=0)
double ring_width
Ringwidth.
double min_power
FileName fn_S_sel
FileName fn_S
Signal reconstructed volume.
bool checkParam(const char *param)
FileName fn_out_images
FileName fn_VSSNR
Filename of the Volumetric SSNR, used only for radial averaging.
int getIntParam(const char *param, int arg=0)
bool fourierProjections
Fourier projections.
bool radial_avg

◆ run()

void ProgSSNR::run ( )
virtual

This function will be start running the program. it also should be implemented by derived classes.

Reimplemented from XmippProgram.

Definition at line 172 of file resolution_ssnr.cpp.

173 {
174  show();
175  produceSideInfo();
176 
177  Matrix2D<double> output;
178  if (!radial_avg)
179  {
180  if (!generate_VSSNR)
181  estimateSSNR(1, output);
182  else
183  estimateSSNR(2, output);
184  if (fn_out == "")
186  }
187  else
188  {
189  radialAverage(output);
190  if (fn_out == "")
192  }
193 #ifdef DEBUG
194  output.write(fn_out);
195 #endif
196  MetaDataVec MD;
197  for (size_t i=1; i<MAT_YSIZE(output); ++i)
198  {
199  size_t id=MD.addObject();
200  MD.setValue(MDL_RESOLUTION_FREQ,output(i,1),id);
201  MD.setValue(MDL_RESOLUTION_SSNR,output(i,2),id);
202  MD.setValue(MDL_RESOLUTION_FREQREAL,1.0/output(i,1),id);
203  }
204  MD.write(fn_out);
205 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
FileName fn_out
Fourier shell correlation (double)
void radialAverage(Matrix2D< double > &output)
FileName removeLastExtension() const
bool generate_VSSNR
FileName addExtension(const String &ext) const
FileName insertBeforeExtension(const String &str) const
void produceSideInfo()
void write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
#define i
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
Frequency in A (double)
Frequency in 1/A (double)
void estimateSSNR(int dim, Matrix2D< double > &output)
FileName fn_S
Signal reconstructed volume.
void write(const FileName &fn) const
Definition: matrix2d.cpp:113
FileName fn_VSSNR
Filename of the Volumetric SSNR, used only for radial averaging.
bool radial_avg

◆ show()

void ProgSSNR::show ( )

Definition at line 130 of file resolution_ssnr.cpp.

131 {
132  std::cout
133  << "Signal Volume: " << fn_S << std::endl
134  << "Noise Volume: " << fn_N << std::endl
135  << "Signal selfile: " << fn_S_sel << std::endl
136  << "Noise selfile: " << fn_N_sel << std::endl
137  << "Volumetric SSNR: " << fn_VSSNR << std::endl
138  << "Output images: " << fn_out << std::endl
139  << "Ring width: " << ring_width << std::endl
140  << "Sampling rate: " << Tm << std::endl
141  << "Generate VSSNR: " << generate_VSSNR << std::endl
142  << "Radial average: " << radial_avg << std::endl
143  << "Fourier projections: " << fourierProjections << std::endl;
144 }
FileName fn_N
Noise reconstructed volume.
FileName fn_out
bool generate_VSSNR
FileName fn_N_sel
double Tm
Sampling rate.
double ring_width
Ringwidth.
FileName fn_S_sel
FileName fn_S
Signal reconstructed volume.
FileName fn_VSSNR
Filename of the Volumetric SSNR, used only for radial averaging.
bool fourierProjections
Fourier projections.
bool radial_avg

Member Data Documentation

◆ fn_N

FileName ProgSSNR::fn_N

Noise reconstructed volume.

Definition at line 46 of file resolution_ssnr.h.

◆ fn_N_sel

FileName ProgSSNR::fn_N_sel

Definition at line 49 of file resolution_ssnr.h.

◆ fn_out

FileName ProgSSNR::fn_out

Output filename. If empty, SSNR is inserted before the extension in fn_S

Definition at line 60 of file resolution_ssnr.h.

◆ fn_out_images

FileName ProgSSNR::fn_out_images

Output rootname for the individual estimations. If empty, SSNR is inserted before the extension in fn_S

Definition at line 63 of file resolution_ssnr.h.

◆ fn_S

FileName ProgSSNR::fn_S

Signal reconstructed volume.

Definition at line 44 of file resolution_ssnr.h.

◆ fn_S_sel

FileName ProgSSNR::fn_S_sel

Definition at line 49 of file resolution_ssnr.h.

◆ fn_SNsel

FileName ProgSSNR::fn_SNsel

Selfile with all the experimental and noise images.

Definition at line 48 of file resolution_ssnr.h.

◆ fn_VSSNR

FileName ProgSSNR::fn_VSSNR

Filename of the Volumetric SSNR, used only for radial averaging.

Definition at line 51 of file resolution_ssnr.h.

◆ fourierProjections

bool ProgSSNR::fourierProjections

Fourier projections.

Definition at line 53 of file resolution_ssnr.h.

◆ generate_VSSNR

bool ProgSSNR::generate_VSSNR

Generate VSSNR.

Definition at line 67 of file resolution_ssnr.h.

◆ min_power

double ProgSSNR::min_power

Min_power: Threshold for not dividing

Definition at line 71 of file resolution_ssnr.h.

◆ N

Image<double> ProgSSNR::N

Definition at line 79 of file resolution_ssnr.h.

◆ Nthreads

int ProgSSNR::Nthreads

Number of threads for ART

Definition at line 73 of file resolution_ssnr.h.

◆ radial_avg

bool ProgSSNR::radial_avg

Generate radial average.

Definition at line 69 of file resolution_ssnr.h.

◆ ring_width

double ProgSSNR::ring_width

Ringwidth.

Definition at line 55 of file resolution_ssnr.h.

◆ S

Image<double> ProgSSNR::S

Definition at line 77 of file resolution_ssnr.h.

◆ SF_N

MetaDataVec ProgSSNR::SF_N

Definition at line 81 of file resolution_ssnr.h.

◆ SF_S

MetaDataVec ProgSSNR::SF_S

Definition at line 81 of file resolution_ssnr.h.

◆ SF_SN

MetaDataVec ProgSSNR::SF_SN

Definition at line 81 of file resolution_ssnr.h.

◆ sym

String ProgSSNR::sym

Symmetry

Definition at line 65 of file resolution_ssnr.h.

◆ Tm

double ProgSSNR::Tm

Sampling rate.

Definition at line 57 of file resolution_ssnr.h.

◆ VSSNR

Image<double> ProgSSNR::VSSNR

Definition at line 83 of file resolution_ssnr.h.


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