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

#include <transform_adjust_image_grey_levels.h>

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

Public Member Functions

 ProgTransformImageGreyLevels ()
 Empty constructor. More...
 
 ~ProgTransformImageGreyLevels ()
 Destructor. More...
 
void readParams ()
 Read argument from command line. More...
 
void show ()
 Show. More...
 
void defineParams ()
 Define parameters. More...
 
void preProcess ()
 
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

FileName fnVol
 
double maxResol
 
double maxA
 
double maxB
 
double Ts
 
int Rmax
 
int pad
 
MultidimArray< int > mask2D
 
double iMask2Dsum
 
FourierProjectorprojector
 
size_t Xdim
 
Image< double > I
 
Image< double > Ifiltered
 
Projection P
 
FourierFilter filter
 
double Istddev
 
- 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 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

Transform image gray value Parameters.

Definition at line 38 of file transform_adjust_image_grey_levels.h.

Constructor & Destructor Documentation

◆ ProgTransformImageGreyLevels()

ProgTransformImageGreyLevels::ProgTransformImageGreyLevels ( )

Empty constructor.

Definition at line 30 of file transform_adjust_image_grey_levels.cpp.

31 {
32  produces_a_metadata = true;
34  projector = nullptr;
35 }
bool each_image_produces_an_output
Indicate that an output is produced for each image in the input.
bool produces_a_metadata
Indicate that the unique final output file is a Metadata.

◆ ~ProgTransformImageGreyLevels()

ProgTransformImageGreyLevels::~ProgTransformImageGreyLevels ( )

Destructor.

Definition at line 37 of file transform_adjust_image_grey_levels.cpp.

38 {
39  delete projector;
40 }

Member Function Documentation

◆ defineParams()

void ProgTransformImageGreyLevels::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippMetadataProgram.

Definition at line 73 of file transform_adjust_image_grey_levels.cpp.

