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

#include <ctf_enhance_psd.h>

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

Public Member Functions

void readParams ()
 
void defineParams ()
 
void show ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
void applyFilter (MultidimArray< double > &PSD)
 
void applySPHT (MultidimArray< double > &PSD)
 
- 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

String method
 Method. More...
 
double filter_w1
 Bandpass filter low frequency (in Fourier space, max 0.5) More...
 
double filter_w2
 Bandpass filter high frequency (in Fourier space, max 0.5) More...
 
double decay_width
 Decay width (raised cosine) More...
 
int N0
 Minimum number of fringes. More...
 
int NF
 Maximum number of fringes. More...
 
double mask_w1
 Lower frequency for the mask (in Fourier space, max 0.5) More...
 
double mask_w2
 Higher frequency for the mask (in Fourier space, max 0.5) More...
 
- 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 preProcess ()
 
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

Parameter class for the project program

Definition at line 38 of file ctf_enhance_psd.h.

Member Function Documentation

◆ applyFilter()

void ProgCTFEnhancePSD::applyFilter ( MultidimArray< double > &  PSD)

Apply filter method to a single PSD. The steps are basically: outlier removal, band pass filtration, masking and normalization.

Definition at line 110 of file ctf_enhance_psd.cpp.

111 {
112  // Take the logarithm
114  A2D_ELEM(PSD, i, j) = log10(1 + A2D_ELEM(PSD, i, j));
115 
116  // Remove single outliers
117  CenterFFT(PSD, true);
119  medianFilter3x3(PSD, aux);
120  PSD = aux;
121 
122  // Reject other outliers
123  reject_outliers(PSD, 2);
124 
125  // Band pass filter
126  FourierFilter Filter;
127  Filter.FilterShape = RAISED_COSINE;
128  Filter.FilterBand = BANDPASS;
129  Filter.w1 = filter_w1;
130  Filter.w2 = filter_w2;
131  Filter.raised_w = decay_width;
132  PSD.setXmippOrigin();
133  Filter.generateMask(PSD);
134  Filter.applyMaskSpace(PSD);
135  STARTINGX(PSD) = STARTINGY(PSD) = 0;
136  CenterFFT(PSD, false);
137 
138  // Mask the input PSD
139  MultidimArray<int> mask;
140  mask.resize(PSD);
141  Matrix1D<double> freq(2); // Frequencies for Fourier plane
142  double limit0_2 = mask_w1;
143  limit0_2 = limit0_2 * limit0_2;
144  double limitF_2 = mask_w2;
145  limitF_2 = limitF_2 * limitF_2;
146  for (int i = STARTINGY(PSD); i <= FINISHINGY(PSD); ++i)
147  {
148  FFT_IDX2DIGFREQ(i, YSIZE(PSD), YY(freq));
149  double freqy2 = YY(freq) * YY(freq);
150  for (int j = STARTINGX(PSD); j <= FINISHINGX(PSD); ++j)
151  {
152  FFT_IDX2DIGFREQ(j, XSIZE(PSD), XX(freq));
153  double freq2 = XX(freq) * XX(freq) + freqy2;
154  if (freq2 < limit0_2 || freq2 > limitF_2)
155  A2D_ELEM(PSD, i, j) = 0;
156  else
157  A2D_ELEM(mask, i, j) = 1;
158  }
159  }
160 
161  //Compute the mean and the standard deviation under a tighter mask
162  //close to the border and normalize the PSD image
163  MultidimArray<int> tighterMask;
164  tighterMask.resizeNoCopy(PSD);
165  limit0_2 = mask_w2 * 0.9;
166  limit0_2 = limit0_2 * limit0_2;
167  limitF_2 = mask_w2;
168  limitF_2 = limitF_2 * limitF_2;
169  for (int i = STARTINGY(PSD); i <= FINISHINGY(PSD); ++i)
170  {
171  FFT_IDX2DIGFREQ(i, YSIZE(PSD), YY(freq));
172  double freqy2 = YY(freq) * YY(freq);
173  for (int j = STARTINGX(PSD); j <= FINISHINGX(PSD); ++j)
174  {
175  FFT_IDX2DIGFREQ(j, XSIZE(PSD), XX(freq));
176  double freq2 = XX(freq) * XX(freq) + freqy2;
177  A2D_ELEM(tighterMask, i, j) = freq2 > limit0_2 && freq2 < limitF_2;
178  }
179  }
180 
181  double avg, stddev;
182  PSD.computeAvgStdev_within_binary_mask(tighterMask, avg, stddev);
183  double istddev = 1.0 / stddev;
185  if (A2D_ELEM(mask, i, j))
186  A2D_ELEM(PSD, i, j) = (A2D_ELEM(PSD, i, j) - avg) * istddev;
187 
188  // Mask again
189  limit0_2 = mask_w1;
190  limit0_2 = limit0_2 * limit0_2;
191  limitF_2 = mask_w2 * 0.9;
192  limitF_2 = limitF_2 * limitF_2;
193  for (int i = STARTINGY(PSD); i <= FINISHINGY(PSD); ++i)
194  {
195  FFT_IDX2DIGFREQ(i, YSIZE(PSD), YY(freq));
196  double freqy2 = YY(freq) * YY(freq);
197  for (int j = STARTINGX(PSD); j <= FINISHINGX(PSD); ++j)
198  {
199  FFT_IDX2DIGFREQ(j, XSIZE(PSD), XX(freq));
200  double freq2 = XX(freq) * XX(freq) + freqy2;
201  if (freq2 < limit0_2 || freq2 > limitF_2)
202  A2D_ELEM(PSD, i, j) = 0;
203  }
204  }
205 
206  CenterFFT(PSD, true);
207 }
#define YSIZE(v)
#define A2D_ELEM(v, i, j)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
#define FINISHINGX(v)
void resizeNoCopy(const MultidimArray< T1 > &v)
#define BANDPASS
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
#define STARTINGX(v)
void computeAvgStdev_within_binary_mask(const MultidimArray< int > &mask, double &avg, double &stddev) const
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
#define STARTINGY(v)
void CenterFFT(MultidimArray< T > &v, bool forward)
Definition: xmipp_fft.h:291
#define XX(v)
Definition: matrix1d.h:85
void reject_outliers(T &v, double percentil_out=0.25)
Definition: histogram.h:605
#define XSIZE(v)
#define RAISED_COSINE
double decay_width
Decay width (raised cosine)
void log10(Image< double > &op)
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
#define j
#define YY(v)
Definition: matrix1d.h:93
#define FINISHINGY(v)
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
void medianFilter3x3(MultidimArray< T > &m, MultidimArray< T > &out)
Definition: filters.h:1088
void generateMask(MultidimArray< double > &v)
void applyMaskSpace(MultidimArray< double > &v)

