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

#include <phantom_simulate_microscope.h>

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

Public Member Functions

void readParams ()
 
void defineParams ()
 
void show ()
 
void estimateSigma ()
 
void setupFourierFilter (FourierFilter &filter, bool isBackground, double &power)
 
void updateCtfs ()
 
void preProcess ()
 
void processImage (const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
 
void apply (MultidimArray< double > &I)
 
- 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 fn_ctf
 Filename with the CTF. More...
 
double sigma
 Total noise power. More...
 
double low_pass_before_CTF
 Low pass frequency before CTF. More...
 
bool after_ctf_noise
 Filename with the root squared spectrum for noise after CTF. More...
 
double defocus_change
 Defocus change (%) More...
 
double targetSNR
 Target SNR. More...
 
bool estimateSNR
 Estimate SNR. More...
 
bool CTFpresent
 CTFpresent. More...
 
FourierFilter ctf
 CTF. More...
 
FourierFilter lowpass
 Low pass filter, if it is 0 no lowpass filter is applied. More...
 
FourierFilter after_ctf
 After CTF noise root squared spectrum. More...
 
double sigma_before_CTF
 Noise power before CTF. More...
 
double sigma_after_CTF
 Noise power after CTF. More...
 
size_t Xdim
 Input image Xdim. More...
 
size_t Ydim
 Input image Ydim. More...
 
MetaDataVecpmdIn
 Particular reference to mdIn to manipulated. More...
 
double downsampling
 
double defocusU
 
double defocusV
 
- 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

Parameter class for the project program

Definition at line 36 of file phantom_simulate_microscope.h.

Member Function Documentation

◆ apply()

void ProgSimulateMicroscope::apply ( MultidimArray< double > &  I)

Apply to a single image. The image is modified. If the CTF is randomly selected then a new CTF is generated for each image

Definition at line 295 of file phantom_simulate_microscope.cpp.

296 {
297  I.setXmippOrigin();
300 
301  // Add noise before CTF
302  MultidimArray<double> noisy;
303  noisy.resize(I);
305  if (low_pass_before_CTF < 0.5)
306  lowpass.applyMaskSpace(noisy);
307  I += noisy;
308 
309  if (CTFpresent)
310  {
311  // Check if the mask is a defocus changing CTF
312  // In that case generate a new mask with a random defocus
313  if (defocus_change != 0)
314  {
316  ctf.ctf.DeltafU = defocusU * rnd_unif(1 - defocus_change / 100, 1 + defocus_change / 100);
317  ctf.ctf.DeltafV = defocusV *rnd_unif(1 - defocus_change / 100, 1 + defocus_change / 100);
318  aux.initZeros(2*Ydim, 2*Xdim);
319  ctf.generateMask(aux);
320  }
321 
322  // Apply CTF
323  ctf.applyMaskSpace(I);
324 
325  // Add noise after CTF
327  if (after_ctf_noise)
328  after_ctf.applyMaskSpace(noisy);
329  I += noisy;
330  }
333 }
double defocus_change
Defocus change (%)
void selfWindow(int n0, int z0, int y0, int x0, int nF, int zF, int yF, int xF, T init_value=0)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
CTFDescription ctf
void initRandom(double op1, double op2, RandomMode mode=RND_UNIFORM)
size_t Ydim
Input image Ydim.
double low_pass_before_CTF
Low pass frequency before CTF.
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
bool after_ctf_noise
Filename with the root squared spectrum for noise after CTF.
double sigma_after_CTF
Noise power after CTF.
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
double sigma_before_CTF
Noise power before CTF.
double rnd_unif()
FourierFilter lowpass
Low pass filter, if it is 0 no lowpass filter is applied.
FourierFilter after_ctf
After CTF noise root squared spectrum.
size_t Xdim
Input image Xdim.
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
void initZeros(const MultidimArray< T1 > &op)
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448
void generateMask(MultidimArray< double > &v)
void applyMaskSpace(MultidimArray< double > &v)

◆ defineParams()

void ProgSimulateMicroscope::defineParams ( )
virtual

Usage message. This function shows the way of introducing these parameters.

Reimplemented from XmippMetadataProgram.

Definition at line 85 of file phantom_simulate_microscope.cpp.

86 {
88  save_metadata_stack = true;
90  addUsageLine("Simulate the effect of the microscope on ideal projections.");
91  addParamsLine("==CTF options==");
92  addParamsLine(" [--ctf <CTFdescr=\"\">] : a CTF description, if this param is not supplied it should come in metadata");
93  addParamsLine(" [--after_ctf_noise] : apply noise after CTF");
94  addParamsLine(" [--defocus_change <v=0>] : change in the defocus value (percentage)");
95  addParamsLine("==Noise options==");
96  addParamsLine(" --noise <stddev> <w=0.5> : noise to be added, this noise is filtered at the frequency specified (<0.5).");
97  addParamsLine("or --targetSNR <snr> : the necessary noise power for a specified SNR is estimated");
98  addParamsLine("or --noNoise : do not add any noise, only simulate the CTF");
99  addParamsLine(" [--downsampling <D=1>] : Downsampling factor of the input micrograph with respect to the original");
100  addParamsLine(" : micrograph.");
101  addExampleLine("Generate a set of images with the CTF applied without any noise", false);
102  addExampleLine(" xmipp_phantom_simulate_microscope -i g0ta.sel --oroot g1ta --ctf untilt_ARMAavg.ctfparam");
103  addExampleLine("Generate a set of images with a target SNR", false);
104  addExampleLine(" xmipp_phantom_simulate_microscope -i g0ta.sel --oroot g2ta --ctf untilt_ARMAavg.ctfparam --targetSNR 0.2 --after_ctf_noise");
105  addExampleLine("Generate a set of images with the CTF applied and noise before and after CTF", false);
106  addExampleLine(" xmipp_phantom_simulate_microscope -i g0ta.sel --oroot g2ta --ctf untilt_ARMAavg.ctfparam --noise 4.15773 --after_ctf_noise");
107 }
void addExampleLine(const char *example, bool verbatim=true)
bool save_metadata_stack
Save the associated output metadata when output file is a stack.
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)

