Xmipp  v3.23.11-Nereus
Protected Member Functions | Protected Attributes | List of all members
ProgStatistics Class Reference
Inheritance diagram for ProgStatistics:
Inheritance graph
[legend]
Collaboration diagram for ProgStatistics:
Collaboration graph
[legend]

Protected Member Functions

void defineParams ()
 
void readParams ()
 
void show ()
 
void preProcess ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
void postProcess ()
 
- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual bool getImageToProcess (size_t &objId, size_t &objIndex)
 
void show () const override
 
virtual void startProcessing ()
 
virtual void finishProcessing ()
 
virtual void writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 

Protected Attributes

MetaDataVec DF_stats
 
ImageGeneric image
 
MultidimArray< double > averageArray
 
MultidimArray< double > stdArray
 
MultidimArray< double > dummyArray
 
Mask mask
 
int short_format
 
int save_mask
 
int repair
 
bool show_angles
 
bool save_image_stats
 
bool apply_mask
 
double min_val
 
double max_val
 
double avg
 
double stddev
 
double mean_min_val
 
double mean_max_val
 
double mean_avg
 
double mean_stddev
 
int max_length
 
FileName maskFileName
 
FileName statsRoot
 
- Protected Attributes inherited from XmippMetadataProgram
WriteModeMetaData mode
 Metadata writing mode: OVERWRITE, APPEND. More...
 
FileName oext
 Output extension and root. More...
 
FileName oroot
 
MDLabel image_label
 MDLabel to be used to read/write images, usually will be MDL_IMAGE. More...
 
bool produces_an_output
 Indicate that a unique final output is produced. More...
 
bool produces_a_metadata
 Indicate that the unique final output file is a Metadata. More...
 
bool each_image_produces_an_output
 Indicate that an output is produced for each image in the input. More...
 
bool allow_apply_geo
 
bool decompose_stacks
 Input Metadata will treat a stack file as a set of images instead of a unique file. More...
 
bool delete_output_stack
 Delete previous output stack file prior to process images. More...
 
bool get_image_info
 Get the input image file dimensions to further operations. More...
 
bool save_metadata_stack
 Save the associated output metadata when output file is a stack. More...
 
bool track_origin
 Include the original input image filename in the output stack. More...
 
bool keep_input_columns
 Keep input metadata columns. More...
 
bool remove_disabled
 Remove disabled images from the input selfile. More...
 
bool allow_time_bar
 Show process time bar. More...
 
bool input_is_metadata
 Input is a metadata. More...
 
bool single_image
 Input is a single image. More...
 
bool input_is_stack
 Input is a stack. More...
 
bool output_is_stack
 Output is a stack. More...
 
bool create_empty_stackfile
 
bool delete_mdIn
 
size_t time_bar_step
 Some time bar related counters. More...
 
size_t time_bar_size
 
size_t time_bar_done
 
- 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
 

Additional Inherited Members

- Public Member Functions inherited from XmippMetadataProgram
MetaDatagetInputMd ()
 
MetaDataVecgetOutputMd ()
 
 XmippMetadataProgram ()
 Empty constructor. More...
 
virtual int tryRead (int argc, const char **argv, bool reportErrors=true)
 
virtual void init ()
 
virtual void setup (MetaData *md, const FileName &o="", const FileName &oroot="", bool applyGeo=false, MDLabel label=MDL_IMAGE)
 
virtual ~XmippMetadataProgram ()
 
void setMode (WriteModeMetaData _mode)
 
void setupRowOut (const FileName &fnImgIn, const MDRow &rowIn, const FileName &fnImgOut, MDRow &rowOut) const
 Prepare rowout. More...
 
virtual void wait ()
 Wait for the distributor to finish. More...
 
virtual void checkPoint ()
 For very long programs, it may be needed to write checkpoints. More...
 
virtual void run ()
 Run over all images. More...
 
- 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)
 
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 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 inherited from XmippMetadataProgram
FileName fn_in
 Filenames of input and output Metadata. More...
 
FileName fn_out
 
FileName baseName
 
FileName pathBaseName
 
FileName oextBaseName
 
bool apply_geo
 Apply geo. More...
 
