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

#include <program_image_residuals.h>

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

Public Member Functions

void defineParams ()
 
void readParams ()
 
void preProcess ()
 
void postProcess ()
 
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 normalizeDivergence
 
Matrix2D< double > R
 
Image< double > IR
 
size_t i
 
MultidimArray< double > resmean
 
MultidimArray< double > resvar
 
- 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 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

Apply some filter operation on images, or selfiles

Definition at line 34 of file program_image_residuals.h.

Member Function Documentation

◆ defineParams()

void ProgImageResiduals::defineParams ( )
virtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Definition at line 30 of file program_image_residuals.cpp.

31 {
33  produces_an_output = true;
34  addUsageLine("Analyze image residuals");
36  addParamsLine(" [--normalizeDivergence] : Normalize the divergence measure");
37  addExampleLine("xmipp_image_residuals -i residuals.stk -o autocorrelations.stk --save_metadata_stack autocorrelations.xmd");
38 }
bool produces_an_output
Indicate that a unique final output is produced.
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)

◆ postProcess()

void ProgImageResiduals::postProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Definition at line 126 of file program_image_residuals.cpp.

127 {
128  FileName fnMDout=fn_out.replaceExtension("xmd");
129  MetaDataVec mdR(fnMDout);
130 
131  // Ravg
132  Matrix2D<double> Ravg;
133  Ravg.initIdentity(MAT_XSIZE(R));
134  std::cerr << "Calculating covariance centroid ..." << std::endl;
135  init_progress_bar(10);
136  for (int i=0; i<10; i++)
137  {
138  progress_bar(i);
139  updateRavg(mdR,Ravg);
140  }
141  progress_bar(10);
142 
143  // Calculate the zscore of the mean and stddev
144  double mean, stddev;
145  resmean.computeAvgStdev(mean,stddev);
146  resmean-=mean;
147  resmean/=stddev;
148  resvar.computeAvgStdev(mean,stddev);
149  resvar-=mean;
150  resvar/=stddev;
151 
153  FileName fnR;
155  std::cerr << "Calculating covariance divergence ..." << std::endl;
156  init_progress_bar(mdR.size());
157  size_t n=0;
158  double minD=1e38;
159  for (size_t objId : mdR.ids())
160  {
161  mdR.getValue(MDL_IMAGE_COVARIANCE,fnR,objId);
162  IR.read(fnR);
163  IR().copy(R);
164 
165  double d=computeCovarianceMatrixDivergence(Ravg,R);
166  if (d<minD)
167  minD=d;
168  mdR.setValue(MDL_ZSCORE_RESMEAN,fabs(A1D_ELEM(resmean,n)),objId);
169  mdR.setValue(MDL_ZSCORE_RESVAR,fabs(A1D_ELEM(resvar,n)),objId);
170  mdR.setValue(MDL_ZSCORE_RESCOV,d,objId);
171  n++;
172  if (n%100==0)
173  progress_bar(n);
174  }
175  progress_bar(mdR.size());
176  if (normalizeDivergence) {
177  for (size_t objId : mdR.ids())
178  {
179  double d;
180  mdR.getValue(MDL_ZSCORE_RESCOV,d,objId);
181  mdR.setValue(MDL_ZSCORE_RESCOV,d/minD-1,objId);
182  }
183  }
184  mdR.write(fnMDout);
185 }
void init_progress_bar(long total)
double computeCovarianceMatrixDivergence(const Matrix2D< double > &C1, const Matrix2D< double > &C2)
Compute the divergence between two covariance matrices.
MultidimArray< double > resmean
FileName replaceExtension(const String &newExt) const
#define A1D_ELEM(v, i)
void computeAvgStdev(U &avg, U &stddev) const
MultidimArray< double > resvar
void updateRavg(MetaData &mdR, Matrix2D< double > &Ravg)
doublereal * d
void progress_bar(long rlen)
Z Score of the mean of the residuals (double)
Name of the covariance imagee associated to this image.
#define MAT_XSIZE(m)
Definition: matrix2d.h:120
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Z Score of the stddev of the residuals (double)
Z Score of the covariance matrix of the residuals (double)
void copy(const ImageBase &other)
int * n
void initIdentity()
Definition: matrix2d.h:673

◆ preProcess()

void ProgImageResiduals::preProcess ( )
virtual

Reimplemented from XmippMetadataProgram.

Definition at line 46 of file program_image_residuals.cpp.

47 {
48  i=0;
51 }
MultidimArray< double > resmean
size_t mdInSize
Number of input elements.
MultidimArray< double > resvar
void initZeros(const MultidimArray< T1 > &op)

◆ processImage()

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

Implements XmippMetadataProgram.

Definition at line 53 of file program_image_residuals.cpp.

54 {
55  rowOut=rowIn;
56 
57  Image<double> img;
59  img.read(fnImg);
60  else
61  {
62  FileName fnResidual;
63  rowIn.getValue(MDL_IMAGE_RESIDUAL,fnResidual);
64  img.read(fnResidual);
65  }
66  covarianceMatrix(img(), R);
67  IR()=R;
68  IR.write(fnImgOut);
69  rowOut.setValue(MDL_IMAGE_COVARIANCE,fnImgOut);
70 
71  img().computeAvgStdev(A1D_ELEM(resmean,i),A1D_ELEM(resvar,i));
72  i++;
73 }
MultidimArray< double > resmean
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 A1D_ELEM(v, i)
MultidimArray< double > resvar
T & getValue(MDLabel label)
Name of a residual image associated to this image.
Name of the covariance imagee associated to this image.
void setValue(MDLabel label, const T &d, bool addLabel=true)
virtual bool containsLabel(MDLabel label) const =0
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void covarianceMatrix(const MultidimArray< double > &I, Matrix2D< double > &C)
Definition: filters.cpp:1582

◆ readParams()

void ProgImageResiduals::readParams ( )
virtual

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 40 of file program_image_residuals.cpp.

41 {
43  normalizeDivergence=checkParam("--normalizeDivergence");
44 }
bool checkParam(const char *param)

Member Data Documentation

◆ i

size_t ProgImageResiduals::i

Definition at line 51 of file program_image_residuals.h.

◆ IR

Image<double> ProgImageResiduals::IR

Definition at line 48 of file program_image_residuals.h.

◆ normalizeDivergence

bool ProgImageResiduals::normalizeDivergence

Definition at line 44 of file program_image_residuals.h.

◆ R

Matrix2D<double> ProgImageResiduals::R

Definition at line 47 of file program_image_residuals.h.

◆ resmean

MultidimArray<double> ProgImageResiduals::resmean

Definition at line 52 of file program_image_residuals.h.

◆ resvar

MultidimArray<double> ProgImageResiduals::resvar

Definition at line 52 of file program_image_residuals.h.


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