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

Public Member Functions

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

bool binaryOperation
 
int operation
 
int size
 
int count
 
int neig2D
 
int neig3D
 
double width
 
double strength
 
int smallSize
 
- 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

Definition at line 33 of file transform_morphology.cpp.

Member Function Documentation

◆ defineParams()

void ProgMorphology::defineParams ( )
inlinevirtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Definition at line 53 of file transform_morphology.cpp.

54  {
56  addUsageLine("Apply morphological operations to binary or gray images/volumes.");
57  addUsageLine("+You may learn about morphological operations in general from");
58  addUsageLine("[[http://en.wikipedia.org/wiki/Mathematical_morphology][here]].");
59  addUsageLine("");
61  addParamsLine("--binaryOperation <op>: Morphological operation on binary images");
62  addParamsLine(" where <op>");
63  addParamsLine(" dilation : Dilate white region");
64  addParamsLine(" erosion : Erode white region");
65  addParamsLine(" closing : Dilation+Erosion, removes black spots");
66  addParamsLine(" opening : Erosion+Dilation, removes white spots");
67  addParamsLine(" keepBiggest : Keep biggest component");
68  addParamsLine(" removeSmall <size=10> : Remove components whose size is smaller than this size");
69  addParamsLine("or --grayOperation <op>: Morphological operation on gray images");
70  addParamsLine(" where <op>");
71  addParamsLine(" sharpening <w=1> <s=0.5>: Sharpening with width (suggested 1 or 2)");
72  addParamsLine(" : and strength (suggested 0.1-1.0).");
73  addParamsLine(" : Only valid for volumes, not images.");
74  addParamsLine(" :++ Implemented according to JGM Schavemaker, MJT Reinders, JJ Gerbrands,");
75  addParamsLine(" :++ E Backer. Image sharpening by morphological filtering. Pattern Recognition");
76  addParamsLine(" :++ 33: 997-1012 (2000)");
77  addParamsLine("[--neigh2D+ <n=Neigh8>] : Neighbourhood in 2D.");
78  addParamsLine(" where <n>");
79  addParamsLine(" Neigh4");
80  addParamsLine(" Neigh8");
81  addParamsLine(" requires --binaryOperation;");
82  addParamsLine("[--neigh3D+ <n=Neigh18>] : Neighbourhood in 3D.");
83  addParamsLine(" where <n>");
84  addParamsLine(" Neigh6");
85  addParamsLine(" Neigh18");
86  addParamsLine(" Neigh26");
87  addParamsLine(" requires --binaryOperation;");
88  addParamsLine("[--size <s=1>]: Size of the Strutural element.");
89  addParamsLine(" requires --binaryOperation;");
90  addParamsLine("[--count+ <c=0>]: Minimum required neighbors with distinct value.");
91  addParamsLine(" requires --binaryOperation;");
92  addExampleLine("xmipp_transform_morphology -i binaryVolume.vol --binaryOperation dilation");
93  }
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 ProgMorphology::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
inlinevirtual

Implements XmippMetadataProgram.

Definition at line 180 of file transform_morphology.cpp.

181  {
182  Image<double> img, imgOut;
183  img.readApplyGeo(fnImg, rowIn);
184  imgOut().resizeNoCopy(img());
185 
186  if (binaryOperation)
187  std::cout << "Initially the image has " << img().sum()
188  << " pixels set to 1\n";
189  bool isVolume=ZSIZE(img())>1;
190  switch (operation)
191  {
192  case DILATION:
193  if (isVolume)
194  dilate3D(img(), imgOut(), neig3D, count, size);
195  else
196  dilate2D(img(), imgOut(), neig2D, count, size);
197  break;
198  case EROSION:
199  if (isVolume)
200  erode3D(img(), imgOut(), neig3D, count, size);
201  else
202  erode2D(img(), imgOut(), neig2D, count, size);
203  break;
204  case OPENING:
205  if (isVolume)
206  opening3D(img(), imgOut(), neig3D, count, size);
207  else
208  opening2D(img(), imgOut(), neig2D, count, size);
209  break;
210  case CLOSING:
211  if (isVolume)
212  closing3D(img(), imgOut(), neig3D, count, size);
213  else
214  closing2D(img(), imgOut(), neig2D, count, size);
215  break;
216  case SHARPENING:
217  if (isVolume)
218  sharpening(img(), width, strength, imgOut());
219  else
220  REPORT_ERROR(ERR_NOT_IMPLEMENTED,"Sharpening has not been implemented for images");
221  break;
222  case KEEPBIGGEST:
223  if (isVolume)
224  keepBiggestComponent(img(),0,neig3D);
225  else
226  keepBiggestComponent(img(),0,neig2D);
227  imgOut()=img();
228  break;
229  case REMOVESMALL:
230  if (isVolume)
232  else
234  imgOut()=img();
235  break;
236  }
237 
238  if (binaryOperation)
239  std::cout << "Finally the image has " << imgOut().sum() << " pixels set to 1\n";
240  imgOut.write(fnImgOut);
241  }
void erode3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:407
Case or algorithm not implemented yet.
Definition: xmipp_error.h:177
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
#define CLOSING
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 EROSION
#define REMOVESMALL
#define DILATION
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
#define KEEPBIGGEST
void opening2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:148
void opening3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:440
void closing3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:422
#define OPENING
void erode2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:116
void removeSmallComponents(MultidimArray< double > &I, int size, int neighbourhood)
Definition: filters.cpp:689
void closing2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:130
#define ZSIZE(v)
void dilate3D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:394
void sharpening(const MultidimArray< double > &in, double width, double strength, MultidimArray< double > &out)
Definition: morphology.cpp:522
void keepBiggestComponent(MultidimArray< double > &I, double percentage, int neighbourhood)
Definition: filters.cpp:713
void dilate2D(const MultidimArray< double > &in, MultidimArray< double > &out, int neig, int count, int size)
Definition: morphology.cpp:103
#define SHARPENING

