Xmipp  v3.23.11-Nereus
image_eliminate_byEnergy.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Carlos Oscar S. Sorzano (coss@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 
27 #include "core/xmipp_image.h"
28 #include "core/xmipp_funcs.h"
29 
30 /* Read parameters --------------------------------------------------------- */
32 {
34  confidence=getDoubleParam("--confidence");
35  sigma20=getDoubleParam("--sigma2");
36  minSigma2=getDoubleParam("--minSigma2");
37 }
38 
39 /* Usage ------------------------------------------------------------------- */
41 {
42  addUsageLine("Eliminate images whose variance is extremely large");
44  produces_an_output=true;
47  addParamsLine("[--confidence <conf=0.99>] : Remove an image if its variance is outside this confidence beyond sigma^2_0");
48  addParamsLine("[--sigma2 <sigma20=1>] : Reference variance");
49  addParamsLine("[--minSigma2 <sigma2=0.01>] : Minimum variance");
50 }
51 
52 /* Show ------------------------------------------------------------------- */
54 {
55  if (verbose==0)
56  return;
58  std::cout
59  << "Confidence: " << confidence << std::endl
60  << "Sigma2: " << sigma20 << std::endl
61  << "MinSigma2: " << minSigma2 << std::endl;
62 }
63 
64 /* Process image ------------------------------------------------------------- */
65 void ProgEliminateByEnergy::processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
66 {
67  rowOut = rowIn;
68  Image<double> I;
69  I.read(fnImg);
70  double avg, stddev;
71  I().computeAvgStdev(avg,stddev);
72  double sigma2=stddev*stddev;
73 
74  double z=(sigma2/sigma20-1);
75  double zalpha=fabs(icdf_gauss(confidence));
76  if (z>zalpha || sigma2<minSigma2 || !std::isfinite(stddev) || fabs(avg)>sigma20/9.0)
77  rowOut.setValue(MDL_ENABLED,-1);
78  else
79  rowOut.setValue(MDL_ENABLED,1);
80 }
81 
85 }
double getDoubleParam(const char *param, int arg=0)
double icdf_gauss(double p)
Is this image enabled? (int [-1 or 1])
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
Process image or volume.
bool produces_an_output
Indicate that a unique final output is produced.
double z
int verbose
Verbosity level.
void setValue(MDLabel label, const T &d, bool addLabel=true)
void show() const override
virtual void removeDisabled()
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
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)
void finishProcessing()
Finish processing.
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
void addParamsLine(const String &line)