◆ estimateSigma()

void ProgSimulateMicroscope::estimateSigma ( )

Estimate sigma for a given SNR

Definition at line 130 of file phantom_simulate_microscope.cpp.

131 {
132  if (CTFpresent)
133  {
134  ctf.FilterBand = CTF;
135  ctf.ctf.enable_CTFnoise = false;
136  ctf.ctf.read(getParam("--ctf"));
139  }
140 
141  size_t N_stats = pmdIn->size();
142  std::cout << "N_stats=" << N_stats << std::endl;
143 
144  MultidimArray<double> proj_power(N_stats);
145  MultidimArray<double> proj_area(N_stats);
146  double power_avg=0., power_stddev, area_avg=0., area_stddev, avg, dummy;
147  if (verbose!=0)
148  {
149  std::cerr << "Estimating noise power for target SNR=" << targetSNR << std::endl;
150  init_progress_bar(N_stats);
151  }
152  FileName fnImg;
153  Image<double> proj;
154  size_t nImg=0;
155  for (size_t objId : pmdIn->ids())
156  {
157  pmdIn->getValue(image_label, fnImg,objId);
158  proj.read(fnImg);
159  MultidimArray<double> mProj=proj();
160 
161  if (CTFpresent)
162  {
163  if (nImg == 0)
164  ctf.generateMask(mProj);
165  ctf.applyMaskSpace(mProj);
166  }
167 
168  // Compute projection area
169  DIRECT_A1D_ELEM(proj_area,nImg) = 0;
171  if (fabs(DIRECT_MULTIDIM_ELEM(mProj,n)) > 1e-6)
172  DIRECT_A1D_ELEM(proj_area,nImg)++;
173 
174  // Compute projection power
175  mProj.computeStats(avg, DIRECT_A1D_ELEM(proj_power,nImg), dummy, dummy);
176 
177  if (nImg++ % 30 == 0 && verbose!=0)
178  progress_bar(nImg);
179  }
180  progress_bar(N_stats);
181  Histogram1D hist_proj, hist_area;
182  compute_hist(proj_power, hist_proj, 300);
183  compute_hist(proj_area, hist_area, 300);
184  proj_power.computeStats(power_avg, power_stddev, dummy, dummy);
185  std::cout << "# Projection power average: " << power_avg << std::endl
186  << "# Projection power stddev: " << power_stddev << std::endl
187  << "# Projection percentil 2.5%: " << hist_proj.percentil(2.5) << std::endl
188  << "# Projection percentil 97.5%: " << hist_proj.percentil(97.5) << std::endl;
189  proj_area.computeStats(area_avg, area_stddev, dummy, dummy);
190  std::cout << "# Projection area average: " << area_avg << std::endl
191  << "# Projection area stddev: " << area_stddev << std::endl
192  << "# Area percentil 2.5%: " << hist_area.percentil(2.5) << std::endl
193  << "# Area percentil 97.5%: " << hist_area.percentil(97.5) << std::endl;
194 
195  sigma=sqrt(power_avg*power_avg*Xdim*Ydim / (targetSNR*area_avg));
196  std::cout << "Estimated sigma=" << sigma << std::endl;
197  updateCtfs();
198 }
void init_progress_bar(long total)
CTFDescription ctf
size_t Ydim
Input image Ydim.
void sqrt(Image< double > &op)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void changeSamplingRate(double newTm)
Definition: ctf.h:994
double percentil(double percent_mass)
Definition: histogram.cpp:160
virtual IdIteratorProxy< false > ids()
size_t size() const override
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
#define DIRECT_A1D_ELEM(v, i)
const char * getParam(const char *param, int arg=0)
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
Definition: histogram.cpp:572
#define CTF
double sigma
Total noise power.
void progress_bar(long rlen)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
double Tm
Sampling rate (A/pixel)
Definition: ctf.h:240
#define DIRECT_MULTIDIM_ELEM(v, n)
int verbose
Verbosity level.
double dummy
MDLabel image_label
MDLabel to be used to read/write images, usually will be MDL_IMAGE.
size_t Xdim
Input image Xdim.
bool getValue(MDObject &mdValueOut, size_t id) const override
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
MetaDataVec * pmdIn
Particular reference to mdIn to manipulated.
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
void generateMask(MultidimArray< double > &v)
int * n
void applyMaskSpace(MultidimArray< double > &v)