size_t ndimOut
 Output dimensions. More...
 
size_t zdimOut
 
size_t ydimOut
 
size_t xdimOut
 
DataType datatypeOut
 
size_t mdInSize
 Number of input elements. More...
 
- Public Attributes inherited from XmippProgram
bool doRun
 
bool runWithoutArgs
 
int verbose
 Verbosity level. More...
 
int debug
 

Detailed Description

Definition at line 35 of file image_statistics.cpp.

Member Function Documentation

◆ defineParams()

void ProgStatistics::defineParams ( )
inlineprotectedvirtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Definition at line 59 of file image_statistics.cpp.

60  {
62  allow_apply_geo = true;
63  allow_time_bar = false;
64  addUsageLine("Display statistics of 2D/3Dimages. A mask can be applied. Average Images may be computed");
65  addUsageLine("All images must have same size");
67  addParamsLine("[-o <metadata>] : Save the statistics in this metadata file.");
68  addParamsLine("[--short_format] : Do not show labels for statistics.");
69  addParamsLine("[--show_angles] : Also show angles in the image header.");
70  addParamsLine("[--save_mask <maskFileName>] : Save 2D and 3D masks.");
71  addParamsLine("[--save_image_stats <stats_root=\"\">]: Save average and standard deviation images");
72  addUsageLine (" Mask is ignored for this operation");
73  mask.defineParams(this,INT_MASK,nullptr,"Statistics restricted to the mask area.");
74  addUsageLine ("NOTE: Geometry will NOT be applied to volumes even if apply_geo flag is on");
75  addKeywords("statistics average mean std");
76  }
static void defineParams(XmippProgram *program, int allowed_data_types=ALL_KINDS, const char *prefix=nullptr, const char *comment=nullptr, bool moreOptions=false)
Definition: mask.cpp:1203
void addKeywords(const char *keywords)
bool allow_time_bar
Show process time bar.
#define INT_MASK
Definition: mask.h:385
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 addParamsLine(const String &line)

◆ postProcess()

void ProgStatistics::postProcess ( )
inlineprotectedvirtual

Reimplemented from XmippMetadataProgram.

Definition at line 204 of file image_statistics.cpp.

