48 auto size_multiple = (int)pow(2.0, (
double) iterations);
49 if (
XSIZE(input) % size_multiple != 0)
51 (std::string)
"Bilib_DWT: Xsize must be a multiple of " +
53 if (
YSIZE(input) > 1 &&
YSIZE(input) % size_multiple != 0)
55 (std::string)
"Bilib_DWT 2D: Ysize must be a multiple of " +
57 if (
ZSIZE(input) > 1 &&
ZSIZE(input) % size_multiple != 0)
59 (std::string)
"Bilib_DWT 3D: Zsize must be a multiple of " +
70 TW.
Filter =
"Orthonormal Spline";
86 for (
int i = 1;
i < iterations;
i++)
95 input_aux.
resize(zsize, ysize, xsize);
96 result_aux.
resize(zsize, ysize, xsize);
113 else if (isign == -1)
116 for (
int i = iterations - 1;
i >= 1;
i--)
120 int ysize =
XMIPP_MAX(1,
YSIZE(input) / (
int)pow(2.0, (
double)i));
121 int zsize =
XMIPP_MAX(1,
ZSIZE(input) / (
int)pow(2.0, (
double)i));
125 input_aux.
resize(zsize, ysize, xsize);
126 result_aux.
resize(zsize, ysize, xsize);
171 for (
int s = 0; s < Nx; s++)
177 int x1, y1, x2, y2,
x,
y,
i,
j;
179 for (y = y1, i = 0; y <= y2; y++, i++)
180 for (x = x1, j = 0; x <= x2; x++, j++)
242 #define DWT_Scale(i,smax) ((int)((i==0)?smax-1:(ABS((CEIL(log10((double)(i+1))/log10(2.0))-smax))))) 243 #define DWT_Quadrant1D(i,s,smax) ((s!=smax-1)?'1':((i==0)?'0':'1')) 244 #define DWT_QuadrantnD(i,s,sp,smax) \ 245 ((s!=sp)?'0':DWT_Quadrant1D(i,s,smax)) 246 #define DWT_icoef1D(i,s,smax) () 249 int &scale, std::string &quadrant)
258 int &scale, std::string &quadrant)
265 scale = (int)(
XMIPP_MIN(scalex, scaley));
272 int &scale, std::string &quadrant)
299 int x1, y1, z1, x2, y2, z2;
304 YY(corner1),
YY(corner2),
ZZ(corner1),
ZZ(corner2));
322 const std::string &quadrant,
double sigma)
328 XX(corner1),
XX(corner2),
YY(corner1),
YY(corner2));
329 double dummy, avg, stddev;
330 I.
computeStats(avg, stddev, dummy, dummy, corner1, corner2);
333 double th = sigma * sigma / stddev;
351 double avg, stddev, min_val=0., max_val=0.;
358 XX(corner1),
XX(corner2),
YY(corner1),
YY(corner2));
361 double value=fabs(I(r));
366 XX(corner1),
XX(corner2),
YY(corner1),
YY(corner2));
369 double value=fabs(I(r));
374 XX(corner1),
XX(corner2),
YY(corner1),
YY(corner2));
377 double value=fabs(I(r));
387 for (
int s = 0; s <= scale; s++)
401 mask.
R1 = (double)
XSIZE(I) / 2 + 1;
415 const std::string &orientation,
416 double mu,
double S,
double N)
423 if (S < 1e-6 && N < 1e-6)
437 double ymu2 = -0.5 * ymu * ymu;
438 double expymu2SN = exp(ymu2 * iSN);
439 double den = exp(ymu2 * iN) + expymu2SN;
441 WI_r *= S_N * expymu2SN / den;
447 const std::string &orientation,
448 double mu,
double S,
double N)
456 if (S < 1e-6 && N < 1e-6)
466 double ymu2 = -0.5 * ymu * ymu;
467 double expymu2SN = exp(ymu2 / SN);
468 double den = exp(ymu2 / N) + expymu2SN;
470 WI(r) = S_N * expymu2SN / den *
y;
487 int scale_dim = power.
size();
490 int extra_constraints = 0;
492 extra_constraints += (scale_dim - 1);
493 A.
initZeros(2*(scale_dim - 1) + 2*scale_dim + 2 + extra_constraints, 2*scale_dim);
494 for (
int i = 1;
i < scale_dim;
i++)
498 A(
i - 1 + scale_dim - 1,
i - 1 + scale_dim) = 1;
499 A(
i - 1 + scale_dim - 1,
i + scale_dim) = -1;
501 for (
int i = 0;
i < 2*scale_dim;
i++)
502 A(
i + 2*(scale_dim - 1),
i) = -1;
506 for (
int j = 0;
j < scale_dim;
j++)
507 aux0coefs(
j) = Ncoefs(
j) * SNR0;
509 for (
int j = 0;
j < scale_dim;
j++)
510 auxFcoefs(
j) = Ncoefs(
j) * SNRF;
513 for (
int j = 0;
j < scale_dim;
j++)
514 A(2*(scale_dim - 1) + 2*scale_dim,
j) = (-1) * auxFcoefs(
j);
515 for (
int j = scale_dim;
j < 2*scale_dim;
j++)
516 A(2*(scale_dim - 1) + 2*scale_dim,
j) = Ncoefs(
j - scale_dim);
519 for (
int j = 0;
j < scale_dim;
j++)
520 A(2*(scale_dim - 1) + 2*scale_dim + 1,
j) = aux0coefs(
j);
521 for (
int j = scale_dim;
j < 2*scale_dim;
j++)
522 A(2*(scale_dim - 1) + 2*scale_dim + 1,
j) = (-1) * Ncoefs(
j - scale_dim);
526 for (
int i = 0;
i < scale_dim - 1;
i++)
528 A(A.
mdimy - (scale_dim - 1) +
i,
i) = -1.01;
529 A(A.
mdimy - (scale_dim - 1) +
i,
i + 1) = 1;
538 for (
int j = 0;
j < scale_dim;
j++)
540 Aeq(0,
j) = Ncoefs(
j);
541 Aeq(0,
j + scale_dim) = Ncoefs(
j);
547 beq(0) = powerI - power_rest;
552 for (
int j = 0;
j < scale_dim;
j++)
555 C(
j,
j + scale_dim) = 1;
562 C.
write(
"./matrices/C.txt");
563 power.
write(
"./matrices/power.txt");
564 A.
write(
"./matrices/A.txt");
565 b.
write(
"./matrices/b.txt");
566 Aeq.
write(
"./matrices/Aeq.txt");
567 beq.
write(
"./matrices/beq.txt");
569 std::cout <<
"Equation system Cx=d\n" 570 <<
"C=\n" << C << std::endl
571 <<
"d=" << (power / Ncoefs).
transpose() << std::endl
574 <<
"A=\n" << A << std::endl
577 <<
"Aeq=\n" << Aeq << std::endl
578 <<
"beq=" << beq.
transpose() << std::endl;
583 leastSquare(C, power / Ncoefs, A, b, Aeq, beq, bl, bu, estimatedS);
589 std::cout <<
"scale_dim :: " << scale_dim << std::endl;
590 std::cout <<
"--------estimatedS -------- \n";
591 std::cout << estimatedS;
592 std::cout <<
"--------------------------- \n";
593 std::cout <<
"Inequality constraints agreement" << std::endl
594 << (A*estimatedS).
transpose() << std::endl;
595 std::cout <<
"Equality constraints agreement" << std::endl
596 << (Aeq*estimatedS).
transpose() << std::endl;
597 std::cout <<
"Goal function value: " << (C*estimatedS).
transpose() << std::endl;
604 double SNR0,
double SNRF,
bool white_noise,
int tell,
bool denoise)
607 double powerI = WI.
sum2();
610 int Xdim =
XSIZE(WI);
611 int max_scale =
ROUND(
log(
double(Xdim)) /
log(2.0));
615 std::cout <<
"powerI= " << powerI << std::endl;
616 double powerWI = WI.
sum2();
617 std::cout <<
"powerWI= " << powerWI << std::endl;
618 std::cout <<
"Ydim = " << Ydim <<
" Xdim = " << Xdim <<
"\n";
619 std::cout <<
"Ncoef_total= " << Ncoef_total << std::endl;
620 std::cout <<
"max_scale = " << max_scale <<
"\n";
627 int scale_dim = scale.
size();
632 std::vector<std::string> orientation;
633 orientation.push_back(
"01");
634 orientation.push_back(
"10");
635 orientation.push_back(
"11");
636 int orientationSize=orientation.size();
637 int jmax=scale.
size();
638 for (
int j = 0;
j < jmax;
j++)
640 for (
size_t k = 0;
k < orientation.size();
k++)
651 VEC_ELEM(Ncoefs,
j) = (int)pow(2.0, 2 * (max_scale -
VEC_ELEM(scale,
j) - 1)) * orientationSize;
656 double power_rest = 0.0;
662 power_rest += aux*aux;
664 Ncoefs_rest = (int)pow(2.0, 2 * (max_scale - 1 - scale(scale_dim - 1)));
668 std::cout <<
"scale = " << std::endl << scale << std::endl;
669 std::cout <<
"power= " << std::endl <<
power <<
"\n";
670 std::cout <<
"average= " << std::endl << average <<
"\n";
671 std::cout <<
"Ncoefs= " << std::endl << Ncoefs <<
"\n";
672 std::cout <<
"power_rest= " << power_rest <<
"\n";
673 std::cout <<
"Ncoefs_rest= " << Ncoefs_rest <<
"\n";
674 std::cout <<
"powerI= " << powerI << std::endl;
675 std::cout <<
"Total sum of powers = " << power.
sum() + power_rest << std::endl;
676 std::cout <<
"Difference powers = " << powerI - power.sum() - power_rest << std::endl;
682 SNR0, SNRF, powerI, power_rest, white_noise, estimatedS);
686 std::cout <<
"estimatedS =\n" << estimatedS << std::endl;
688 for (
int i = 0;
i < scale_dim;
i++)
690 N += Ncoefs(
i) * estimatedS(
i);
691 S += Ncoefs(
i) * estimatedS(scale_dim +
i);
693 std::cout <<
"SNR value=" << S / N << std::endl << std::endl;
707 std::vector<std::string> orientation;
708 orientation.push_back(
"01");
709 orientation.push_back(
"10");
710 orientation.push_back(
"11");
716 for (
size_t i = 0;
i < scale.
size();
i++)
718 double N = estimatedS(
i);
719 double S = estimatedS(
i + scale.
size());
720 for (
size_t k = 0;
k < orientation.size();
k++)
727 double SNR0,
double SNRF,
bool white_noise,
728 int tell,
bool denoise)
731 double powerI = WI.
sum2();
734 size_t Xdim=
ZSIZE(WI);
735 int max_scale =
ROUND(
log(
double(Xdim)) /
log(2.0));
739 std::cout <<
"powerI= " << powerI << std::endl;
740 double powerWI = WI.
sum2();
741 std::cout <<
"powerWI= " << powerWI << std::endl;
742 std::cout <<
"Zdim= " << Zdim <<
" Ydim = " << Ydim <<
" Xdim = " << Xdim <<
"\n";
743 std::cout <<
"Ncoef_total= " << Ncoef_total << std::endl;
744 std::cout <<
"max_scale = " << max_scale <<
"\n";
751 int scale_dim = scale.
size();
756 std::vector<std::string> orientation;
757 orientation.push_back(
"001");
758 orientation.push_back(
"010");
759 orientation.push_back(
"011");
760 orientation.push_back(
"100");
761 orientation.push_back(
"101");
762 orientation.push_back(
"110");
763 orientation.push_back(
"111");
764 for (
size_t j = 0;
j < scale.
size();
j++)
766 for (
size_t k = 0;
k < orientation.size();
k++)
772 power(
j) += WI(r) * WI(r);
776 Ncoefs(
j) = (int)pow(2.0, 3 * (max_scale - scale(
j) - 1)) * orientation.
size();
777 average(
j) = average(
j) / Ncoefs(
j);
781 double power_rest = 0.0;
786 power_rest += WI(r) * WI(r);
787 Ncoefs_rest = (int)pow(2.0, 3 * (max_scale - 1 - scale(scale_dim - 1)));
791 std::cout <<
"scale = " << std::endl << scale << std::endl;
792 std::cout <<
"power= " << std::endl <<
power <<
"\n";
793 std::cout <<
"average= " << std::endl << average <<
"\n";
794 std::cout <<
"Ncoefs= " << std::endl << Ncoefs <<
"\n";
795 std::cout <<
"power_rest= " << power_rest <<
"\n";
796 std::cout <<
"Ncoefs_rest= " << Ncoefs_rest <<
"\n";
797 std::cout <<
"powerI= " << powerI << std::endl;
798 std::cout <<
"Total sum of powers = " << power.
sum() + power_rest << std::endl;
799 std::cout <<
"Difference powers = " << powerI - power.sum() - power_rest << std::endl;
805 SNR0, SNRF, powerI, power_rest, white_noise, estimatedS);
808 std::cout <<
"estimatedS =\n" << estimatedS << std::endl;
810 for (
int i = 0;
i < scale_dim;
i++)
812 N += Ncoefs(
i) * estimatedS(
i);
813 S += Ncoefs(
i) * estimatedS(scale_dim +
i);
815 std::cout <<
"SNR value=" << S / N << std::endl << std::endl;
828 std::vector<std::string> orientation;
829 orientation.push_back(
"001");
830 orientation.push_back(
"010");
831 orientation.push_back(
"011");
832 orientation.push_back(
"100");
833 orientation.push_back(
"101");
834 orientation.push_back(
"110");
835 orientation.push_back(
"111");
841 for (
size_t i = 0;
i <
XSIZE(scale);
i++)
843 double N = estimatedS(
i);
844 double S = estimatedS(
i +
XSIZE(scale));
845 for (
size_t k = 0;
k < orientation.size();
k++)
858 double minWaveLength,
868 size_t NR, NC,NZ, NDim;
871 if ( (NZ!=1) || (NDim!=1) )
880 & (H.xinit == 0) & (H.yinit == 0) )
900 double radius=
sqrt(wy2+wx2);
901 if (radius < 1e-10) radius=1;
906 A2D_ELEM(lowPass,
i,
j)= 1.0/(1.0+std::pow(radius/cutoff,n));
942 for (
int num = 0; num < nScale; ++num)
944 double waveLength = minWaveLength;
946 for(
int numMult=0; numMult < num;numMult++)
949 double fo = 1.0/waveLength;
1006 A2D_ELEM(Or,
i,
j) = std::atan2(temph1,temph2);
1022 Energy.
write(fpName3);
void phaseCongMono(MultidimArray< double > &I, MultidimArray< double > &Ph, MultidimArray< double > &Or, MultidimArray< double > &Energy, MultidimArray< double > &lowPass, MultidimArray< double > &Radius, MultidimArray< std::complex< double > > &H, int nScale, double minWaveLength, double mult, double sigmaOnf)
#define A2D_ELEM(v, i, j)
void Bilib_DWT(const MultidimArray< double > &input, MultidimArray< double > &result, int iterations, int isign)
void set_DWT_type(int DWT_type)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
int Get_Max_Scale(int size)
#define REPORT_ERROR(nerr, ErrormMsg)
void DWT_lowpass2D(const MultidimArray< double > &v, MultidimArray< double > &result)
#define INSERT_VALUE(histogram, value)
void resizeNoCopy(const MultidimArray< T1 > &v)
void sqrt(Image< double > &op)
void clean_quadrant3D(MultidimArray< double > &I, int scale, const std::string &quadrant)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
#define DIRECT_A2D_ELEM(v, i, j)
#define MULTIDIM_ARRAY(v)
double percentil(double percent_mass)
void bayesian_solve_eq_system(const Matrix1D< double > &power, const Matrix1D< double > &Ncoefs, double SNR0, double SNRF, double powerI, double power_rest, bool white_noise, Matrix1D< double > &estimatedS)
String integerToString(int I, int _width, char fill_with)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY3D(V)
Incorrect MultidimArray size.
void adaptive_soft_thresholding_block2D(MultidimArray< double > &I, int scale, const std::string &quadrant, double sigma)
void write(const FileName &fn) const
i<=ncnstr;i++) cs[i].mult=0.e0;if(nfsip) for(i=1;i<=nob;i++) { ob[i].mult=0.e0;ob[i].mult_L=0.e0;} for(i=1;i<=nqpram;i++) { ii=k+i;if(clamda[ii]==0.e0 &&clamda[ii+nqpram]==0.e0) continue;else if(clamda[ii] !=0.e0) clamda[ii]=-clamda[ii];else clamda[ii]=clamda[ii+nqpram];} nqnp=nqpram+ncnstr;for(i=1;i<=nqpram;i++) param-> mult[i]
void init(double min_val, double max_val, int n_steps)
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
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
Matrix1D< T > transpose() const
void clean_quadrant2D(MultidimArray< double > &I, int scale, const std::string &quadrant)
Matrix1D< double > bayesian_wiener_filtering2D(MultidimArray< double > &WI, int allowed_scale, double SNR0, double SNRF, bool white_noise, int tell, bool denoise)
void CenterFFT(MultidimArray< T > &v, bool forward)
#define A3D_ELEM(V, k, i, j)
#define DWT_Quadrant1D(i, s, smax)
double compute_noise_power(MultidimArray< double > &I)
#define FOR_ALL_ELEMENTS_IN_MATRIX1D(v)
void apply_mask(const MultidimArray< T > &I, MultidimArray< T > &result, T subs_val=0, bool apply_geo=false)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
std::string Quadrant3D(int q)
void log(Image< double > &op)
void DWT_Bijaoui_denoise_LL2D(MultidimArray< double > &WI, int scale, const std::string &orientation, double mu, double S, double N)
void transpose(double *array, int size)
void DWT(const MultidimArray< T > &v, MultidimArray< double > &result, int isign=1)
Incorrect argument received.
#define DWT_QuadrantnD(i, s, sp, smax)
void write(const FileName &fn) const
#define DWT_Scale(i, smax)
void adaptive_soft_thresholding2D(MultidimArray< double > &I, int scale)
double sum(bool average=false) const
int Wavelet(struct TWaveletStruct *Data)
#define DIRECT_A3D_ELEM(v, k, i, j)
#define BINARY_DWT_CIRCULAR_MASK
__device__ float FFT_IDX2DIGFREQ(int idx, int size)
void power(Image< double > &op)
#define FOR_ALL_ELEMENTS_IN_ARRAY1D(v)
void SelectDWTBlock(int scale, const MultidimArray< T > &I, const std::string &quadrant, int &x1, int &x2)
void generate_mask(bool apply_geo=false)
void getReal(MultidimArray< double > &realImg) const
Matrix1D< double > bayesian_wiener_filtering3D(MultidimArray< double > &WI, int allowed_scale, double SNR0, double SNRF, bool white_noise, int tell, bool denoise)
void write(const FileName &fn) const
std::string Quadrant2D(int q)
const char * BoundaryConditions
void DWT_keep_central_part(MultidimArray< double > &I, double R)
void IDWT(const MultidimArray< double > &v, MultidimArray< double > &result)
void soft_thresholding(MultidimArray< double > &I, double th)
Incorrect MultidimArray dimensions.
#define FOR_ALL_ELEMENTS_IN_ARRAY2D_BETWEEN(corner1, corner2)
void initZeros(const MultidimArray< T1 > &op)
void getImag(MultidimArray< double > &imagImg) const
void DWT_Bijaoui_denoise_LL3D(MultidimArray< double > &WI, int scale, const std::string &orientation, double mu, double S, double N)
Incorrect value received.
#define FOR_ALL_ELEMENTS_IN_ARRAY3D_BETWEEN(corner1, corner2)
void Get_Scale_Quadrant(int size_x, int x, int &scale, std::string &quadrant)
void getDimensions(size_t &Xdim, size_t &Ydim, size_t &Zdim, size_t &Ndim) const