◆ preProcess()

void ProgSimulateMicroscope::preProcess ( )
virtual

Produce side information.

Reimplemented from XmippMetadataProgram.

Definition at line 250 of file phantom_simulate_microscope.cpp.

251 {
253  size_t dum, dum2;
254  getImageSize(*pmdIn, Xdim, Ydim, dum, dum2);
255 
256  if (low_pass_before_CTF < 0.5)
257  {
261  }
262 
263  if (estimateSNR)
264  estimateSigma();
265 }
size_t Ydim
Input image Ydim.
double low_pass_before_CTF
Low pass frequency before CTF.
void getImageSize(const MetaData &md, size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim, MDLabel image_label)
FourierFilter lowpass
Low pass filter, if it is 0 no lowpass filter is applied.
#define RAISED_COSINE
size_t Xdim
Input image Xdim.
MetaDataVec * pmdIn
Particular reference to mdIn to manipulated.
unsigned int randomize_random_generator()
#define LOWPASS

◆ processImage()

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

Implements XmippMetadataProgram.

Definition at line 267 of file phantom_simulate_microscope.cpp.

268 {
269  static Image<double> img;
270  static FileName last_ctf;
271  static bool firstImage=true;
272  last_ctf = fn_ctf;
273  img.read(fnImg);
274 
275  rowOut=rowIn;
276 
277  rowIn.getValue(MDL_CTF_MODEL, fn_ctf);
278  rowOut.setValue(MDL_IMAGE, fnImgOut);
279  rowOut.setValue(MDL_CTF_MODEL, fn_ctf);
280  if (fn_ctf != last_ctf || firstImage)
281  {
282  updateCtfs();
283  firstImage=false;
284  }
285 
286  if (ZSIZE(img())!=1)
287  REPORT_ERROR(ERR_MULTIDIM_DIM,"This process is not intended for volumes");
288 
289  apply(img());
290 
291  img.write(fnImgOut);
292 }
void apply(MultidimArray< double > &I)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
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)
Name for the CTF Model (std::string)
FileName fn_ctf
Filename with the CTF.
T & getValue(MDLabel label)
#define ZSIZE(v)
void setValue(MDLabel label, const T &d, bool addLabel=true)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
Incorrect MultidimArray dimensions.
Definition: xmipp_error.h:173
Name of an image (std::string)

◆ readParams()

void ProgSimulateMicroscope::readParams ( )
virtual

Read from a command line. An exception might be thrown by any of the internal conversions, this would mean that there is an error in the command line and you might show a usage message.

Reimplemented from XmippMetadataProgram.

Definition at line 33 of file phantom_simulate_microscope.cpp.

