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

Public Member Functions

void defineParams ()
 
void readParams ()
 
void run ()
 
- 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

Image< double > image
 
MetaDataVec mdIn
 
FileName fn_in
 
FileName fn_out
 
FileName fn_sel
 
Mask mask
 
MultidimArray< int > maskArray
 
bool automatic_range
 
bool do_normalize
 
bool apply_mask
 
double m
 
double M
 
int StepsNo
 
Histogram1D hist
 
Histogram1D histb
 
- 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

Definition at line 31 of file image_histogram.cpp.

Member Function Documentation

◆ defineParams()

void ProgHistogram::defineParams ( )
inlinevirtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 44 of file image_histogram.cpp.

45  {
46  addUsageLine("Calculate histogram from a list of images/volumes");
47  addParamsLine(" -i <input_file> : input metadata, image, volume or stack");
48  addParamsLine(" [-o <text_file>] : output text file with histogram");
49  addParamsLine(" [--range <m> <M>] : range for the histogram, automatic calculated if not provided");
50  addParamsLine(" [--steps <N=100>] : number of subdivisions");
51  addParamsLine(" [--norm] : normalize histogram ");
52  mask.defineParams(this, INT_MASK, nullptr, "Histogram constrained to the mask area.");
53 
54  addExampleLine("Create the histogram from an stack setting number of steps to 20", false);
55  addExampleLine("xmipp_histogram -i input/images_some.stk -o hist.txt --steps 20");
56  addExampleLine("You can use the =hist.txt= file with =gnuplot= to produce graphical histogram", false);
57  addExampleLine("After you enter =gnuplot= terminal you can use:", false);
58  addExampleLine("gnuplot> plot \"kk.txt\" using 1:2 title \"Histogram\" with steps");
59 
60  addSeeAlsoLine("metadata_histogram");
61  }
void addSeeAlsoLine(const char *seeAlso)
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 addExampleLine(const char *example, bool verbatim=true)
#define INT_MASK
Definition: mask.h:385
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgHistogram::readParams ( )
inlinevirtual

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 63 of file image_histogram.cpp.

64  {
65  fn_in = getParam("-i");
66  mdIn.read(fn_in);
67 
68  if (mdIn.isEmpty())
69  REPORT_ERROR(ERR_PARAM_INCORRECT, "Can't calculate histogram from empty metadata");
70 
71  if (checkParam("-o"))
72  fn_out = getParam("-o");
73 
74  StepsNo = getIntParam("--steps");
75  do_normalize = checkParam("--norm");
76  automatic_range = true;
77 
78  if (checkParam("--range"))
79  {
80  m = getDoubleParam("--range", 0);
81  M = getDoubleParam("--range", 1);
82  automatic_range = false;
83  }
84 
86  if ((apply_mask = checkParam("--mask")))
87  mask.readParams(this);
88 
89  //todo: check this
90  // if (fn_sel!="" && automatic_range)
91  // REPORT_ERROR(ERR_ARG_INCORRECT,"Only use selfile in combination with fixed range!");
92  //
93  // mask_prm.read(argc, argv);
94 
95  }
Parameter incorrect.
Definition: xmipp_error.h:181
MetaDataVec mdIn
double getDoubleParam(const char *param, int arg=0)
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
int allowed_data_types
Definition: mask.h:495
bool isEmpty() const override
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)
int getIntParam(const char *param, int arg=0)

◆ run()

void ProgHistogram::run ( )
inlinevirtual

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

Reimplemented from XmippProgram.

Definition at line 97 of file image_histogram.cpp.

98  {
99  auto iterId = mdIn.ids().begin();
100  image.readApplyGeo(mdIn, *iterId);
101  image().setXmippOrigin();
102  double dummy;
103 
104  // Generate mask if necessary
105  if (apply_mask)
106  {
109  if (automatic_range)
110  computeStats_within_binary_mask(maskArray, image(), m, M, dummy, dummy);
111  }
112  else if (automatic_range)
113  image().computeDoubleMinMax(m, M);
114 
115  if (automatic_range)
116  {
117  m *= 1.5;
118  M *= 1.5;
119  }
120 
121  if (apply_mask)
123  else
125 
126  const auto totalSize = mdIn.ids().end();
127  while (++iterId != totalSize)
128  {
129  image.readApplyGeo(mdIn, *iterId);
130  image().setXmippOrigin();
131  // Compute histogram ----------------------------------------------------
132  if (apply_mask)
134  else
135  compute_hist(image(), hist, m, M, StepsNo);
136  histb += hist;
137  }
138 
139  if (do_normalize)
140  histb *= 1.0 / (histb.sum() * histb.step_size);
141 
142  if (!fn_out.empty())
143  histb.write(fn_out);
144  else
145  std::cout << histb;
146  }
MetaDataVec mdIn
Histogram1D hist
MultidimArray< int > maskArray
virtual IdIteratorProxy< false > ids()
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
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
Image< double > image
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
Histogram1D histb
double dummy
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
void write(const FileName &fn, MDLabel=MDL_X, MDLabel=MDL_COUNT)
Definition: histogram.cpp:129
double step_size
Definition: histogram.h:127
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
void compute_hist_within_binary_mask(const MultidimArray< int > &mask, MultidimArray< T > &v, Histogram1D &hist, int no_steps)
Definition: mask.h:906
double sum() const

Member Data Documentation

◆ apply_mask

bool ProgHistogram::apply_mask

Definition at line 39 of file image_histogram.cpp.

◆ automatic_range

bool ProgHistogram::automatic_range

Definition at line 39 of file image_histogram.cpp.

◆ do_normalize

bool ProgHistogram::do_normalize

Definition at line 39 of file image_histogram.cpp.

◆ fn_in

FileName ProgHistogram::fn_in

Definition at line 36 of file image_histogram.cpp.

◆ fn_out

FileName ProgHistogram::fn_out

Definition at line 36 of file image_histogram.cpp.

◆ fn_sel

FileName ProgHistogram::fn_sel

Definition at line 36 of file image_histogram.cpp.

◆ hist

Histogram1D ProgHistogram::hist

Definition at line 42 of file image_histogram.cpp.

◆ histb

Histogram1D ProgHistogram::histb

Definition at line 42 of file image_histogram.cpp.

◆ image

Image<double> ProgHistogram::image

Definition at line 34 of file image_histogram.cpp.

◆ m

double ProgHistogram::m

Definition at line 40 of file image_histogram.cpp.

◆ M

double ProgHistogram::M

Definition at line 40 of file image_histogram.cpp.

◆ mask

Mask ProgHistogram::mask

Definition at line 37 of file image_histogram.cpp.

◆ maskArray

MultidimArray<int> ProgHistogram::maskArray

Definition at line 38 of file image_histogram.cpp.

◆ mdIn

MetaDataVec ProgHistogram::mdIn

Definition at line 35 of file image_histogram.cpp.

◆ StepsNo

int ProgHistogram::StepsNo

Definition at line 41 of file image_histogram.cpp.


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