90 addUsageLine(
"Simulate the effect of the microscope on ideal projections.");
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)");
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");
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");
116 <<
"Noise: " <<
sigma << std::endl
123 <<
"Target SNR: " <<
targetSNR << std::endl;
125 std::cout <<
"CTF file: " <<
fn_ctf << std::endl;
127 std::cout <<
"No CTF provided\n";
142 std::cout <<
"N_stats=" << N_stats << std::endl;
146 double power_avg=0., power_stddev, area_avg=0., area_stddev, avg,
dummy;
149 std::cerr <<
"Estimating noise power for target SNR=" <<
targetSNR << std::endl;
177 if (nImg++ % 30 == 0 &&
verbose!=0)
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;
196 std::cout <<
"Estimated sigma=" <<
sigma << std::endl;
203 static int dXdim = 2 *
Xdim, dYdim = 2 *
Ydim;
222 double before_power = 0, after_power = 0;
233 if ((after_power != 0 || before_power != 0) &&
sigma!=0)
235 double p = after_power / (after_power + before_power);
236 double K = 1 /
sqrt(p * after_power + (1 - p) * before_power);
271 static bool firstImage=
true;
280 if (
fn_ctf != last_ctf || firstImage)
void init_progress_bar(long total)
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)
void apply(MultidimArray< double > &I)
double getDoubleParam(const char *param, int arg=0)
bool CTFpresent
CTFpresent.
#define REPORT_ERROR(nerr, ErrormMsg)
void initRandom(double op1, double op2, RandomMode mode=RND_UNIFORM)
size_t Ydim
Input image Ydim.
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
double low_pass_before_CTF
Low pass frequency before CTF.
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
double DeltafV
Defocus in V (in Angstroms). Negative values are underfocused.
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)
bool after_ctf_noise
Filename with the root squared spectrum for noise after CTF.
bool estimateSNR
Estimate SNR.
void changeSamplingRate(double newTm)
double percentil(double percent_mass)
FileName fn_ctf
Filename with the CTF.
double sigma_after_CTF
Noise power after CTF.
void read(const FileName &fn, bool disable_if_not_K=true)
double DeltafU
Global gain. By default, 1.
bool enable_CTF
Enable CTF part.
double sigma_before_CTF
Noise power before CTF.
#define DIRECT_A1D_ELEM(v, i)
T & getValue(MDLabel label)
const char * getParam(const char *param, int arg=0)
void compute_hist(const MultidimArrayGeneric &array, Histogram1D &hist, int no_steps)
double sigma
Total noise power.
FourierFilter lowpass
Low pass filter, if it is 0 no lowpass filter is applied.
double targetSNR
Target SNR.
void progress_bar(long rlen)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
FourierFilter after_ctf
After CTF noise root squared spectrum.
double Tm
Sampling rate (A/pixel)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
size_t Xdim
Input image Xdim.
void power(Image< double > &op)
void setValue(MDLabel label, const T &d, bool addLabel=true)
#define FIRST_XMIPP_INDEX(size)
void produceSideInfo()
Produce Side information.
bool checkParam(const char *param)
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.
Incorrect MultidimArray dimensions.
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
unsigned int randomize_random_generator()
bool enable_CTFnoise
Enable CTFnoise part.
#define LAST_XMIPP_INDEX(size)
void generateMask(MultidimArray< double > &v)
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)
void setupFourierFilter(FourierFilter &filter, bool isBackground, double &power)