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

Public Member Functions

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

FileName fn_in
 
FileName fn_root
 
bool invert
 
double min_size
 
- 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 30 of file image_separate_objects.cpp.

Member Function Documentation

◆ defineParams()

void ProgSeparateObjects::defineParams ( )
inlinevirtual

Function in which the param of each Program are defined.

Reimplemented from XmippProgram.

Definition at line 47 of file image_separate_objects.cpp.

48  {
49  addUsageLine("Separate different disconnected objects in a binary volume. ");
50  addUsageLine("+In this way, small objects can be separated from large ones in ");
51  addUsageLine("+reconstructions. This is very useful for reconstructions. Objects ");
52  addUsageLine("+are written in separate files as binary volumes, too. Output volume ");
53  addUsageLine("+number 1 is the background, number 2 corresponds to object 1, number 3 ");
54  addUsageLine("+to object 2 ... This program also tells you the number of voxels on ");
55  addUsageLine("+each object. ");
56  addParamsLine(" -i <fn_in> : Input image or volume");
57  addParamsLine(" [--oroot <fn_root=\"\">] : Root filename for output");
58  addParamsLine(" : By default, the input name");
59  addParamsLine(" : The output masks are <fn_root>_000001.vol, ...");
60  addParamsLine(" [--invert] : Produce inverse masks");
61  addParamsLine(" [--min_size <size=0>] : Save if size is greater than this");
62  addSeeAlsoLine("transform_morphology, transform_threshold, transform_mask, volume_segment");
63  }
void addSeeAlsoLine(const char *seeAlso)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgSeparateObjects::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 37 of file image_separate_objects.cpp.

38  {
39  fn_in = getParam("-i");
40  fn_root = getParam("--oroot");
41  invert = checkParam("--invert");
42  min_size = getDoubleParam("--min_size");
43  if (fn_root == "")
45  }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
FileName withoutExtension() const
bool checkParam(const char *param)

◆ run()

void ProgSeparateObjects::run ( )
inlinevirtual

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

Reimplemented from XmippProgram.

Definition at line 65 of file image_separate_objects.cpp.

66  {
67  FileName fn_out;
68  FileName fn_ext = fn_in.getExtension();
69  Image<double> I, label;
70  I.read(fn_in);
71  int object_no;
72  if (ZSIZE(I())==1)
73  object_no=labelImage2D(I(), label());
74  else
75  object_no=labelImage3D(I(), label());
76  for (int o = 0; o <= object_no; o++)
77  {
78  I() = label();
81  {
83  if (invert)
85  }
86  double number_elements = I().sum();
87  if (number_elements > min_size)
88  {
89  fn_out.compose(fn_root, o+1, fn_ext);
90  I.write(fn_out);
91  }
92 
93  if (ZSIZE(I())==1)
94  std::cout << "Image number " << o+1 << " contains " << number_elements
95  << " pixels set to 1\n";
96  else
97  std::cout << "Volume number " << o+1 << " contains " << number_elements
98  << " voxels set to 1\n";
99  }
100  }
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)
#define MULTIDIM_ARRAY(v)
void compose(const String &str, const size_t no, const String &ext="")
String getExtension() const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define ZSIZE(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int labelImage2D(const MultidimArray< double > &I, MultidimArray< double > &label, int neighbourhood)
Definition: filters.cpp:648
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
int labelImage3D(const MultidimArray< double > &V, MultidimArray< double > &label)
Definition: filters.cpp:669
int * n

Member Data Documentation

◆ fn_in

FileName ProgSeparateObjects::fn_in

Definition at line 33 of file image_separate_objects.cpp.

◆ fn_root

FileName ProgSeparateObjects::fn_root

Definition at line 33 of file image_separate_objects.cpp.

◆ invert

bool ProgSeparateObjects::invert

Definition at line 34 of file image_separate_objects.cpp.

◆ min_size

double ProgSeparateObjects::min_size

Definition at line 35 of file image_separate_objects.cpp.


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