34 {
36 
37  fn_ctf = "";//initialize empty, force recalculation of first time
38  pmdIn = dynamic_cast<MetaDataVec*>(getInputMd());
39  CTFpresent=true;
40  if (checkParam("--ctf"))
41  {
42  //Fill the input metadata with the value of 'fn_ctf'
43  fn_ctf=getParam("--ctf");
44  MDConstGenerator generator(fn_ctf);
45  generator.label = MDL_CTF_MODEL;
46  generator.fill(*pmdIn);
47  }
48  else
49  {
51  {
52  //sort the images according to the ctf to avoid the recaculation of it
53  //beeten images of the same ctf group
54  MetaDataDb md(*pmdIn);
55  pmdIn->sort(md, MDL_CTF_MODEL);
56  }
57  else
58  CTFpresent=false;
59  }
60  after_ctf_noise = checkParam("--after_ctf_noise");
61  defocus_change = getDoubleParam("--defocus_change");
62  if (checkParam("--noise"))
63  {
64  sigma = getDoubleParam("--noise");
65  low_pass_before_CTF = getDoubleParam("--noise",1);
66  estimateSNR=false;
67  }
68  else if (checkParam("--noNoise"))
69  {
70  estimateSNR=0;
71  sigma=0;
73  }
74  else
75  {
76  targetSNR = getDoubleParam("--targetSNR");
78  estimateSNR=true;
79  }
80  downsampling = getDoubleParam("--downsampling");
81 
82 }
double defocus_change
Defocus change (%)
void sort(const MetaDataVec &MDin, const MDLabel sortLabel, bool asc=true, int limit=-1, int offset=0)
double getDoubleParam(const char *param, int arg=0)
double low_pass_before_CTF
Low pass frequency before CTF.
bool after_ctf_noise
Filename with the root squared spectrum for noise after CTF.
Name for the CTF Model (std::string)
FileName fn_ctf
Filename with the CTF.
const char * getParam(const char *param, int arg=0)
double sigma
Total noise power.
bool checkParam(const char *param)
MetaDataVec * pmdIn
Particular reference to mdIn to manipulated.
bool containsLabel(const MDLabel label) const override

◆ setupFourierFilter()

void ProgSimulateMicroscope::setupFourierFilter ( FourierFilter filter,
bool  isBackground,
double &  power 
)

Prepare fourier filter

Definition at line 200 of file phantom_simulate_microscope.cpp.

202 {
203  static int dXdim = 2 * Xdim, dYdim = 2 * Ydim;
204  static MultidimArray<double> aux;
205 
206  filter.FilterBand = CTF;
207  filter.ctf.read(fn_ctf);
210  filter.ctf.enable_CTF = !isBackground;
211  filter.ctf.enable_CTFnoise = isBackground;
212  filter.ctf.produceSideInfo();
213  aux.resizeNoCopy(dYdim, dXdim);
214  aux.setXmippOrigin();
215  filter.do_generate_3dmask=true;
216  filter.generateMask(aux);
217  power = filter.maskPower();
218 }
CTFDescription ctf
size_t Ydim
Input image Ydim.
void resizeNoCopy(const MultidimArray< T1 > &v)
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
Definition: ctf.h:830
FileName fn_ctf
Filename with the CTF.
void read(const FileName &fn, bool disable_if_not_K=true)
Definition: ctf.cpp:1220
double DeltafU
Global gain. By default, 1.
Definition: ctf.h:828
bool enable_CTF
Enable CTF part.
Definition: ctf.h:275
#define CTF
size_t Xdim
Input image Xdim.
void power(Image< double > &op)
void produceSideInfo()
Produce Side information.
Definition: ctf.cpp:1392
bool enable_CTFnoise
Enable CTFnoise part.
Definition: ctf.h:273
void generateMask(MultidimArray< double > &v)

◆ show()

void ProgSimulateMicroscope::show ( )

Show parameters.

Definition at line 110 of file phantom_simulate_microscope.cpp.

111 {
112  if (!verbose)
113  return;
115  std::cout
116  << "Noise: " << sigma << std::endl
117  << "Low pass freq: " << low_pass_before_CTF << std::endl
118  << "After CTF noise: " << after_ctf_noise << std::endl
119  << "Defocus change: " << defocus_change << std::endl
120  ;
121  if (estimateSNR)
122  std::cout
123  << "Target SNR: " << targetSNR << std::endl;
124  if (CTFpresent)
125  std::cout << "CTF file: " << fn_ctf << std::endl;
126  else
127  std::cout << "No CTF provided\n";
128 }
double defocus_change
Defocus change (%)
double low_pass_before_CTF
Low pass frequency before CTF.
bool after_ctf_noise
Filename with the root squared spectrum for noise after CTF.
FileName fn_ctf
Filename with the CTF.
double sigma
Total noise power.
int verbose
Verbosity level.
void show() const override

◆ updateCtfs()

void ProgSimulateMicroscope::updateCtfs ( )