◆ applySPHT()

void ProgCTFEnhancePSD::applySPHT ( MultidimArray< double > &  PSD)

Apply SPHT to a single PSD.

Definition at line 209 of file ctf_enhance_psd.cpp.

210 {
211  FourierTransformer transformer;
213  transformer.FourierTransform(PSD, PSDfourier, false);
214 
215  transformer.inverseFourierTransform();
216 }
void inverseFourierTransform()
Definition: xmipp_fftw.cpp:329
void FourierTransform(T &v, T1 &V, bool getCopy=true)
Definition: xmipp_fftw.h:166

◆ defineParams()

void ProgCTFEnhancePSD::defineParams ( )
virtual

Define parameters.

Reimplemented from XmippMetadataProgram.

Definition at line 60 of file ctf_enhance_psd.cpp.

61 {
63  defaultComments["-i"].clear();
64  defaultComments["-i"].addComment("Metadata with PSDs or a single PSD");
67  "Enhances the visibility of the Thon rings in a Power Spectrum Density (PSD).");
68  addSeeAlsoLine("ctf_estimate_from_micrograph");
69  addParamsLine("[--method <mth=filter>] : Choose enhancing method");
70  addParamsLine(" where <mth>");
71  addParamsLine(" filter <freq_low=0.05> <freq_high=0.2> <freq_decay=0.02>: Ad hoc filters. The algorithm is fully described at [[http://www.ncbi.nlm.nih.gov/pubmed/16987671][this article]]");
72  addParamsLine(" : The frequency limits define a raised-cosine bandpass filter, frequencies are normalized to 0.5");
73  addParamsLine(" spht <N0=1> <NF=10> : Spiral phase transform normalization.");
74  addParamsLine(" : N0 and NF define the minimum and maximum number of fringes in the CTF");
75  addParamsLine("==+ Output parameters");
76  addParamsLine(" [--dont_center] : By default, the output is centered");
77  addParamsLine(" [--dont_log] : Don't take log10 before working");
78  addParamsLine("==+ Output mask parameters");
79  addParamsLine(" [--m1 <freq_low=0.025>] : Low freq. for frequency mask, max 0.5");
80  addParamsLine(" [--m2 <freq_high=0.3>] : High freq. for frequency mask, max 0.5");
81  addExampleLine("xmipp_ctf_enhance_psd -i myPSD.psd -o myPSD_enhanced.psd");
82 }
void addSeeAlsoLine(const char *seeAlso)
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)
std::map< String, CommentList > defaultComments
Definition: xmipp_program.h:83

