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

#include <image_resize.h>

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

Public Member Functions

 ProgImageResize ()
 
 ~ProgImageResize ()
 
- 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 ()
 

Protected Member Functions

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

ScaleType scale_type
 
int splineDegree
 
int dim
 
int pyramid_level
 
int fourier_threads
 
bool isVol
 
bool temporaryOutput
 
Matrix1D< double > resizeFactor
 
ImageGeneric img
 
ImageGeneric imgOut
 
- 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 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 40 of file image_resize.h.

Constructor & Destructor Documentation

◆ ProgImageResize()

ProgImageResize::ProgImageResize ( )

Constructor and destructor, just to avoid vtable undefined references errors

Definition at line 30 of file image_resize.cpp.

31 {}

◆ ~ProgImageResize()

ProgImageResize::~ProgImageResize ( )

Definition at line 33 of file image_resize.cpp.

34 {}

Member Function Documentation

◆ defineParams()

void ProgImageResize::defineParams ( )
protectedvirtual

Function in which the param of each Program are defined.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageResize >.

Definition at line 36 of file image_resize.cpp.

37 {
39  save_metadata_stack = true;
40  keep_input_columns = true;
41  allow_apply_geo = true;
42  temporaryOutput = false;
44  //usage
45  addUsageLine("Resize image or volume dimensions.");
46  addUsageLine("+You can select different ways to resize your image/volumes.");
47  //keywords
48  addKeywords("transform, dimension, pyramid, fourier, scale");
49  //examples
50  addExampleLine("Resize a group of images to half size", false);
51  addExampleLine("xmipp_image_resize -i images.xmd --factor 0.5 --oroot halvedOriginal");
52  addExampleLine("For pyramid resizing(increase volume size 4 times):", false);
53  addExampleLine("xmipp_image_resize -i input/bacteriorhodopsin.vol --pyramid 2 -o bdr_x4.vol");
54  addExampleLine("Resize from 128 to 64 using Fourier", false);
55  addExampleLine("xmipp_image_resize -i images.xmd --fourier 64 --oroot halvedFourierDim");
56  //params
57  addParamsLine("--factor <n=0.5> : Resize a factor of dimensions, 0.5 halves and 2 doubles (uses splines or linear interpolation).");
58  addParamsLine(" alias -n;");
59  addParamsLine("or --dim <x> <y=x> <z=x> : New x,y and z dimensions (uses splines / linear interpolation or nearest neighbour method).");
60  addParamsLine(" alias -d;");
61  addParamsLine("or --fourier <x> <y=x> <z=x> <thr=1> : Use padding/windowing in Fourier Space to resize. thr=number of threads");
62  addParamsLine(" alias -f;");
63  addParamsLine("or --pyramid <levels=1> : Use positive value to expand and negative to reduce");
64  addParamsLine(" alias -p;");
65  addParamsLine(" [--interp <interpolation_type=spline>] : Interpolation type to be used. ");
66  addParamsLine(" where <interpolation_type>");
67  addParamsLine(" spline : Use spline interpolation");
68  addParamsLine(" linear : Use bilinear/trilinear interpolation");
69  addParamsLine(" nearest : Use nearest neighbour to set new value");
70 }
void addKeywords(const char *keywords)
void addExampleLine(const char *example, bool verbatim=true)
bool save_metadata_stack
Save the associated output metadata when output file is a stack.
bool keep_input_columns
Keep input metadata columns.
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 ProgImageResize::postProcess ( )
protectedvirtual

Reimplemented from XmippMetadataProgram.

Definition at line 236 of file image_resize.cpp.

237 {
238  if (temporaryOutput)
239  std::rename(fn_out.c_str(),fn_in.c_str());
240 }
FileName fn_in
Filenames of input and output Metadata.

◆ preProcess()

void ProgImageResize::preProcess ( )
protectedvirtual

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageResize >.

Definition at line 88 of file image_resize.cpp.

