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

Threshold Parameters. More...

#include <threshold.h>

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

Public Member Functions

void readParams ()
 
void defineParams ()
 
void show ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 Process image or volume. More...
 
- 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

String selectionMethod
 
double threshold
 
String substitutionMethod
 
double newValue
 
double noiseAvg
 
double noiseStddev
 
int iSelectionMethod
 
- 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
 

Additional Inherited Members

- Protected Member Functions inherited from XmippMetadataProgram
virtual void initComments ()
 
virtual void preProcess ()
 
virtual void postProcess ()
 
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 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
 

Detailed Description

Threshold Parameters.

Definition at line 38 of file threshold.h.

Member Function Documentation

◆ defineParams()

void ProgThreshold::defineParams ( )
virtual

Define Parameters

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgThreshold >.

Definition at line 51 of file threshold.cpp.

52 {
53  addUsageLine("Threshold volumes and images ");
56  addSeeAlsoLine("transform_mask, transform_morphology");
57  addParamsLine(" --select <mode> : Select pixels meeting");
58  addParamsLine(" where <mode>");
59  addParamsLine(" abs_below <th> : Absolute value below a threshold");
60  addParamsLine(" below <th> : Below a threshold");
61  addParamsLine(" above <th> : Above a threshold");
62  addParamsLine(" --substitute <substitutionMode=value> : Substitute selected pixels by");
63  addParamsLine(" where <substitutionMode>");
64  addParamsLine(" binarize : Selected are set to 0, non-selected to 1");
65  addParamsLine(" value <new=0> : New value");
66  addParamsLine(" noise <avg=0> <stddev=1> : Gaussian noise");
67  addParamsLine(" avg : Average of non-selected");
68  addExampleLine("Threshold a volume below a threshold",false);
69  addExampleLine("xmipp_transform_threshold -i volume.vol -o volumeThresholded.vol --select below 0.01 --substitute value 0");
70  addExampleLine("Generate a binary mask based on a threshold and apply it",false);
71  addExampleLine("xmipp_transform_threshold -i volume.vol -o mask.vol --select below 0.5 --substitute binarize");
72  addExampleLine("xmipp_transform_morphology -i mask.vol --dil");
73  addExampleLine("xmipp_transform_mask -i volume.vol -o volumeMasked.vol --mask mask.vol");
74 }
void addSeeAlsoLine(const char *seeAlso)
void addExampleLine(const char *example, bool verbatim=true)
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)

◆ processImage()

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

Process image or volume.

Implements XmippMetadataProgram.

Definition at line 96 of file threshold.cpp.

97 {
98  Image<double> I;
99  I.read(fnImg);
100  MultidimArray<double> &mI=I();
101 
102  // Compute substitute value
103  double substituteValue=0.0;
104  if (substitutionMethod=="value")
105  substituteValue=newValue;
106  else if (substitutionMethod=="noise")
107  substituteValue=rnd_gaus(noiseAvg,noiseStddev);
108  else if (substitutionMethod=="avg")
109  {
110  double N=0;
111  switch (iSelectionMethod)
112  {
113  case 0:
115  {
116  double pixval=DIRECT_MULTIDIM_ELEM(mI,n);
117  if (fabs(pixval)>threshold)
118  {
119  substituteValue+=pixval;
120  ++N;
121  }
122  }
123  break;
124  case 1:
126  {
127  double pixval=DIRECT_MULTIDIM_ELEM(mI,n);
128  if (pixval>threshold)
129  {
130  substituteValue+=pixval;
131  ++N;
132  }
133  }
134  break;
135  case 2:
137  {
138  double pixval=DIRECT_MULTIDIM_ELEM(mI,n);
139  if (pixval<threshold)
140  {
141  substituteValue+=pixval;
142  ++N;
143  }
144  }
145  break;
146  }
147  substituteValue/=N;
148  }
149 
150  // Apply threshold
151  bool binarize=substitutionMethod=="binarize";
152  switch (iSelectionMethod)
153  {
154  case 0:
156  {
157  if (fabs(DIRECT_MULTIDIM_ELEM(mI,n))<threshold)
158  DIRECT_MULTIDIM_ELEM(mI,n)=substituteValue;
159  else if (binarize)
160  DIRECT_MULTIDIM_ELEM(mI,n)=1;
161  }
162  break;
163  case 1:
165  {
167  DIRECT_MULTIDIM_ELEM(mI,n)=substituteValue;
168  else if (binarize)
169  DIRECT_MULTIDIM_ELEM(mI,n)=1;
170  }
171  break;
172  case 2:
174  {
176  DIRECT_MULTIDIM_ELEM(mI,n)=substituteValue;
177  else if (binarize)
178  DIRECT_MULTIDIM_ELEM(mI,n)=1;
179  }
180  break;
181  }
182 
183  // Write result
184  I.write(fnImgOut);
185 }
double newValue
Definition: threshold.h:51
double threshold
Definition: threshold.h:45
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)
String substitutionMethod
Definition: threshold.h:48
int iSelectionMethod
Definition: threshold.h:72
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
double noiseAvg
Definition: threshold.h:54
double rnd_gaus()
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int * n
double noiseStddev
Definition: threshold.h:57