74 {
75  addUsageLine("Make a continuous angular assignment");
76  defaultComments["-i"].clear();
77  defaultComments["-i"].addComment("Metadata with images and alignment");
78  defaultComments["-o"].clear();
79  defaultComments["-o"].addComment("Stack of images prepared for 3D reconstruction");
81  addParamsLine(" --ref <volume> : Reference volume");
82  addParamsLine(" [--max_resolution <f=4>] : Maximum resolution (A)");
83  addParamsLine(" [--max_gray_scale <a=0.05>] : Maximum gray scale change");
84  addParamsLine(" [--max_gray_shift <b=0.05>] : Maximum gray shift change as a factor of the image standard deviation");
85  addParamsLine(" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
86  addParamsLine(" [--Rmax <R=-1>] : Maximum radius (px). -1=Half of volume size");
87  addParamsLine(" [--padding <p=2>] : Padding factor");
88 }
void addUsageLine(const char *line, bool verbatim=false)
void addParamsLine(const String &line)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83

◆ preProcess()

void ProgTransformImageGreyLevels::preProcess ( )
virtual

Produce side info. An exception is thrown if any of the files is not found

Reimplemented from XmippMetadataProgram.

Definition at line 91 of file transform_adjust_image_grey_levels.cpp.

92 {
93  // Read the reference volume
94  Image<double> V;
95  V.read(fnVol);
96  V().setXmippOrigin();
97  Xdim=XSIZE(V());
98 
99  // Construct mask
100  if (Rmax<0)
101  Rmax=Xdim/2;
102  Mask mask;
103  mask.type = BINARY_CIRCULAR_MASK;
104  mask.mode = INNER_MASK;
105  mask.R1 = Rmax;
106  mask.generate_mask(Xdim,Xdim);
107  mask2D=mask.get_binary_mask();
108  iMask2Dsum=1.0/mask2D.sum();
109 
110  // Construct projector
112 
113  // Low pass filter
116  filter.raised_w=0.02;
117 }
Definition: mask.h:360
double R1
Definition: mask.h:413
#define XSIZE(v)
int type
Definition: mask.h:402
void generate_mask(bool apply_geo=false)
Definition: mask.cpp:1577
#define BINARY_CIRCULAR_MASK
Definition: mask.h:365
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
const MultidimArray< int > & get_binary_mask() const
Definition: mask.h:707
double sum() const
#define LOWPASS
int mode
Definition: mask.h:407
constexpr int INNER_MASK
Definition: mask.h:47

◆ processImage()

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

Predict angles and shift. At the input the pose parameters must have an initial guess of the parameters. At the output they have the estimated pose.

Implements XmippMetadataProgram.

Definition at line 154 of file transform_adjust_image_grey_levels.cpp.

155 {
156  rowOut=rowIn;
157 
158  // Read input image and initial parameters
159  double rot, tilt, psi;
160  rowIn.getValue(MDL_ANGLE_ROT,rot);
161  rowIn.getValue(MDL_ANGLE_TILT,tilt);
162  rowIn.getValue(MDL_ANGLE_PSI,psi);
163 
164  double olda=1.0, oldb=0.0;
166  rowIn.getValue(MDL_CONTINUOUS_GRAY_A,olda);
167  rowIn.getValue(MDL_CONTINUOUS_GRAY_B,oldb);
168  }
169 
170  I.read(fnImg);
171  I().setXmippOrigin();
172  Istddev=I().computeStddev();
173 
174  Ifiltered()=I();
176 
177  projectVolume(*projector, P, (int)XSIZE(I()), (int)XSIZE(I()), rot, tilt, psi);
178 
179 #ifdef DEBUG
180  Image<double> save;
181  save()=P();
182  std::cout << "P: "; P().printStats(); std::cout << std::endl;
183  save.write("PPPprojection.xmp");
184  save()=I();
185  std::cout << "I: "; I().printStats(); std::cout << std::endl;
186  save.write("PPPexperimental.xmp");
187  save()=P()-I();
188  std::cout << "P-I init: "; save().printStats(); std::cout << std::endl;
189  save.write("PPPdiffInit.xmp");
190 #endif
191 
192  Matrix1D<double> pAB(2), steps(2), pBA(2), p(2);
193  steps.initConstant(1);
194 
195  // Optimize
196  double costAB=-1, costBA=-1;
197  int iter;
198  try
199  {
200  costAB=1e38;
201  pAB(0)=olda; // a in I'=a*I+b
202  pAB(1)=oldb; // b in I'=a*I+b
203  powellOptimizer(pAB, 1, 2, &transformImageGrayCostAB, this, 0.01, costAB, iter, steps, verbose>=2);
204  if (costAB>1e30)
205  {
206  rowOut.setValue(MDL_ENABLED,-1);
207  pAB.initZeros();
208  pAB(0)=1; // a in I'=a*I+b
209  pAB(1)=0; // b in I'=a*I+b
210  }
211 
212  costBA=1e38;
213  pBA(0)=oldb; // a in I'=a*I+b
214  pBA(1)=olda; // b in I'=a*I+b
215  powellOptimizer(pBA, 1, 2, &transformImageGrayCostBA, this, 0.01, costBA, iter, steps, verbose>=2);
216  if (costBA>1e30)
217  {
218  rowOut.setValue(MDL_ENABLED,-1);
219  pBA.initZeros();
220  pBA(0)=0; // a in I'=a*I+b
221  pBA(1)=1; // b in I'=a*I+b
222  }
223 
224  // Decide
225  if (costAB<costBA)
226  p=pAB;
227  else
228  {
229  p(0)=pBA(1);
230  p(1)=pBA(0);
231  }
232 
233  // Apply
234  MultidimArray<double> &mI=I();
235  double ia=1.0/p(0);
236  double b=p(1);
238  {
239  if (DIRECT_MULTIDIM_ELEM(mask2D,n) || true)
241  else
242  DIRECT_MULTIDIM_ELEM(mI,n)=0.0;
243  }
244  rowOut.setValue(MDL_IMAGE,fnImgOut);
245  I.write(fnImgOut);
246  }
247  catch (XmippError XE)
248  {
249  std::cerr << XE.what() << std::endl;
250  std::cerr << "Warning: Cannot refine " << fnImg << std::endl;
251  rowOut.setValue(MDL_ENABLED,-1);
252  }
253  rowOut.setValue(MDL_CONTINUOUS_GRAY_A,p(0));
254  rowOut.setValue(MDL_CONTINUOUS_GRAY_B,p(1));
255 
256 #ifdef DEBUG
257  save()=I();
258  save.write("PPPexperimentalCorrected.xmp");
259  std::cout << "I corrected: "; I().printStats(); std::cout << std::endl;
260  save()=P()-I();
261  std::cout << "P-I final: "; save().printStats(); std::cout << std::endl;
262  save.write("PPPdiff.xmp");
263  std::cout << fnImgOut << " rewritten\n";
264  std::cout << "Press any key" << std::endl;
265  char c; std::cin >> c;
266 #endif
267 }
Rotation angle of an image (double,degrees)
double transformImageGrayCostBA(double *x, void *_prm)
doublereal * c
Tilting angle of an image (double,degrees)
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)
Special label to be used when gathering MDs in MpiMetadataPrograms.
void powellOptimizer(Matrix1D< double > &p, int i0, int n, double(*f)(double *x, void *), void *prm, double ftol, double &fret, int &iter, const Matrix1D< double > &steps, bool show)
glob_prnt iter
Is this image enabled? (int [-1 or 1])
doublereal * b
T & getValue(MDLabel label)
a value of continuous assignment
#define XSIZE(v)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void projectVolume(FourierProjector &projector, Projection &P, int Ydim, int Xdim, double rot, double tilt, double psi, const MultidimArray< double > *ctf)
int verbose
Verbosity level.
double steps
void setValue(MDLabel label, const T &d, bool addLabel=true)
b value of continuous assignment
virtual bool containsLabel(MDLabel label) const =0
double psi(const double x)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
double transformImageGrayCostAB(double *x, void *_prm)
int * n
Name of an image (std::string)
void applyMaskSpace(MultidimArray< double > &v)

