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

#include <classify_compare_classes.h>

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

Public Member Functions

void readParams ()
 Read input parameters. More...
 
void defineParams ()
 Define input parameters. More...
 
void show ()
 Show. More...
 
void run ()
 Execute. 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)
 
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 fnClass1
 Name of the two classification metadatas. More...
 
FileName fnClass2
 
FileName fnOut
 Name of the output text file. More...
 
bool append
 Append to output. 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 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

Compare a set of classes

Definition at line 37 of file classify_compare_classes.h.

Member Function Documentation

◆ defineParams()

void ProgCompareClass::defineParams ( )
virtual

Define input parameters.

Reimplemented from XmippProgram.

Definition at line 39 of file classify_compare_classes.cpp.

40 {
41  addUsageLine("Compare two classifications");
42  addUsageLine("+The program provides information about which class of classification 1 corresponds to which class of classification 2");
43  addUsageLine("+");
44  addParamsLine(" --i1 <infile1> : Metadata with the classification 1");
45  addParamsLine(" --i2 <infile2> : Metadata with the classification 2");
46  addParamsLine(" -o <outfile> : Output text file");
47  addParamsLine(" [--append] : Append text to output");
48  addExampleLine("xmipp_classify_compare_classes --i1 2D/CL2D/run_001/results_level_00_classes.xmd --i2 2D/CL2D/run_001/results_level_01_classes.xmd -o comparison_level_00_01.txt");
49 }
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ readParams()

void ProgCompareClass::readParams ( )
virtual

Read input parameters.

Reimplemented from XmippProgram.

Definition at line 31 of file classify_compare_classes.cpp.

32 {
33  fnClass1=getParam("--i1");
34  fnClass2=getParam("--i2");
35  fnOut=getParam("-o");
36  append=checkParam("--append");
37 }
const char * getParam(const char *param, int arg=0)
FileName fnClass1
Name of the two classification metadatas.
bool checkParam(const char *param)
bool append
Append to output.
FileName fnOut
Name of the output text file.

◆ run()

void ProgCompareClass::run ( )
virtual

Execute.

Reimplemented from XmippProgram.

Definition at line 61 of file classify_compare_classes.cpp.

