35 void ProgVolumeSubtraction::defineParams() {
37 addUsageLine(
"This program modifies a volume as much as possible in order " 38 "to assimilate it to another one, " 39 "without loosing the important information in it ('adjustment " 40 "process'). Then, the subtraction of " 41 "the two volumes can be optionally calculated. Sharpening: " 42 "reference volume must be an atomic " 43 "structure previously converted into a density map of the " 44 "same specimen than in input volume 2.");
48 addParamsLine(
"[-o <structure=\"\">]\t: Volume 2 modified or " 51 "then output_volume.mrc");
53 "subtraction of the volumes. Output will be the difference");
55 "(sigma) to smooth the mask transition");
57 "[--iter <n=5>]\t: Number of iterations for the adjustment process");
61 "[--maskSub <mask=\"\">]\t: Mask for subtraction region");
63 "[--cutFreq <f=0>]\t: Filter both volumes with a filter which " 64 "specified cutoff frequency (i.e. resolution inverse, <0.5)");
66 "[--lambda <l=1>]\t: Relaxation factor for Fourier Amplitude POCS, " 67 "i.e. 'how much modification of volume Fourier amplitudes', between 1 " 68 "(full modification, recommended) and 0 (no modification)");
69 addParamsLine(
"[--radavg]\t: Match the radially averaged Fourier " 70 "amplitudes when adjusting the amplitudes instead of taking " 71 "directly them from the reference volume");
73 "[--computeEnergy]\t: Compute the energy difference between each step " 74 "(energy difference gives information about the convergence of the " 75 "adjustment process, while it can slightly slow the performance)");
77 "[--saveV1 <structure=\"\"> ]\t: Save subtraction intermediate file " 78 "(vol1 filtered) just when option --sub is passed, if not passed the " 79 "input reference volume is not modified");
81 "[--saveV2 <structure=\"\"> ]\t: Save subtraction intermediate file " 82 "(vol2 adjusted) just when option --sub is passed, if not passed the " 83 "output of the program is this file");
87 void ProgVolumeSubtraction::readParams() {
92 fnOutVol =
"output_volume.mrc";
103 fnVol1F =
"volume1_filtered.mrc";
106 fnVol2A =
"volume2_adjusted.mrc";
112 void ProgVolumeSubtraction::show()
const {
113 std::cout <<
"Input volume 1:\t" << fnVol1 << std::endl
114 <<
"Input volume 2: " << fnVol2 << std::endl
115 <<
"Input mask 1: " << fnMask1 << std::endl
116 <<
"Input mask 2: " << fnMask2 << std::endl
117 <<
"Input mask sub: " << fnMaskSub << std::endl
118 <<
"Sigma: " << sigma << std::endl
119 <<
"Iterations: " << iter << std::endl
120 <<
"Cutoff frequency: " << cutFreq << std::endl
121 <<
"Relaxation factor: " << lambda << std::endl
122 <<
"Match radial averages:\t" << radavg << std::endl
123 <<
"Output:\t" << fnOutVol << std::endl;
150 int V1size_x,
int V1size_y,
int V1size_z) {
151 int V1size2_x = V1size_x/2;
152 double V1sizei_x = 1.0/V1size_x;
153 int V1size2_y = V1size_y/2;
154 double V1sizei_y = 1.0/V1size_y;
155 int V1size2_z = V1size_z/2;
156 double V1sizei_z = 1.0/V1size_z;
167 double wy2_wz2 = wy*wy + wz2;
171 double w =
sqrt(wx*wx + wy2_wz2);
197 void ProgVolumeSubtraction::extractPhase(
MultidimArray<std::complex<double>> &FI)
const{
200 double phi = atan2(*(ptr + 1), *ptr);
226 int Vsize2_x = int(
XSIZE(V))/2;
227 double Vsizei_x = 1.0/int(
XSIZE(V));
228 int Vsize2_y = int(
YSIZE(V))/2;
229 double Vsizei_y = 1.0/int(
YSIZE(V));
230 int Vsize2_z = int(
ZSIZE(V))/2;
231 double Vsizei_z = 1.0/int(
ZSIZE(V));
235 auto maxrad = int(
floor(
sqrt(Vsize2_x*Vsize2_x + Vsize2_y*Vsize2_y + Vsize2_z*Vsize2_z)));
238 for (
int k=0;
k<Vsize2_z; ++
k)
242 for (
int i=0;
i<Vsize2_y; ++
i)
245 double wy2_wz2 = wy*wy + wz2;
246 for (
int j=0;
j<Vsize2_x; ++
j)
249 double w =
sqrt(wx*wx + wy2_wz2);
256 radial_mean/= radial_count;
270 radQuotient(
i) =
std::min(radQuotient(
i), 1.0);
271 if (radQuotient(
i) != radQuotient(
i))
281 filter2.
w1 = cutFreq;
293 V1Filtered.
write(fnVol1F);
319 if (fnM1 !=
"" && fnM2 !=
"") {
324 mask = mask1() * mask2();
354 masksub.
read(fnMSub);
367 auto V1size_x = (int)
XSIZE(V1());
368 auto V1size_y = (int)
YSIZE(V1());
369 auto V1size_z = (int)
ZSIZE(V1());
377 computeEnergy(Vdiff(), V());
382 computeEnergy(Vdiff(), V());
387 computeEnergy(Vdiff(), V());
394 computeEnergy(Vdiff(), V());
399 computeEnergy(Vdiff(), V());
402 double std2 = V().computeStddev();
405 computeEnergy(Vdiff(), V());
414 computeEnergy(Vdiff(), V());
420 void ProgVolumeSubtraction::run() {
424 auto mask = createMask(V1, fnMask1, fnMask2);
427 V1().computeDoubleMinMax(v1min, v1max);
432 std1 = V1().computeStddev();
434 auto V2FourierPhase = computePhase(V());
440 for (n = 0; n < iter; ++n) {
441 runIteration(V, V1, radQuotient, V1FourierMag, V2FourierPhase, mask, filter2);
443 if (performSubtraction) {
444 auto masksub = getSubtractionMask(fnMaskSub, mask);
446 V =
subtraction(V1, V, masksub, fnVol1F, fnVol2A, filter2, cutFreq);
void min(Image< double > &op1, const Image< double > &op2)
double getDoubleParam(const char *param, int arg=0)
Image< double > subtraction(Image< double > V1, Image< double > &V, const MultidimArray< double > &mask, const FileName &fnVol1F, const FileName &fnVol2A, FourierFilter &filter2, double cutFreq)
__host__ __device__ float2 floor(const float2 v)
void resizeNoCopy(const MultidimArray< T1 > &v)
void createFilter(FourierFilter &filter2, double cutFreq)
void sqrt(Image< double > &op)
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)
void POCSnonnegative(MultidimArray< double > &I)
void abs(Image< double > &op)
ql0001_ & k(htemp+1),(cvec+1),(atemp+1),(bj+1),(bl+1),(bu+1),(x+1),(clamda+1), &iout, infoqp, &zero,(w+1), &lenw,(iw+1), &leniw, &glob_grd.epsmac
void POCSmask(const MultidimArray< double > &mask, MultidimArray< double > &I)
void CenterFFT(MultidimArray< T > &v, bool forward)
#define FFT_IDX2DIGFREQ_FAST(idx, size, size_2, isize, freq)
#define DIRECT_A1D_ELEM(v, i)
MultidimArray< double > computeMagnitude(MultidimArray< double > &volume)
const char * getParam(const char *param, int arg=0)
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
void radialAverage(const MultidimArray< double > &VolFourierMag, const MultidimArray< double > &V, MultidimArray< double > &radial_mean)
#define DIRECT_MULTIDIM_ELEM(v, n)
void POCSFourierAmplitude(const MultidimArray< double > &V1FourierMag, MultidimArray< std::complex< double >> &V2Fourier, double l)
void mod(const MultidimArray< T > &x, MultidimArray< T > &m, double y)
#define DIRECT_A3D_ELEM(v, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
void POCSMinMax(MultidimArray< double > &V, double v1m, double v1M)
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)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
void POCSFourierPhase(const MultidimArray< std::complex< double >> &phase, MultidimArray< std::complex< double >> &FI)
void POCSFourierAmplitudeRadAvg(MultidimArray< std::complex< double >> &V, double l, const MultidimArray< double > &rQ, int V1size_x, int V1size_y, int V1size_z)
int getIntParam(const char *param, int arg=0)
void FFT_magnitude(const MultidimArray< std::complex< double > > &v, MultidimArray< double > &mag)
void generateMask(MultidimArray< double > &v)
MultidimArray< double > computeRadQuotient(const MultidimArray< double > &v1Mag, const MultidimArray< double > &vMag, const MultidimArray< double > &V1, const MultidimArray< double > &V)
void addParamsLine(const String &line)
void applyMaskSpace(MultidimArray< double > &v)