◆ readParams()

void ProgMorphology::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 XmippMetadataProgram.

Definition at line 95 of file transform_morphology.cpp.

96  {
98  binaryOperation=checkParam("--binaryOperation");
99  if (binaryOperation)
100  {
101  String strOperation=getParam("--binaryOperation");
102  if (strOperation=="dilation")
104  else if (strOperation=="erosion")
105  operation = EROSION;
106  else if (strOperation=="closing")
107  operation = CLOSING;
108  else if (strOperation=="opening")
109  operation = OPENING;
110  else if (strOperation=="keepBiggest")
112  else if (strOperation=="removeSmall")
113  {
115  smallSize = getIntParam("--binaryOperation",1);
116  }
117 
118  size = getIntParam("--size");
119  String neighbourhood=getParam("--neigh2D");
120  if (neighbourhood=="Neigh8")
121  neig2D = 8;
122  else
123  neig2D = 4;
124  neighbourhood=getParam("--neigh3D");
125  if (neighbourhood=="Neigh6")
126  neig3D = 6;
127  else if (neighbourhood=="Neigh18")
128  neig3D = 18;
129  else
130  neig3D = 26;
131  count = getIntParam("--count");
132  }
133  else if (checkParam("--grayOperation"))
134  {
135  String strOperation=getParam("--grayOperation");
136  if (strOperation=="sharpening")
137  {
139  width=getDoubleParam("--grayOperation",1);
140  strength=getDoubleParam("--grayOperation",2);
141  }
142  }
143  }
double getDoubleParam(const char *param, int arg=0)
#define CLOSING
#define EROSION
#define REMOVESMALL
#define DILATION
#define KEEPBIGGEST
#define OPENING
const char * getParam(const char *param, int arg=0)
std::string String
Definition: xmipp_strings.h:34
bool checkParam(const char *param)
#define SHARPENING
int getIntParam(const char *param, int arg=0)

◆ show()

void ProgMorphology::show ( )
inline

Definition at line 145 of file transform_morphology.cpp.

146  {
147  std::cout << "Performing a ";
148  switch (operation)
149  {
150  case DILATION :
151  std::cout << "Dilation\n";
152  break;
153  case EROSION :
154  std::cout << "Erosion\n";
155  break;
156  case OPENING :
157  std::cout << "Opening\n";
158  break;
159  case CLOSING :
160  std::cout << "Closing\n";
161  break;
162  case SHARPENING :
163  std::cout << "Sharpening\n"
164  << "Width = " << width << std::endl
165  << "Strength = " << strength << std::endl;
166  case KEEPBIGGEST :
167  std::cout << "Keeping biggest component\n";
168  break;
169  case REMOVESMALL :
170  std::cout << "Removing small objects\n"
171  << "Small size < " << smallSize << std::endl;
172  break;
173  }
174  if (binaryOperation)
175  std::cout << "Size=" << size << std::endl
176  << "Neighbourhood2D=" << neig2D << std::endl
177  << "Neighbourhood3D=" << neig3D << std::endl
178  << "Count=" << count << std::endl;
179  }
#define CLOSING
#define EROSION
#define REMOVESMALL
#define DILATION
#define KEEPBIGGEST
#define OPENING
#define SHARPENING

Member Data Documentation

◆ binaryOperation

bool ProgMorphology::binaryOperation

Definition at line 44 of file transform_morphology.cpp.

◆ count

int ProgMorphology::count

Definition at line 47 of file transform_morphology.cpp.

◆ neig2D

int ProgMorphology::neig2D

Definition at line 48 of file transform_morphology.cpp.

◆ neig3D

int ProgMorphology::neig3D

Definition at line 48 of file transform_morphology.cpp.

◆ operation

int ProgMorphology::operation

Definition at line 45 of file transform_morphology.cpp.

◆ size

int ProgMorphology::size

Definition at line 46 of file transform_morphology.cpp.

◆ smallSize

int ProgMorphology::smallSize

Definition at line 51 of file transform_morphology.cpp.

◆ strength

double ProgMorphology::strength

Definition at line 50 of file transform_morphology.cpp.

◆ width

double ProgMorphology::width

Definition at line 49 of file transform_morphology.cpp.


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