◆ processImage()

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

Process one image

Implements XmippMetadataProgram.

Definition at line 95 of file ctf_enhance_psd.cpp.

97 {
98  Image<double> PSD;
99  PSD.read(fnImg);
100  if (ZSIZE(PSD()) != 1)
101  REPORT_ERROR(ERR_MATRIX_DIM,"This program is not intended for volumes");
102  if (method=="filter")
103  applyFilter(PSD());
104  else
105  applySPHT(PSD());
106  PSD.write(fnImgOut);
107 }
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
String method
Method.
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)
Problem with matrix dimensions.
Definition: xmipp_error.h:150
#define ZSIZE(v)
void applyFilter(MultidimArray< double > &PSD)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void applySPHT(MultidimArray< double > &PSD)

◆ readParams()

void ProgCTFEnhancePSD::readParams ( )
virtual

Read from a command line.

Reimplemented from XmippMetadataProgram.

Definition at line 40 of file ctf_enhance_psd.cpp.

41 {
43  method = getParam("--method");
44  if (method == "filter")
45  {
46  filter_w1 = getDoubleParam("--method", 1);
47  filter_w2 = getDoubleParam("--method", 2);
48  decay_width = getDoubleParam("--method", 3);
49  }
50  else
51  {
52  N0 = getIntParam("--method", 1);
53  NF = getIntParam("--method", 2);
54  }
55  mask_w1 = getDoubleParam("--m1");
56  mask_w2 = getDoubleParam("--m2");
57 }
int N0
Minimum number of fringes.
double getDoubleParam(const char *param, int arg=0)
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
String method
Method.
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
const char * getParam(const char *param, int arg=0)
double decay_width
Decay width (raised cosine)
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)
int getIntParam(const char *param, int arg=0)
int NF
Maximum number of fringes.

◆ show()

void ProgCTFEnhancePSD::show ( )

Show parameters.

Definition at line 85 of file ctf_enhance_psd.cpp.

86 {
88  std::cout << "Filter w1: " << filter_w1 << std::endl << "Filter w2: "
89  << filter_w2 << std::endl << "Filter decay: " << decay_width
90  << std::endl << "Mask w1: " << mask_w1 << std::endl
91  << "Mask w2: " << mask_w2 << std::endl;
92 }
double filter_w2
Bandpass filter high frequency (in Fourier space, max 0.5)
double mask_w1
Lower frequency for the mask (in Fourier space, max 0.5)
double mask_w2
Higher frequency for the mask (in Fourier space, max 0.5)
double decay_width
Decay width (raised cosine)
void show() const override
double filter_w1
Bandpass filter low frequency (in Fourier space, max 0.5)

Member Data Documentation

◆ decay_width

double ProgCTFEnhancePSD::decay_width

Decay width (raised cosine)

Definition at line 51 of file ctf_enhance_psd.h.

◆ filter_w1

double ProgCTFEnhancePSD::filter_w1

Bandpass filter low frequency (in Fourier space, max 0.5)

Definition at line 45 of file ctf_enhance_psd.h.

◆ filter_w2

double ProgCTFEnhancePSD::filter_w2

Bandpass filter high frequency (in Fourier space, max 0.5)

Definition at line 48 of file ctf_enhance_psd.h.

◆ mask_w1

double ProgCTFEnhancePSD::mask_w1

Lower frequency for the mask (in Fourier space, max 0.5)

Definition at line 60 of file ctf_enhance_psd.h.

◆ mask_w2

double ProgCTFEnhancePSD::mask_w2

Higher frequency for the mask (in Fourier space, max 0.5)

Definition at line 63 of file ctf_enhance_psd.h.

◆ method

String ProgCTFEnhancePSD::method

Method.

Definition at line 42 of file ctf_enhance_psd.h.

◆ N0

int ProgCTFEnhancePSD::N0

Minimum number of fringes.

Definition at line 54 of file ctf_enhance_psd.h.

◆ NF

int ProgCTFEnhancePSD::NF

Maximum number of fringes.

Definition at line 57 of file ctf_enhance_psd.h.


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