62 {
63  MetaDataVec MD1(formatString("classes@%s",fnClass1.c_str()));
64  MetaDataVec MD2(formatString("classes@%s",fnClass2.c_str()));
65  std::vector<int> ref1, ref2;
66  int aux;
67  for (size_t objId : MD1.ids())
68  {
69  MD1.getValue(MDL_REF,aux,objId);
70  ref1.push_back(aux);
71  }
72  for (size_t objId : MD2.ids())
73  {
74  MD2.getValue(MDL_REF,aux,objId);
75  ref2.push_back(aux);
76  }
77 
78  Matrix2D<int> comparisonMatrix(MD1.size(),MD2.size());
79  Matrix1D<int> MD1classSize(MAT_YSIZE(comparisonMatrix)), MD2classSize(MAT_XSIZE(comparisonMatrix));
80 
81  // Read the size of the individual classes
82  MetaDataDb MDclass1, MDclass2;
83  FOR_ALL_ELEMENTS_IN_MATRIX1D(MD1classSize)
84  {
85  MDclass1.read(formatString("class%06d_images@%s",ref1[i],fnClass1.c_str()));
86  VEC_ELEM(MD1classSize,i)=MDclass1.size();
87  }
88 
89  FOR_ALL_ELEMENTS_IN_MATRIX1D(MD2classSize)
90  {
91  MDclass2.read(formatString("class%06d_images@%s",ref2[i],fnClass2.c_str()));
92  VEC_ELEM(MD2classSize,i)=MDclass2.size();
93  }
94 
95  // Now compare the two classifications
96  for (size_t i=0; i<MAT_YSIZE(comparisonMatrix); i++)
97  {
98  MDclass1.read(formatString("class%06d_images@%s",ref1[i],fnClass1.c_str()));
99  for (size_t j=0; j<MAT_XSIZE(comparisonMatrix); j++)
100  {
101  MDclass2.read(formatString("class%06d_images@%s",ref2[j],fnClass2.c_str()));
102  MDclass2.intersection(MDclass1,MDL_IMAGE);
103  MAT_ELEM(comparisonMatrix,i,j)=MDclass2.size();
104  }
105  }
106 
107  // Report analysis
108  std::ofstream fhOut;
109  if (append)
110  {
111  fhOut.open(fnOut.c_str(),std::ios::app);
112  fhOut << "\n\n------------------------------------------------------------------------\n";
113  }
114  else
115  fhOut.open(fnOut.c_str());
116  if (!fhOut)
118  fhOut << "Comparison of " << fnClass1 << " and " << fnClass2 << std::endl;
119  fhOut << "Analysis of " << fnClass1 << " =======================\n";
120  for (size_t i=0; i<MAT_YSIZE(comparisonMatrix); i++)
121  {
122  fhOut << "Class " << formatString("class%06d_images@%s",ref1[i],fnClass1.c_str()) << ": " << VEC_ELEM(MD1classSize,i) << " images\n";
123  for (size_t j=0; j<MAT_XSIZE(comparisonMatrix); j++)
124  if (MAT_ELEM(comparisonMatrix,i,j)>0)
125  fhOut << " " << 100.0*MAT_ELEM(comparisonMatrix,i,j)/VEC_ELEM(MD1classSize,i) << "% are in class " << formatString("class%06d_images@%s",j+1,fnClass2.c_str()) << std::endl;
126  }
127  fhOut << "\n\nAnalysis of " << fnClass2 << " =======================\n";
128  for (size_t j=0; j<MAT_XSIZE(comparisonMatrix); j++)
129  {
130  fhOut << "Class " << formatString("class%06d_images@%s",ref2[j],fnClass2.c_str()) << ": " << VEC_ELEM(MD2classSize,j) << " images\n";
131  for (size_t i=0; i<MAT_YSIZE(comparisonMatrix); i++)
132  if (MAT_ELEM(comparisonMatrix,i,j)>0)
133  fhOut << " " << 100.0*MAT_ELEM(comparisonMatrix,i,j)/VEC_ELEM(MD2classSize,j) << "% are in class " << formatString("class%06d_images@%s",i+1,fnClass1.c_str()) << std::endl;
134  }
135  fhOut.close();
136 }
#define MAT_YSIZE(m)
Definition: matrix2d.h:124
#define VEC_ELEM(v, i)
Definition: matrix1d.h:245
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
void intersection(const MetaDataDb &mdIn, const MDLabel label)
Couldn&#39;t write to file.
Definition: xmipp_error.h:140
#define i
#define MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
Definition: matrix1d.h:72
FileName fnClass1
Name of the two classification metadatas.
size_t size() const override
#define j
Class to which the image belongs (int)
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
String formatString(const char *format,...)
void read(const FileName &inFile, const std::vector< MDLabel > *desiredLabels=NULL, bool decomposeStack=true) override
bool append
Append to output.
FileName fnOut
Name of the output text file.
Name of an image (std::string)

◆ show()

void ProgCompareClass::show ( )

Show.

Definition at line 51 of file classify_compare_classes.cpp.

52 {
53  if (!verbose)
54  return;
55  std::cout
56  << "Input1: " << fnClass1 << std::endl
57  << "Input2: " << fnClass2 << std::endl
58  << "Output: " << fnOut << std::endl;
59 }
FileName fnClass1
Name of the two classification metadatas.
int verbose
Verbosity level.
FileName fnOut
Name of the output text file.

Member Data Documentation

◆ append

bool ProgCompareClass::append

Append to output.

Definition at line 45 of file classify_compare_classes.h.

◆ fnClass1

FileName ProgCompareClass::fnClass1

Name of the two classification metadatas.

Definition at line 41 of file classify_compare_classes.h.

◆ fnClass2

FileName ProgCompareClass::fnClass2

Definition at line 41 of file classify_compare_classes.h.

◆ fnOut

FileName ProgCompareClass::fnOut

Name of the output text file.

Definition at line 43 of file classify_compare_classes.h.


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