89 {
90  double factor=1.0;
91  double oxdim = xdimOut;
92  auto oydim = (double)ydimOut;
93  auto ozdim = (double)zdimOut;
94 
95  //If zdimOut greater than 1, is a volume and should apply transform
96  dim = (isVol = (zdimOut > 1)) ? 3 : 2;
97 
100 
101  if (fn_out.empty() && oroot.empty())
102  {
103  fn_out=fn_in+"_tmp";
105  temporaryOutput=true;
107  }
108 
109  if (checkParam("--factor") || checkParam("--dim"))
110  {
111  //Calculate scale factor from images sizes and given dimensions
112  //this approach assumes that all images have equal size
113  if (checkParam("--dim"))
114  {
115  xdimOut = getIntParam("--dim", 0);
116  ydimOut = STR_EQUAL(getParam("--dim", 1), "x") ? xdimOut : getIntParam("--dim", 1);
117  XX(resizeFactor) = (double)xdimOut / oxdim;
118  YY(resizeFactor) = (double)ydimOut / oydim;
119  }
120  else
121  {
122  factor = getDoubleParam("--factor");
123  if (factor <= 0)
124  REPORT_ERROR(ERR_VALUE_INCORRECT,"Resize factor must be a positive number");
125  xdimOut = (int) (xdimOut * factor);
126  ydimOut = (int) (ydimOut * factor);
127  resizeFactor.initConstant(factor);
128  }
129 
130  //if scale factor is large splines s not the way to go, print a warning
131  if( fabs(1.0-XX(resizeFactor)) > 0.1 )
132  {
133  reportWarning("Do not apply large scale factor using B-splines "
134  "choose fourier option.");
135  }
136 
137  if (isVol)
138  {
139  if (checkParam("--dim"))
140  {
141  zdimOut = STR_EQUAL(getParam("--dim", 2), "x")
142  ? xdimOut : getIntParam("--dim", 2);
143  ZZ(resizeFactor) = (double)zdimOut / ozdim;
144  }
145  else
146  zdimOut = (int) (zdimOut * factor);
147  }
149  }
150  else if (checkParam("--fourier"))
151  {
152  // if (isVol)
153  // REPORT_ERROR(ERR_PARAM_INCORRECT, "The 'fourier' scaling type is only valid for images");
154  auto oxdim2 = xdimOut;
155  auto oydim2 = ydimOut;
156  auto ozdim2 = zdimOut;
158 
159  xdimOut = getIntParam("--fourier", 0);
160  ydimOut = STR_EQUAL(getParam("--fourier", 1), "x") ? xdimOut : getIntParam("--fourier", 1);
161  if (isVol)
162  zdimOut = STR_EQUAL(getParam("--fourier", 2), "x") ? xdimOut : getIntParam("--fourier", 2);
163  else
164  zdimOut=1;
165  fourier_threads = getIntParam("--fourier", 3);
166  XX(resizeFactor) = (double)xdimOut / oxdim2;
167  YY(resizeFactor) = (double)ydimOut / oydim2;
168  if (isVol)
169  ZZ(resizeFactor) = (double)zdimOut / ozdim2;
170  //Do not think this is true
171  // if (oxdim < xdimOut || oydim < ydimOut)
172  // REPORT_ERROR(ERR_PARAM_INCORRECT, "The 'fourier' scaling type can only be used for reducing size");
173  }
174  else if (checkParam("--pyramid"))
175  {
177  pyramid_level = getIntParam("--pyramid", 0);
178  factor = (double)(pow(2.0, pyramid_level));
179  xdimOut = (size_t)(xdimOut*factor);
180  ydimOut = (size_t)(ydimOut*factor);
181  if (isVol)
182  zdimOut = (size_t)(zdimOut*factor);
183  if (pyramid_level < 0)
184  {
185  pyramid_level *= -1; //change sign, negative means reduce operation
187  }
188  resizeFactor.initConstant(factor);
189  }
190 }
double getDoubleParam(const char *param, int arg=0)
void reportWarning(const String &what)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
FileName addExtension(const String &ext) const
ScaleType scale_type
Definition: image_resize.h:48
String getExtension() const
FileName fn_in
Filenames of input and output Metadata.
const char * getParam(const char *param, int arg=0)
#define XX(v)
Definition: matrix1d.h:85
#define STR_EQUAL(str1, str2)
Definition: xmipp_strings.h:42
#define YY(v)
Definition: matrix1d.h:93
Matrix1D< double > resizeFactor
Definition: image_resize.h:57
void resizeNoCopy(int Xdim)
Definition: matrix1d.h:458
bool checkParam(const char *param)
int getIntParam(const char *param, int arg=0)
Incorrect value received.
Definition: xmipp_error.h:195
void initConstant(T val)
Definition: matrix1d.cpp:83
#define ZZ(v)
Definition: matrix1d.h:101

