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

Protected Member Functions

void defineParams ()
 
void readParams ()
 
void show ()
 
void roundShifts (MDRow &row)
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
void finishProcessing ()
 
- 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 writeOutput ()
 
virtual void showProgress ()
 
virtual void defineLabelParam ()
 
- Protected Member Functions inherited from XmippProgram
void defineCommons ()
 

Protected Attributes

HeaderOperation operation
 
bool round_shifts
 
MDRowVec row
 
ApplyGeoParams params
 
double sampling
 
- 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
 

Additional Inherited Members

- 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 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
 

Detailed Description

Definition at line 33 of file image_header.cpp.

Member Function Documentation

◆ defineParams()

void ProgHeader::defineParams ( )
inlineprotectedvirtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Definition at line 42 of file image_header.cpp.

43  {
44  produces_an_output = true;
45  get_image_info = false;
46 
48  addUsageLine("Operate with image files headers. By default in Xmipp, geometrical transformations");
49  addUsageLine("coming in images files headers are ignored. Instead this information is read from");
50  addUsageLine("the images metadata if exist. With this program geometrical transformations can be");
51  addUsageLine("extracted to a metadata or assigned to header, also allows print or reset image file headers.");
52  addParamsLine("[ --print <decompose=0>] : Print the geometrical transformations in image file headers.");
53  addParamsLine(" : if input is stack and decompose=1 print header of each individual image.");
54  addParamsLine(" alias -p;");
55  addParamsLine("or --extract : The output is a selfile with geometrical transformations read from image file headers.");
56  addParamsLine(" alias -e;");
57  addParamsLine(" requires -o;");
58  addParamsLine("or --assign : Write the geometrical transformations from selfile to the image file headers.");
59  addParamsLine(" alias -a;");
60  addParamsLine("or --reset : Reset the geometrical transformations in image file headers.");
61  addParamsLine(" alias -r;");
62  addParamsLine("or --tree : Print the tree scheme from file containers as hdf5 files.");
63  addParamsLine(" alias -t;");
64  addParamsLine("or --sampling_rate <Ts=-1> : Change the sampling rate (in Angstrom units) in the image file header.");
65  addParamsLine(" : If no value is passed then current value in header is print.");
66  addParamsLine(" alias -s;");
67  addParamsLine(" [--round_shifts] :Round shifts to integers");
68  addExampleLine("Print the header of the images in metadata: ", false);
69  addExampleLine("xmipp_image_header -i images.sel");
70  addExampleLine("Extract geometrical transformations from image file headers: ", false);
71  addExampleLine("xmipp_image_header -i smallStack.stk --extract -o header.doc");
72  addExampleLine("Assign the geometrical transformations from the metadata to header: ", false);
73  addExampleLine("xmipp_image_header -i header.doc --assign");
74  addSeeAlsoLine("transform_geometry");
75  addKeywords("header, geometric, transformation, print");
76  }
bool get_image_info
Get the input image file dimensions to further operations.
void addSeeAlsoLine(const char *seeAlso)
void addKeywords(const char *keywords)
bool produces_an_output
Indicate that a unique final output is produced.
void addExampleLine(const char *example, bool verbatim=true)
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)

◆ finishProcessing()

void ProgHeader::finishProcessing ( )
inlineprotectedvirtual

Reimplemented from XmippMetadataProgram.

Definition at line 232 of file image_header.cpp.

233  {
235  single_image = false;
237  }
bool single_image
Input is a single image.
HeaderOperation operation

◆ processImage()

void ProgHeader::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
inlineprotectedvirtual

Implements XmippMetadataProgram.

Definition at line 165 of file image_header.cpp.

166  {
167 
168  ImageGeneric img;
169 
170  switch (operation)
171  {
172  case HEADER_PRINT:
173  img.read(fnImg, _HEADER_ALL);
174  img.print();
175  break;
176  case HEADER_EXTRACT:
177  img.read(fnImg, _HEADER_ALL);
178  rowOut = img.getGeometry();
179  if (round_shifts)
180  roundShifts(rowOut);
181  rowOut.setValue(MDL_IMAGE, fnImgOut);
182  break;
183  case HEADER_ASSIGN:
184  rowOut = rowIn;
185  if (round_shifts)
186  roundShifts(rowOut);
187  img.readApplyGeo(fnImg, rowOut, params);
189  img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE);
190  break;
191  case HEADER_RESET:
192  img.read(fnImg, _HEADER_ALL);
193  img.initGeometry();
194  img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE);
195  break;
196  case HEADER_SAMPLINGRATE:
197  {
198  img.read(fnImg, _HEADER_ALL);
199  if (sampling < 0)
200  {
201  double samplingRead;
202  img.image->MDMainHeader.getValue(MDL_SAMPLINGRATE_X, samplingRead);
203  std::cout << samplingRead << std::endl;
204  }
205  else
206  {
210  img.write(fnImg, ALL_IMAGES, fnImg.isInStack(), WRITE_REPLACE);
211  std::cout << "New sampling rate (Angstrom) = " << sampling << std::endl;
212  }
213  }
214  break;
215  case HEADER_TREE:
216  {
217  XmippH5File H5File;
218  FileName filename = fnImg.removeAllPrefixes().removeFileFormat();
219 
220  if (H5File.isHdf5(filename.c_str()))
221  {
222  H5File.openFile(fnImg.removeAllPrefixes().removeFileFormat(), H5F_ACC_RDONLY);
223  H5File.showTree();
224  }
225  else
226  REPORT_ERROR(ERR_IMG_UNKNOWN, "Unknown file format to display its data structure.");
227  }
228  break;
229  }
230  }
void setDataMode(DataMode mode)
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)
sampling rate in A/pixel (double)
MDRow & getGeometry(const size_t n=0)
void showTree(std::ostream &out=std::cout)
Definition: xmipp_hdf5.cpp:191
sampling rate in A/pixel (double)
sampling rate in A/pixel (double)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName removeFileFormat() const
void openFile(const H5std_string &name, unsigned int flags, const H5::FileAccPropList &access_plist=H5::FileAccPropList::DEFAULT)
Definition: xmipp_hdf5.cpp:112
void setValue(const MDObject &object) override
Unknown image type.
Definition: xmipp_error.h:130
ApplyGeoParams params
void initGeometry(const size_t n=0)
T & getValue(MDLabel label)
FileName removeAllPrefixes() const
bool round_shifts
void roundShifts(MDRow &row)
HeaderOperation operation
ImageBase * image
MDRowVec MDMainHeader
void setValue(MDLabel label, const T &d, bool addLabel=true)
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams &params=DefaultApplyGeoParams)
#define ALL_IMAGES
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
Name of an image (std::string)
bool isInStack() const
double sampling