205  {
206 
207  if (mdInSize > 1)
208  {
211  mean_avg /= mdInSize;
213 
214  if (verbose)
215  {
216  // Show total statistics ------------------------------------------------
217  std::cout << "==================================================\n";
218  std::cout << "Total number of images/volumes: " << mdInSize << std::endl;
219  std::cout << stringToString(" ", max_length + 13);
220  if (!short_format)
221  std::cout << formatString("min=%10f max=%10f avg=%10f stddev=%10f",
223  else
224  std::cout << formatString("%10f %10f %10f %10f", mean_min_val, mean_max_val, mean_avg, mean_stddev);
225  std::cout << std::endl;
226  }
227 
228  if (save_image_stats)
229  {
231  if (mdInSize > 1)
232  {
234  stdArray *= mdInSize / (mdInSize - 1);
235  //Do this as an image since it is not define for arrays
238  }
239  else
241  }
242  }
243 
244  // Save masks -----------------------------------------------------------
245  if (save_mask)
247  // Save statistics ------------------------------------------------------
248  if (fn_out != "")
250 
251  //save average and std images
252  if(save_image_stats)
253  {
254  Image<double> dummyImage;
255  dummyImage() = averageArray;
256  dummyImage.write(statsRoot + "average.xmp");
257  dummyImage() = stdArray;
258  dummyImage.write(statsRoot + "stddev.xmp");
259  }
260  }
size_t mdInSize
Number of input elements.
void sqrt(Image< double > &op)
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 write(const FileName &outFile, WriteModeMetaData mode=MD_OVERWRITE) const
MultidimArray< double > averageArray
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int verbose
Verbosity level.
String stringToString(const String &str, size_t _width)
MetaDataVec DF_stats
MultidimArray< double > stdArray
String formatString(const char *format,...)
void write_mask(const FileName &fn)
Definition: mask.cpp:1192
void initZeros(const MultidimArray< T1 > &op)
int * n

◆ preProcess()

void ProgStatistics::preProcess ( )
inlineprotectedvirtual

Reimplemented from XmippMetadataProgram.

Definition at line 103 of file image_statistics.cpp.

104  {
105  DF_stats.setComment((std::string)"Statistics of " + fn_in);
106  // Get maximum filename size ---------------------------------------------
108 
109  // Process each file -----------------------------------------------------
110  mean_min_val = 0, mean_max_val = 0, mean_avg = 0, mean_stddev = 0;
111 
112  if (verbose > 0)
113  {
114  if (short_format)
115  {
116  std::cout << "Format: Name ZxYxX min max avg stddev ";
117  if (show_angles)
118  std::cout << " <rot tilt psi>";
119  std::cout << '>' << std::endl;
120  }
121  }
122 
123  // get xdim, ydim,zdim
124  //getImageSize(mdIn, xDim, yDim, zDim, nDim, image_label);
125  averageArray.resize(ndimOut, zdimOut, ydimOut, xdimOut);
126  stdArray.resize(ndimOut,zdimOut,ydimOut,xdimOut);
127  averageArray.setXmippOrigin();
128  stdArray.setXmippOrigin();
129 
130  // Generate mask if necessary
131  if (apply_mask)
132  mask.generate_mask(zdimOut, ydimOut, xdimOut);
133 
134  }
virtual void setComment(const String &newComment="No comment")
FileName fn_in
Filenames of input and output Metadata.
int verbose
Verbosity level.
virtual int getMaxStringLength(const MDLabel thisLabel) const =0
MetaDataVec DF_stats
MDLabel image_label
MDLabel to be used to read/write images, usually will be MDL_IMAGE.

◆ processImage()

void ProgStatistics::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
inlineprotectedvirtual

Implements XmippMetadataProgram.

Definition at line 136 of file image_statistics.cpp.

137  {
138  if (apply_geo)
139  image.readApplyGeo(fnImg, rowIn);
140  else
141  image.read(fnImg, DATA, ALL_IMAGES, true);
142 
143  image().setXmippOrigin();
144 
145  double rot = 0, tilt = 0, psi = 0;
146  if (show_angles)
147  image.getEulerAngles(rot,tilt,psi);
148 
149  if (apply_mask)
150  {
152  avg, stddev);
153  }
154  else
155  image().computeStats(avg, stddev, min_val, max_val);
156 
157  if(save_image_stats)
158  {
159  //copy image from imageGeneric
160  image().getImage( dummyArray );
163  }
164 
165  // Show information
166  if (verbose > 0)
167  {
168  std::cout << stringToString(fnImg, max_length + 1);
169  if (zdimOut > 1)
170  formatString("%4dx%4dx%4d ", zdimOut, ydimOut, xdimOut);
171  else
172  formatString("%4dx%4d", ydimOut, xdimOut);
173 
174  if (!short_format)
175  {
176  std::cout << formatString("min=%10f max=%10f avg=%10f stddev=%10f",
178 
179  if (show_angles)
180  std::cout << formatString("rot=%10f tilt=%10f psi=%10f", rot, tilt, psi);
181  }
182  else
183  std::cout << formatString("%10f %10f %10f %10f", min_val, max_val, avg, stddev);
184  }
185  size_t id;
186  id = DF_stats.addObject();
187  DF_stats.setRow(rowIn,id);
192 
193  // Total statistics
196  mean_avg += avg;
197  mean_stddev += stddev;
198 
199  // Finish information .................................................
200  if (verbose > 0)
201  std::cout << std::endl;
202  }
tsne coefficients in 2D
Maximum value (double)
void getEulerAngles(double &rot, double &tilt, double &psi, size_t n=0)
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
Minimum value (double)
MultidimArray< double > dummyArray
MultidimArray< double > averageArray
ImageGeneric image
bool setValue(const MDObject &mdValueIn, size_t id)
size_t addObject() override
int verbose
Verbosity level.
String stringToString(const String &str, size_t _width)
MetaDataVec DF_stats
MultidimArray< double > stdArray
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
double psi(const double x)
#define ALL_IMAGES
String formatString(const char *format,...)
average value (double)
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
bool setRow(const MDRow &row, size_t id)

◆ readParams()

void ProgStatistics::readParams ( )
inlineprotectedvirtual

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

Reimplemented from XmippMetadataProgram.

Definition at line 78 of file image_statistics.cpp.

79  {
81  short_format = checkParam("--short_format");
82 
83  if ((save_mask = checkParam("--save_mask")))
84  maskFileName = getParam("--save_mask");
85 
86  if ((save_image_stats = checkParam("--save_image_stats")))
87  statsRoot = getParam("--save_image_stats");
88 
89  show_angles = checkParam("--show_angles");
90  fn_out = (checkParam("-o"))? getParam("-o"): "";
91 
93 
94  if ((apply_mask = checkParam("--mask")))
95  mask.readParams(this);
96  }
int allowed_data_types
Definition: mask.h:495
const char * getParam(const char *param, int arg=0)
void readParams(XmippProgram *program)
Definition: mask.cpp:1284
#define INT_MASK
Definition: mask.h:385
bool checkParam(const char *param)

◆ show()

void ProgStatistics::show ( )
inlineprotected

Definition at line 98 of file image_statistics.cpp.

99  {
100  std::cout << " Statistics of " << fn_in << std::endl;
101  }
FileName fn_in
Filenames of input and output Metadata.

Member Data Documentation

◆ apply_mask

bool ProgStatistics::apply_mask
protected

Definition at line 50 of file image_statistics.cpp.

◆ averageArray

MultidimArray<double> ProgStatistics::averageArray
protected

Definition at line 40 of file image_statistics.cpp.

◆ avg

double ProgStatistics::avg
protected

Definition at line 52 of file image_statistics.cpp.

◆ DF_stats

MetaDataVec ProgStatistics::DF_stats
protected

Definition at line 38 of file image_statistics.cpp.

◆ dummyArray

MultidimArray<double> ProgStatistics::dummyArray
protected

Definition at line 42 of file image_statistics.cpp.

◆ image

ImageGeneric ProgStatistics::image
protected

Definition at line 39 of file image_statistics.cpp.

◆ mask

Mask ProgStatistics::mask
protected

Definition at line 44 of file image_statistics.cpp.

◆ maskFileName

FileName ProgStatistics::maskFileName
protected

Definition at line 57 of file image_statistics.cpp.

◆ max_length

int ProgStatistics::max_length
protected

Definition at line 54 of file image_statistics.cpp.

◆ max_val

double ProgStatistics::max_val
protected

Definition at line 52 of file image_statistics.cpp.

◆ mean_avg

double ProgStatistics::mean_avg
protected

Definition at line 53 of file image_statistics.cpp.

◆ mean_max_val

double ProgStatistics::mean_max_val
protected

Definition at line 53 of file image_statistics.cpp.

◆ mean_min_val

double ProgStatistics::mean_min_val
protected

Definition at line 53 of file image_statistics.cpp.

◆ mean_stddev

double ProgStatistics::mean_stddev
protected

Definition at line 53 of file image_statistics.cpp.

◆ min_val

double ProgStatistics::min_val
protected

Definition at line 52 of file image_statistics.cpp.

◆ repair

int ProgStatistics::repair
protected

Definition at line 47 of file image_statistics.cpp.

◆ save_image_stats

bool ProgStatistics::save_image_stats
protected

Definition at line 49 of file image_statistics.cpp.

◆ save_mask

int ProgStatistics::save_mask
protected

Definition at line 46 of file image_statistics.cpp.

◆ short_format

int ProgStatistics::short_format
protected

Definition at line 45 of file image_statistics.cpp.

◆ show_angles

bool ProgStatistics::show_angles
protected

Definition at line 48 of file image_statistics.cpp.

◆ statsRoot

FileName ProgStatistics::statsRoot
protected

Definition at line 57 of file image_statistics.cpp.

◆ stdArray

MultidimArray<double> ProgStatistics::stdArray
protected

Definition at line 41 of file image_statistics.cpp.

◆ stddev

double ProgStatistics::stddev
protected

Definition at line 52 of file image_statistics.cpp.


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