31 #define OUTSIDE_WRAP 0 33 #define OUTSIDE_VALUE 2 55 << std::endl <<
"Output movie: " 62 << std::endl <<
"Pre-exposure Amount (e/A^2): " 64 <<
"Restore Power after Filter: " <<
restore_power << std::endl;
69 addUsageLine(
"Align a set of frames by cross-correlation of the frames");
71 addParamsLine(
" [-o <fn=\"out.mrcs\">] : output filtered movie.");
73 " [--frameRange <n0=-1> <nF=-1>] : First and last frame to align, frame numbers start at 0");
74 addParamsLine(
" [--sampling <Ts=1>] : Sampling rate (A/pixel)");
75 addParamsLine(
" [--dosePerFrame <dose=2>] : Dose per frame (e/A^2)");
77 " [--accVoltage <voltage=300>] : Acceleration voltage (kV) min_value=200.0e0,max_value=300.0e0)");
86 double critical_dose) {
87 return exp((-0.5 * dose_at_end_of_frame) / critical_dose);
95 return 2.51284 * critical_dose;
112 if (accelerationVoltage < 301 && accelerationVoltage > 299.) {
115 }
else if (accelerationVoltage < 201.0 && accelerationVoltage > 199.0) {
120 "Bad acceleration voltage (must be 200 or 300 kV");
133 const double dose_start,
const double dose_finish) {
134 std::complex<double> complex_zero = 0;
137 double current_critical_dose, current_optimal_dose;
138 int sizeX_2 = Xdim / 2;
139 double ixsize = 1.0 / Xdim;
140 int sizeY_2 = Ydim / 2;
141 double iysize = 1.0 / Ydim;
142 for (
long int i = 0;
i <
YSIZE(FFT1);
i++) {
145 for (
long int j = 0;
j <
XSIZE(FFT1);
j++) {
147 #ifdef DEBUG_FFT_FREQ 148 std::cerr <<
"(j+1,i+1)(x,y)=" <<
j +1 <<
"," <<
i + 1<<
" " 149 << x <<
" " << y <<
" = " 152 if (
i == 0 &&
j == 0)
161 current_critical_dose);
162 if (
abs(dose_finish - current_optimal_dose)
163 <
abs(dose_start - current_optimal_dose)) {
165 current_critical_dose);
177 size_t Xdim, Ydim, Zdim, Ndim;
190 for (
size_t i = 0;
i < Ndim;
i++) {
205 std::cout <<
"Computing Fourier transform of frames ..." << std::endl;
216 for (
size_t objId : movie.
ids())
223 #ifdef PRINT_ORIGINAL_IMAGE 224 std::cerr <<
"n= (original image)" << n << std::endl << frame() << std::endl;
232 VFourierMag().resizeNoCopy(FFT1);
236 int m1sizeX =
XSIZE(frame());
int m1sizeY =
YSIZE(frame());
237 int sizeX_2 = m1sizeX/2;
double ixsize = 1.0/m1sizeX;
238 int sizeY_2 = m1sizeY/2;
double iysize = 1.0/m1sizeY;
239 for (
long int i=0;
i<
YSIZE(FFT1);
i++) {
241 for (
long int j=0;
j<
XSIZE(FFT1);
j++) {
243 std::cerr <<
"(x,y)=" <<
j +1 <<
"," <<
i + 1<<
" = " <<
245 x*x <<
" " << y*y <<
" " << (x*x+y*
y) << std::endl;
254 std::cerr <<
"DEBUG_JM: n re im: " << counter <<
" " << re <<
" " << im << std::endl;
259 VFourierMag.
write(
"/tmp/frame_mag_1.mrc");
260 frame.
write(
"/tmp/frame_1.mrc");
264 std::cerr <<
"fourier before filter " << n << std::endl
265 << FFT1 << std::endl;
271 #ifdef PRINTFFTAFTERFILTER 272 std::cerr <<
"Fourier after filter"<< std::endl << FFT1 << std::endl;
275 #ifdef PRINTREALIMAGEAFTERDOEFILTERING 276 std::cerr <<
"fourier matrix after inverse (very likely garbage)" << std::endl
277 << FFT1 << std::endl;
278 std::cerr <<
"image after filter " << std::endl
279 << frame() << std::endl;
FileName user_supplied_input_filename
void init_progress_bar(long total)
double getDoubleParam(const char *param, int arg=0)
void applyDoseFilterToImage(int Ydim, int Xdim, const MultidimArray< std::complex< double > > &FFT1, const double dose_start, const double dose_finish)
Apply a dose filter to the image Fourier transform.
#define REPORT_ERROR(nerr, ErrormMsg)
double criticalDose(double spatial_frequency)
Given a spatial frequency, return the critical dose in electrons per square Angstroms.
ProgMovieFilterDose(void)
double acceleration_voltage
double pre_exposure_amount
void sqrt(Image< double > &op)
double optimalDoseGivenCriticalDose(double critical_dose)
Given the critical dose, return an estimate of the optimal dose (at which the SNR is maximised) ...
#define DIRECT_A2D_ELEM(v, i, j)
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)
#define MULTIDIM_ARRAY(v)
void compose(const String &str, const size_t no, const String &ext="")
void abs(Image< double > &op)
double critical_dose_at_dc
String getExtension() const
#define FFT_IDX2DIGFREQ_FAST(idx, size, size_2, isize, freq)
void log(Image< double > &op)
const char * getParam(const char *param, int arg=0)
void initVoltage(double accelerationVoltage)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const
Incorrect argument received.
FileName user_supplied_output_filename
void progress_bar(long rlen)
void max(Image< double > &op1, const Image< double > &op2)
bool restore_power
Restore noise power after filtering?', 'Renormalise the summed image after filtering.
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
int verbose
Verbosity level.
int user_supplied_last_frame
bool isMetaData(bool failIfNotExists=true) const
void defineParams()
Define parameters.
void readParams()
Read argument from command line.
int user_supplied_first_frame
double doseFilter(double dose_at_end_of_frame, double critical_dose)
Compute the dose filter, which is the signal attenuation.
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
void addUsageLine(const char *line, bool verbatim=false)
int getIntParam(const char *param, int arg=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false)
double voltage_scaling_factor
void addParamsLine(const String &line)