◆ readParams()

void ProgTransformImageGreyLevels::readParams ( )
virtual

Read argument from command line.

Reimplemented from XmippMetadataProgram.

Definition at line 43 of file transform_adjust_image_grey_levels.cpp.

44 {
46  fnVol = getParam("--ref");
47  maxResol = getDoubleParam("--max_resolution");
48  maxA = getDoubleParam("--max_gray_scale");
49  maxB = getDoubleParam("--max_gray_shift");
50  Ts = getDoubleParam("--sampling");
51  Rmax = getIntParam("--Rmax");
52  pad = getIntParam("--padding");
53 }
double getDoubleParam(const char *param, int arg=0)
const char * getParam(const char *param, int arg=0)
int getIntParam(const char *param, int arg=0)

◆ show()

void ProgTransformImageGreyLevels::show ( )

Show.

Definition at line 56 of file transform_adjust_image_grey_levels.cpp.

57 {
58  if (!verbose)
59  return;
61  std::cout
62  << "Reference volume: " << fnVol << std::endl
63  << "Max. Resolution: " << maxResol << std::endl
64  << "Max. Gray Scale: " << maxA << std::endl
65  << "Max. Gray Shift: " << maxB << std::endl
66  << "Sampling: " << Ts << std::endl
67  << "Max. Radius: " << Rmax << std::endl
68  << "Padding factor: " << pad << std::endl
69  ;
70 }
int verbose
Verbosity level.
void show() const override

Member Data Documentation

◆ filter

FourierFilter ProgTransformImageGreyLevels::filter

Definition at line 69 of file transform_adjust_image_grey_levels.h.

◆ fnVol

FileName ProgTransformImageGreyLevels::fnVol

Filename of the reference volume

Definition at line 42 of file transform_adjust_image_grey_levels.h.

◆ I

Image<double> ProgTransformImageGreyLevels::I

Definition at line 65 of file transform_adjust_image_grey_levels.h.

◆ Ifiltered

Image<double> ProgTransformImageGreyLevels::Ifiltered

Definition at line 65 of file transform_adjust_image_grey_levels.h.

◆ iMask2Dsum

double ProgTransformImageGreyLevels::iMask2Dsum

Definition at line 59 of file transform_adjust_image_grey_levels.h.

◆ Istddev

double ProgTransformImageGreyLevels::Istddev

Definition at line 71 of file transform_adjust_image_grey_levels.h.

◆ mask2D

MultidimArray<int> ProgTransformImageGreyLevels::mask2D

Definition at line 57 of file transform_adjust_image_grey_levels.h.

◆ maxA

double ProgTransformImageGreyLevels::maxA

Maximum gray scale change

Definition at line 46 of file transform_adjust_image_grey_levels.h.

◆ maxB

double ProgTransformImageGreyLevels::maxB

Maximum gray shift change

Definition at line 48 of file transform_adjust_image_grey_levels.h.

◆ maxResol

double ProgTransformImageGreyLevels::maxResol

Maximum frequency (A)

Definition at line 44 of file transform_adjust_image_grey_levels.h.

◆ P

Projection ProgTransformImageGreyLevels::P

Definition at line 67 of file transform_adjust_image_grey_levels.h.

◆ pad

int ProgTransformImageGreyLevels::pad

Padding factor

Definition at line 54 of file transform_adjust_image_grey_levels.h.

◆ projector

FourierProjector* ProgTransformImageGreyLevels::projector

Definition at line 61 of file transform_adjust_image_grey_levels.h.

◆ Rmax

int ProgTransformImageGreyLevels::Rmax

Maximum radius

Definition at line 52 of file transform_adjust_image_grey_levels.h.

◆ Ts

double ProgTransformImageGreyLevels::Ts

Sampling rate

Definition at line 50 of file transform_adjust_image_grey_levels.h.

◆ Xdim

size_t ProgTransformImageGreyLevels::Xdim

Definition at line 63 of file transform_adjust_image_grey_levels.h.


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