78 double &sigmai,
bool tiltMask,
bool tomography0,
79 double mu0,
double sigma0)
91 0.5*(
XSIZE(I)-(2*L+1)));
94 for (
int j=-Xdimtilt;
j<=Xdimtilt;
j++)
103 double meanVariance=0;
108 double variancePiece=0;
110 for (
int ii=
i-L; ii<=
i+L; ii++)
113 for (
int jj=
j-L; jj<=
j+L; jj++)
119 variancePiece+=pixval*pixval;
125 variancePiece=variancePiece/(Npiece-1)-
126 Npiece/(Npiece-1)*meanPiece*meanPiece;
128 meanVariance+=variancePiece;
139 double iMeanVariance=1.0/meanVariance;
146 double ratio=
A2D_ELEM(localVariance,
i,
j)*iMeanVariance;
147 double thl=ratio*iFu;
148 double thu=ratio*iFl;
156 save.
write(
"PPP.xmp");
157 save()=localVariance;
158 save.
write(
"PPPLocalVariance.xmp");
161 savemask.
write(
"PPPmask.xmp");
170 double cosTilt=cos(
DEG2RAD(tilt));
171 double iCosTilt=1.0/cosTilt;
174 double iadjustedStddev=1.0/(sigma0*cosTilt);
195 double adjustedStddev=stddev*cosTilt;
196 double iAdjustedStddev=1.0/adjustedStddev;
218 sigmai=
sqrt(meanVariance);
222 save.
write(
"PPPafter.xmp");
223 std::cout <<
"Press any key\n";
260 double istddevbg=1.0/stddevbg;
267 std::vector<double> voxel_vector;
288 std::sort(voxel_vector.begin(), voxel_vector.end());
295 idx = (int)(voxel_vector.size() * 0.99);
296 p99 = voxel_vector[idx];
328 double K=1.0/fabs(avg - avgbg);
344 if (bg_mask ==
nullptr)
351 Npoints=(int)bg_mask->
sum();
356 if (bg_mask ==
nullptr)
364 auto *allpoints=
new FitPoint[Npoints];
385 if (bg_mask ==
nullptr)
390 double aux=pB *
i + pC;
394 (*ref) -= pA *
j + aux;
396 sum2 += (*ref)*(*ref);
405 double aux=pB *
i + pC;
419 double avgbg = sum1 / Npoints;
420 double stddevbg =
sqrt(fabs(sum2 / Npoints - avgbg * avgbg) * Npoints / (Npoints - 1));
448 auto Npoints=(int)bg_mask.
sum();
449 auto *allpoints=
new FitPoint[Npoints];
461 if ( fabs(avgbg -
A2D_ELEM(I,
i,
j)) < threshold * stddevbg)
498 aux = sum1 / (double) N;
499 newstddev =
sqrt(fabs(sum2 / N - aux*aux) * N / (N - 1));
507 if ( fabs(
A2D_ELEM(I,
i,
j)) > threshold * stddevbg)
510 aux = pA *
j + pB *
i + pC;
526 addUsageLine(
"Change the range of intensity values of pixels.");
527 addUsageLine(
"In general, most of the methods requires a background to separate " 528 "particles from noise");
531 addParamsLine(
" [--method <mth=NewXmipp>] : Normalizing method.");
534 addParamsLine(
" : Avg(I)=0, Stddev(I)=1, does not need background");
538 addParamsLine(
" : Positivity constraints can be added in reconstruction");
539 addParamsLine(
" Tomography : I=(I-mean(I))/(stddev(I)*cos(tilt))");
540 addParamsLine(
" : does not need background, it assumes the tilt series is vertically aligned");
541 addParamsLine(
" : Similar to OldXmipp but with an extra division by the cos(tilt)");
542 addParamsLine(
" Tomography0 : I=(I-mean(I(0 degrees)))/(stddev(I)*cos(tilt))");
544 addParamsLine(
" : Similar to Tomography but the average at 0 degrees is used for all images");
551 addParamsLine(
" Neighbour : Replace pixels in the background with random noise");
553 addParamsLine(
" [--thr_black_dust <sblack=-3.5>] : Remove black dust particles with sigma threshold sblack.");
554 addParamsLine(
" [--thr_white_dust <swhite=3.5>] : Remove white dust particles with sigma threshold swhite.");
555 addParamsLine(
" [--thr_neigh <value=1.2>] : Sigma threshold for neighbour removal.");
556 addParamsLine(
" [--prm <a0> <aF> <b0> <bF>] : Requires --method Random. I=aI+b.");
557 addParamsLine(
" [--clip] : Requires --method Robust. Constrain maximum values in normalize volume.");
559 addParamsLine(
" [--tiltMask] : Apply a mask depending on the tilt");
560 addParamsLine(
" : requires --method Tomography or Tomography0");
563 addParamsLine(
" frame <r> : Rectangular background of r pixels.");
564 addParamsLine(
" circle <r> : Circular background outside radius r.");
567 addExampleLine(
"xmipp_transform_normalize -i images.sel --method OldXmipp",
true);
568 addExampleLine(
"Normalize 64x64 images using NewXmipp method",
false);
569 addExampleLine(
"xmipp_transform_normalize -i images.sel --method NewXmipp --background circle 29",
true);
570 addExampleLine(
"Normalize 64x64 images using NewXmipp method and a crown mask",
false);
571 addExampleLine(
"xmipp_transform_normalize -i images.sel --method NewXmipp --mask crown 29 32",
true);
572 addExampleLine(
"Normalize a volume to have zero mean and unit variance",
false);
573 addExampleLine(
"xmipp_transform_normalize -i volume.vol --method OldXmipp",
true);
574 addExampleLine(
"Normalize a volume so that the noise outside a sphere of radius 29 has zero mean and unit variance",
false);
575 addExampleLine(
"xmipp_transform_normalize -i volume.vol --background circle 29",
true);
586 if (aux ==
"OldXmipp")
588 else if (aux ==
"Near_OldXmipp")
590 else if (aux ==
"NewXmipp")
592 else if (aux ==
"NewXmipp2")
594 else if (aux ==
"Robust")
596 else if (aux ==
"Michael")
598 else if (aux ==
"Random")
600 else if (aux ==
"None")
602 else if (aux ==
"Ramp")
604 else if (aux ==
"Neighbour")
606 else if (aux ==
"Tomography")
608 else if (aux ==
"Tomography0")
644 "Normalize: --background or --mask parameter required.");
651 else if (aux ==
"circle")
672 "Normalize_parameters: -prm parameter required.");
685 std::cout <<
"Normalizing method: ";
689 std::cout <<
"OldXmipp\n";
692 std::cout <<
"Near_OldXmipp\n";
695 std::cout <<
"NewXmipp\n";
698 std::cout <<
"NewXmipp2\n";
701 std::cout <<
"Robust\n";
704 std::cout <<
"Michael\n";
707 std::cout <<
"None\n";
710 std::cout <<
"Ramp\n";
713 std::cout <<
"Neighbour\n";
716 std::cout <<
"Tomography\n";
719 std::cout <<
"Tomography0\n";
722 std::cout <<
"Random a=[" <<
a0 <<
"," <<
aF <<
"], " <<
"b=[" <<
723 b0 <<
"," <<
bF <<
"]\n";
731 std::cout <<
"Background mode: ";
735 std::cout <<
"None\n";
738 std::cout <<
"Frame, width=" <<
r << std::endl;
739 std::cout <<
"Apply transformation to mask: " <<
apply_geo <<
743 std::cout <<
"Circle, radius=" <<
r << std::endl;
744 std::cout <<
"Apply transformation to mask: " <<
apply_geo <<
751 std::cout <<
"Invert contrast "<< std::endl;
754 std::cout <<
"Applying a mask depending on tilt "<< std::endl;
757 std::cout <<
"Remove black dust particles, using threshold " <<
761 std::cout <<
"Remove white dust particles, using threshold " <<
804 tt.
write(
"PPPmask.xmp");
805 std::cerr<<
"DEBUG info: written PPPmask.xmp"<<std::endl;
812 double bestTilt=1000;
818 for (
size_t objId: md->
ids())
830 if (tiltTemp < bestTilt)
854 I().setXmippOrigin();
862 img.checkDimension(2);
void processImage(const FileName &fnImg, const FileName &fnImgOut, const MDRow &rowIn, MDRow &rowOut)
void min(Image< double > &op1, const Image< double > &op2)
#define A2D_ELEM(v, i, j)
void normalize_NewXmipp(MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
double getDoubleParam(const char *param, int arg=0)
void normalize_Michael(MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
void least_squares_plane_fit(FitPoint *IN_points, int Npoints, double &plane_a, double &plane_b, double &plane_c)
#define REPORT_ERROR(nerr, ErrormMsg)
void resizeNoCopy(const MultidimArray< T1 > &v)
double z
z coordinate, assumed to be a function of x and y
void sqrt(Image< double > &op)
void BinaryCircularMask(MultidimArray< int > &mask, double radius, int mode, double x0, double y0, double z0)
void normalize_tomography(MultidimArray< double > &I, double tilt, double &mui, double &sigmai, bool tiltMask, bool tomography0, double mu0, double sigma0)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void normalize_Near_OldXmipp(MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
#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)
void computeAvgStdev(U &avg, U &stddev) const
void normalize_OldXmipp_decomposition(MultidimArray< double > &I, const MultidimArray< int > &bg_mask, const MultidimArray< double > *mask)
double w
Weight of the point in the Least-Squares problem.
String floatToString(float F, int _width, int _prec)
void computeAvgStdev_within_binary_mask(const MultidimArray< int > &mask, double &avg, double &stddev) const
int readApplyGeo(const FileName &name, const MDRow &row, const ApplyGeoParams ¶ms=DefaultApplyGeoParams)
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 computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
static void defineParams(XmippProgram *program, int allowed_data_types=ALL_KINDS, const char *prefix=nullptr, const char *comment=nullptr, bool moreOptions=false)
double tilt(const size_t n=0) const
void addKeywords(const char *keywords)
void threshold(double *phi, unsigned long nvox, double limit)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
void computeMedian_within_binary_mask(const MultidimArray< int > &mask, double &median) const
const char * getParam(const char *param, int arg=0)
void normalize_ramp(MultidimArray< double > &I, MultidimArray< int > *bg_mask)
Incorrect argument received.
void normalize_remove_neighbours(MultidimArray< double > &I, const MultidimArray< int > &bg_mask, const double &threshold)
void normalize_Robust(MultidimArray< double > &I, const MultidimArray< int > &bg_mask, bool clip)
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
Error related to numerical calculation.
double icdf_FSnedecor(int d1, int d2, double p)
#define DIRECT_MULTIDIM_ELEM(v, n)
void addExampleLine(const char *example, bool verbatim=true)
void readParams(XmippProgram *program)
BackgroundMode background_mode
MultidimArray< int > bg_mask
void sort(struct DCEL_T *dcel)
void generate_mask(bool apply_geo=false)
MultidimArray< int > bg_mask_bck
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
void normalize_NewXmipp2(MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
bool checkParam(const char *param)
constexpr int OUTSIDE_MASK
void getTransformationMatrix(Matrix2D< double > &A, bool only_apply_shifts=false, const size_t n=0)
int read(const FileName &name, DataMode datamode=DATA, size_t select_img=ALL_IMAGES, bool mapData=false, int mode=WRITE_READONLY)
MultidimArray< int > imask
void normalize_OldXmipp(MultidimArray< double > &I)
double EntropySegmentation(MultidimArray< double > &V)
void addUsageLine(const char *line, bool verbatim=false)
void initZeros(const MultidimArray< T1 > &op)
int getIntParam(const char *param, int arg=0)
Incorrect value received.
int readMapped(const FileName &name, size_t select_img=ALL_IMAGES, int mode=WRITE_READONLY)
void addParamsLine(const String &line)
void BinaryFrameMask(MultidimArray< int > &mask, int Xrect, int Yrect, int Zrect, int mode, double x0, double y0, double z0)
void least_squares_plane_fit_All_Points(const MultidimArray< double > &Image, double &plane_a, double &plane_b, double &plane_c)
double tilt(const size_t n=0) const