◆ readParams()

void ProgHeader::readParams ( )
inlineprotectedvirtual

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 78 of file image_header.cpp.

79  {
80  if (checkParam("--extract"))
81  {
83  produces_a_metadata = true;
84  }
85  else if (checkParam("--assign"))
87  else if (checkParam("--reset"))
89  else if (checkParam("--sampling_rate"))
90  {
92  sampling = getDoubleParam("--sampling_rate");
93  allow_time_bar = false;
94  }
95  else if (checkParam("--tree"))
96  {
98  decompose_stacks = false;
99  }
100  else
101  {
103  allow_time_bar = false;
104  decompose_stacks = getIntParam("--print") == 1;
105  }
107  round_shifts = checkParam("--round_shifts");
108  if (operation != HEADER_EXTRACT && checkParam("-o"))
109  REPORT_ERROR(ERR_PARAM_INCORRECT, "Argument -o is not valid for this operation");
111  }
Parameter incorrect.
Definition: xmipp_error.h:181
double getDoubleParam(const char *param, int arg=0)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
ApplyGeoParams params
bool round_shifts
HeaderOperation operation
bool allow_time_bar
Show process time bar.
bool decompose_stacks
Input Metadata will treat a stack file as a set of images instead of a unique file.
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.
double sampling

◆ roundShifts()

void ProgHeader::roundShifts ( MDRow row)
inlineprotected

Definition at line 150 of file image_header.cpp.

151  {
152  double aux = 0.;
153  if (row.getValue(MDL_SHIFT_X, aux))
154  {
155  aux = (double)ROUND(aux);
156  row.setValue(MDL_SHIFT_X, aux);
157  }
158  if (row.getValue(MDL_SHIFT_Y, aux))
159  {
160  aux = (double)ROUND(aux);
161  row.setValue(MDL_SHIFT_Y, aux);
162  }
163  }
Shift for the image in the X axis (double)
T & getValue(MDLabel label)
#define ROUND(x)
Definition: xmipp_macros.h:210
void setValue(MDLabel label, const T &d, bool addLabel=true)
Shift for the image in the Y axis (double)

◆ show()

void ProgHeader::show ( )
inlineprotected

Definition at line 113 of file image_header.cpp.

114  {
115  if (verbose == 0)
116  return;
117 
118  String msg;
119  switch (operation)
120  {
121  case HEADER_PRINT:
122  msg = "Printing headers...";
123  break;
124  case HEADER_EXTRACT:
125  msg = "Extracting image(s) geometrical transformations from header to metadata...";
126  break;
127  case HEADER_ASSIGN:
128  msg = "Assigning image(s) geometrical transformations from metadata to header...";
129  break;
130  case HEADER_RESET:
131  msg = "Reseting geometrical transformations from headers...";
132  break;
133  case HEADER_SAMPLINGRATE:
134  if (sampling > 0)
135  msg = "Setting sampling rate into headers...";
136  else
137  msg = "Showing sampling rate from headers...";
138  break;
139  case HEADER_TREE:
140  msg = "Printing tree structure...";
141  break;
142  }
143  std::cout << msg << std::endl << "Input: " << fn_in << std::endl;
144 
145  if (checkParam("-o"))
146  std::cout << "Output: " << fn_out << std::endl;
147 
148  }
FileName fn_in
Filenames of input and output Metadata.
HeaderOperation operation
int verbose
Verbosity level.
std::string String
Definition: xmipp_strings.h:34
bool checkParam(const char *param)
double sampling

Member Data Documentation

◆ operation

HeaderOperation ProgHeader::operation
protected

Definition at line 36 of file image_header.cpp.

◆ params

ApplyGeoParams ProgHeader::params
protected

Definition at line 39 of file image_header.cpp.

◆ round_shifts

bool ProgHeader::round_shifts
protected

Definition at line 37 of file image_header.cpp.

◆ row

MDRowVec ProgHeader::row
protected

Definition at line 38 of file image_header.cpp.

◆ sampling

double ProgHeader::sampling
protected

Definition at line 40 of file image_header.cpp.


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