◆ readParams()

void ProgThreshold::readParams ( )
virtual

Read parameters from command line.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgThreshold >.

Definition at line 29 of file threshold.cpp.

30 {
32  selectionMethod=getParam("--select");
33  if (selectionMethod=="abs_below")
35  else if (selectionMethod=="below")
37  else if (selectionMethod=="above")
39  threshold=getDoubleParam("--select",1);
40  substitutionMethod=getParam("--substitute");
41  if (substitutionMethod=="value")
42  newValue=getDoubleParam("--substitute",1);
43  else if (substitutionMethod=="noise")
44  {
45  noiseAvg=getDoubleParam("--substitute",1);
46  noiseStddev=getDoubleParam("--substitute",2);
47  }
48 }
double getDoubleParam(const char *param, int arg=0)
double newValue
Definition: threshold.h:51
double threshold
Definition: threshold.h:45
String substitutionMethod
Definition: threshold.h:48
String selectionMethod
Definition: threshold.h:42
int iSelectionMethod
Definition: threshold.h:72
const char * getParam(const char *param, int arg=0)
double noiseAvg
Definition: threshold.h:54
double noiseStddev
Definition: threshold.h:57

◆ show()

void ProgThreshold::show ( )

Show parameters

Definition at line 77 of file threshold.cpp.

78 {
79  if (verbose==0)
80  return;
82  std::cout
83  << "Selection method: " << selectionMethod << std::endl
84  << "Threshold: " << threshold << std::endl
85  << "Substitution method: " << substitutionMethod << std::endl;
86  if (substitutionMethod=="value")
87  std::cout << "New value: " << newValue << std::endl;
88  else if (substitutionMethod=="noise")
89  {
90  std::cout << "Noise average: " << noiseAvg << std::endl;
91  std::cout << "Noise std.dev.: " << noiseStddev << std::endl;
92  }
93 }
double newValue
Definition: threshold.h:51
double threshold
Definition: threshold.h:45
String substitutionMethod
Definition: threshold.h:48
String selectionMethod
Definition: threshold.h:42
int verbose
Verbosity level.
void show() const override
double noiseAvg
Definition: threshold.h:54
double noiseStddev
Definition: threshold.h:57

Member Data Documentation

◆ iSelectionMethod

int ProgThreshold::iSelectionMethod

Definition at line 72 of file threshold.h.

◆ newValue

double ProgThreshold::newValue

Definition at line 51 of file threshold.h.

◆ noiseAvg

double ProgThreshold::noiseAvg

Definition at line 54 of file threshold.h.

◆ noiseStddev

double ProgThreshold::noiseStddev

Definition at line 57 of file threshold.h.

◆ selectionMethod

String ProgThreshold::selectionMethod

Definition at line 42 of file threshold.h.

◆ substitutionMethod

String ProgThreshold::substitutionMethod

Definition at line 48 of file threshold.h.

◆ threshold

double ProgThreshold::threshold

Definition at line 45 of file threshold.h.


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