Update ctfs

Definition at line 220 of file phantom_simulate_microscope.cpp.

221 {
222  double before_power = 0, after_power = 0;
224 
225  if (CTFpresent)
226  {
227  setupFourierFilter(ctf, false, before_power);
228  if (after_ctf_noise)
229  setupFourierFilter(after_ctf, true, after_power);
230  }
231 
232  // Compute noise balance
233  if ((after_power != 0 || before_power != 0) && sigma!=0)
234  {
235  double p = after_power / (after_power + before_power);
236  double K = 1 / sqrt(p * after_power + (1 - p) * before_power);
237  sigma_after_CTF = sqrt(p) * K * sigma;
238  sigma_before_CTF = sqrt(1 - p) * K * sigma;
239  }
240  else if (sigma != 0)
241  {
243  sigma_after_CTF = 0;
244  }
245  else
247 }
void sqrt(Image< double > &op)
bool after_ctf_noise
Filename with the root squared spectrum for noise after CTF.
double sigma_after_CTF
Noise power after CTF.
double sigma_before_CTF
Noise power before CTF.
double sigma
Total noise power.
FourierFilter after_ctf
After CTF noise root squared spectrum.
constexpr int K
void setupFourierFilter(FourierFilter &filter, bool isBackground, double &power)

Member Data Documentation

◆ after_ctf

FourierFilter ProgSimulateMicroscope::after_ctf

After CTF noise root squared spectrum.

Definition at line 60 of file phantom_simulate_microscope.h.

◆ after_ctf_noise

bool ProgSimulateMicroscope::after_ctf_noise

Filename with the root squared spectrum for noise after CTF.

Definition at line 46 of file phantom_simulate_microscope.h.

◆ ctf

FourierFilter ProgSimulateMicroscope::ctf

CTF.

Definition at line 56 of file phantom_simulate_microscope.h.

◆ CTFpresent

bool ProgSimulateMicroscope::CTFpresent

CTFpresent.

Definition at line 54 of file phantom_simulate_microscope.h.

◆ defocus_change

double ProgSimulateMicroscope::defocus_change

Defocus change (%)

Definition at line 48 of file phantom_simulate_microscope.h.

◆ defocusU

double ProgSimulateMicroscope::defocusU

Definition at line 74 of file phantom_simulate_microscope.h.

◆ defocusV

double ProgSimulateMicroscope::defocusV

Definition at line 76 of file phantom_simulate_microscope.h.

◆ downsampling

double ProgSimulateMicroscope::downsampling

Downsampling factor

Definition at line 72 of file phantom_simulate_microscope.h.

◆ estimateSNR

bool ProgSimulateMicroscope::estimateSNR

Estimate SNR.

Definition at line 52 of file phantom_simulate_microscope.h.

◆ fn_ctf

FileName ProgSimulateMicroscope::fn_ctf

Filename with the CTF.

Definition at line 40 of file phantom_simulate_microscope.h.

◆ low_pass_before_CTF

double ProgSimulateMicroscope::low_pass_before_CTF

Low pass frequency before CTF.

Definition at line 44 of file phantom_simulate_microscope.h.

◆ lowpass

FourierFilter ProgSimulateMicroscope::lowpass

Low pass filter, if it is 0 no lowpass filter is applied.

Definition at line 58 of file phantom_simulate_microscope.h.

◆ pmdIn

MetaDataVec* ProgSimulateMicroscope::pmdIn

Particular reference to mdIn to manipulated.

Definition at line 70 of file phantom_simulate_microscope.h.

◆ sigma

double ProgSimulateMicroscope::sigma

Total noise power.

Definition at line 42 of file phantom_simulate_microscope.h.

◆ sigma_after_CTF

double ProgSimulateMicroscope::sigma_after_CTF

Noise power after CTF.

Definition at line 64 of file phantom_simulate_microscope.h.

◆ sigma_before_CTF

double ProgSimulateMicroscope::sigma_before_CTF

Noise power before CTF.

Definition at line 62 of file phantom_simulate_microscope.h.

◆ targetSNR

double ProgSimulateMicroscope::targetSNR

Target SNR.

Definition at line 50 of file phantom_simulate_microscope.h.

◆ Xdim

size_t ProgSimulateMicroscope::Xdim

Input image Xdim.

Definition at line 66 of file phantom_simulate_microscope.h.

◆ Ydim

size_t ProgSimulateMicroscope::Ydim

Input image Ydim.

Definition at line 68 of file phantom_simulate_microscope.h.


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