◆ processImage()

void ProgImageResize::processImage ( const FileName fnImg,
const FileName fnImgOut,
const MDRow rowIn,
MDRow rowOut 
)
protectedvirtual

Implements XmippMetadataProgram.

Definition at line 195 of file image_resize.cpp.

196 {
197  double aux;
198  if (apply_geo)
199  {
202  if (isVol)
204  }
205  else
206  rowOut.resetGeo(false);
207 
208  img.read(fnImg);
209  img().setXmippOrigin();
211 
212  switch (scale_type)
213  {
214  case RESIZE_FACTOR:
215  //selfScaleToSize(splineDegree, img(), xdimOut, ydimOut, zdimOut);
217  break;
220  //selfPyramidExpand(splineDegree, img(), pyramid_level);
221  break;
224  //selfPyramidReduce(splineDegree, img(), pyramid_level);
225  break;
226  case RESIZE_FOURIER:
228  img.write(fnImgOut);
229  return;
230  case RESIZE_NONE:
231  break;
232  }
233  imgOut.write(fnImgOut);
234 }
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)
void pyramidReduce(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int levels)
Shift for the image in the X axis (double)
ScaleType scale_type
Definition: image_resize.h:48
ImageGeneric imgOut
Definition: image_resize.h:59
DataType getDatatype() const
#define XX(v)
Definition: matrix1d.h:85
void selfScaleToSizeFourier(int Zdim, int Ydim, int Xdim, MultidimArray< double > &mda, int nThreads)
Definition: xmipp_fftw.cpp:723
void pyramidExpand(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int levels)
virtual void resetGeo(bool addLabels=true)
void scaleToSize(int SplineDegree, MultidimArrayGeneric &V2, const MultidimArrayGeneric &V1, int Xdim, int Ydim, int Zdim)
#define YY(v)
Definition: matrix1d.h:93
void setDatatype(DataType _datatype)
Matrix1D< double > resizeFactor
Definition: image_resize.h:57
Shift for the image in the Z axis (double)
ImageGeneric img
Definition: image_resize.h:58
Shift for the image in the Y axis (double)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
#define ZZ(v)
Definition: matrix1d.h:101
#define SCALE_SHIFT(shiftLabel, resizeFactor)

◆ readParams()

void ProgImageResize::readParams ( )
protectedvirtual

Function in which each program will read parameters that it need. If some error occurs the usage will be printed out.

Reimplemented from XmippMetadataProgram.

Reimplemented in BasicMpiMetadataProgram< ProgImageResize >.

Definition at line 72 of file image_resize.cpp.

73 {
75  String degree = getParam("--interp");
76 
77  if (degree == "spline")
79  else if (degree == "linear")
81  else if (degree == "nearest")
83 
85 }
ScaleType scale_type
Definition: image_resize.h:48
const char * getParam(const char *param, int arg=0)
std::string String
Definition: xmipp_strings.h:34

Member Data Documentation

◆ dim

int ProgImageResize::dim
protected

Definition at line 51 of file image_resize.h.

◆ fourier_threads

int ProgImageResize::fourier_threads
protected

Definition at line 53 of file image_resize.h.

◆ img

ImageGeneric ProgImageResize::img
protected

Definition at line 58 of file image_resize.h.

◆ imgOut

ImageGeneric ProgImageResize::imgOut
protected

Definition at line 59 of file image_resize.h.

◆ isVol

bool ProgImageResize::isVol
protected

Definition at line 54 of file image_resize.h.

◆ pyramid_level

int ProgImageResize::pyramid_level
protected

Definition at line 52 of file image_resize.h.

◆ resizeFactor

Matrix1D<double> ProgImageResize::resizeFactor
protected

Definition at line 57 of file image_resize.h.

◆ scale_type

ScaleType ProgImageResize::scale_type
protected

Definition at line 48 of file image_resize.h.

◆ splineDegree

int ProgImageResize::splineDegree
protected

Definition at line 50 of file image_resize.h.

◆ temporaryOutput

bool ProgImageResize::temporaryOutput
protected

Definition at line 55 of file image_resize.h.


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