Xmipp  v3.23.11-Nereus
Classes
Normalization of images and volumes
Collaboration diagram for Normalization of images and volumes:

Classes

class  ProgNormalize
 

Image normalization procedures

This functions implement the normalization of a single image. They should be called with all images in the corresponding SelFile. In the following documentation m(x) is the mean of x, v(x) is the variance, bg(x) is its background.

The original image is X and is supposed to be related to each single projection by I=a*(X+n)+b where a and b are different for every projection.

Noise is assumed to follow a gaussian distribution N(0,sqrt(v(n)))

In general the background mask is used only to compute statistics, while the mask is the one which is really applied to the image. Supply NULL if you don't want any mask to be applied

When b is used it is measured as the mean in the background, while a*sqrt(v(n)) is the standard deviation in the same area.

void normalize_OldXmipp (MultidimArray< double > &I)
 
void normalize_Near_OldXmipp (MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
 
void normalize_OldXmipp_decomposition (MultidimArray< double > &I, const MultidimArray< int > &bg_mask, const MultidimArray< double > *mask=nullptr)
 
void normalize_tomography (MultidimArray< double > &I, double tilt, double &mui, double &sigmai, bool tiltMask, bool tomography0=false, double mu0=0, double sigma0=1)
 
void normalize_Michael (MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
 
void normalize_NewXmipp (MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
 
void normalize_NewXmipp2 (MultidimArray< double > &I, const MultidimArray< int > &bg_mask)
 
void normalize_Robust (MultidimArray< double > &I, const MultidimArray< int > &bg_mask, bool clip)
 
void normalize_ramp (MultidimArray< double > &I, MultidimArray< int > *bg_mask=nullptr)
 
void normalize_remove_neighbours (MultidimArray< double > &I, const MultidimArray< int > &bg_mask, const double &threshold)
 

Detailed Description

Function Documentation

◆ normalize_Michael()

void normalize_Michael ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask 
)

Michael's normalization.

Formula:

I'=(I-b)/b

Properties:

m(I')=0 m(bg(I'))=-a*m(x)/b
v(I')=a^2*(v(X)+v(n))/b^2 v(bg(I'))=a^2*v(n)/b^2

Comments: it's not bad but positivity constraints cannot be imposed and the statistical properties are not so good.

Definition at line 230 of file normalize.cpp.

231 {
232  double avg;
233  double stddev;
234  double min=0.;
235  double max;
236  double avgbg;
237  double stddevbg;
238  double minbg;
239  double maxbg;
240  I.computeStats(avg, stddev, min, max);
241  computeStats_within_binary_mask(bg_mask, I, minbg, maxbg, avgbg,
242  stddevbg);
243  if (avgbg > 0)
244  {
245  I -= avgbg;
246  I /= avgbg;
247  }
248  else
249  { // To avoid the contrast inversion
250  I -= (avgbg - min);
251  I /= (avgbg - min);
252  }
253 }
void min(Image< double > &op1, const Image< double > &op2)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
void max(Image< double > &op1, const Image< double > &op2)

◆ normalize_Near_OldXmipp()

void normalize_Near_OldXmipp ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask 
)

Near_OldXmipp normalization.

Formula:

I'=(I-m(I))/sqrt(v(bg))

Properties:

m(I')=0 m(bg(I'))=-m(x)/sqrt(v(n))
v(I')=(v(X)+v(n))/v(n) v(bg(I'))=1

Comments: it's not bad but positivity constraints cannot be imposed

Definition at line 43 of file normalize.cpp.

44 {
45  double avg=0.;
46  double stddev;
47  double min;
48  double max;
49  double avgbg;
50  double stddevbg;
51  double minbg;
52  double maxbg;
53  I.computeStats(avg, stddev, min, max);
54  computeStats_within_binary_mask(bg_mask, I, minbg, maxbg, avgbg,
55  stddevbg);
56  I -= avg;
57  I /= stddevbg;
58 }
void min(Image< double > &op1, const Image< double > &op2)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
void max(Image< double > &op1, const Image< double > &op2)

◆ normalize_NewXmipp()

void normalize_NewXmipp ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask 
)

NewXmipp's normalization.

Formula:

I'=(I-b)/a*sqrt(v(n))
// I''=(I'>0)? I':0
// I'''=I''-a*sqrt(v(n)/2*PI)
I''''=I'''*mask

Properties:

m(I')=m(X)/sqrt(v(n)) m(bg(I'))=0
v(I')=(v(X)+v(n))/v(n) v(bg(I'))=1

Comments: In general, we cannot assure that mass projects into positive numbers, so the "denoising" capability directly on the images is disabled. However, a positivity constraint can be applied on the 3D volume.

Definition at line 255 of file normalize.cpp.

256 {
257  double avgbg;
258  double stddevbg;
259  I.computeAvgStdev_within_binary_mask(bg_mask, avgbg, stddevbg);
260  double istddevbg=1.0/stddevbg;
262  DIRECT_MULTIDIM_ELEM(I,n)=(DIRECT_MULTIDIM_ELEM(I,n)-avgbg)*istddevbg;
263 }
void computeAvgStdev_within_binary_mask(const MultidimArray< int > &mask, double &avg, double &stddev) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ normalize_NewXmipp2()

void normalize_NewXmipp2 ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask 
)

NewXmipp 2's normalization.

Formula:

I'=(I-m(bg))/(m(I)-m(bg))

Properties:

m(I')=m(X)/sqrt(v(n)) m(bg(I'))=0
v(I')=(v(X)+v(n))/v(n) v(bg(I'))=1

Comments: In general, we cannot assure that mass projects into positive numbers, so the "denoising" capability directly on the images is disabled. However, a positivity constraint can be applied on the 3D volume.

Definition at line 315 of file normalize.cpp.

316 {
317  double avg=0;
318  double stddev;
319  double min;
320  double max;
321  double avgbg=0;
322  double stddevbg;
323  double minbg;
324  double maxbg;
325  I.computeStats(avg, stddev, min, max);
326  computeStats_within_binary_mask(bg_mask, I, minbg, maxbg, avgbg,
327  stddevbg);
328  double K=1.0/fabs(avg - avgbg);
331 }
void min(Image< double > &op1, const Image< double > &op2)
void computeStats(double &avg, double &stddev, T &minval, T &maxval) const
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
void max(Image< double > &op1, const Image< double > &op2)
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
constexpr int K
int * n

◆ normalize_OldXmipp()

void normalize_OldXmipp ( MultidimArray< double > &  I)

OldXmipp normalization.

Formula:

I'=(I-m(I))/sqrt(v(I))

Properties:

m(I')=0 m(bg(I'))=-m(x)/sqrt((v(X)+v(n)))
v(I')=1 v(bg(I'))=v(n)/(v(X)+v(n))

Comments: it's not bad but positivity constraints cannot be imposed

Definition at line 33 of file normalize.cpp.

34 {
35  double mean;
36  double std;
37  I.computeAvgStdev(mean,std);
38  double istd=1.0/std;
40  DIRECT_MULTIDIM_ELEM(I,n)=(DIRECT_MULTIDIM_ELEM(I,n)-mean)*istd;
41 }
void computeAvgStdev(U &avg, U &stddev) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
int * n

◆ normalize_OldXmipp_decomposition()

void normalize_OldXmipp_decomposition ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask,
const MultidimArray< double > *  mask = nullptr 
)

OldXmipp decomposition.

Formula:

I'=(I-b)/a*sqrt(v(n))
I''=I'*mask
I'''=(I''-m(I''))/sqrt(v(I''))

Properties:

m(I')=m(X)/sqrt(v(n)) m(bg(I'))=0
v(I')=(v(X)+v(n))/v(n) v(bg(I'))=1

Comments: it's not bad but positivity constraints cannot be imposed. If no mask is applied, then this formula is a beautiful decomposition of the OldXmipp method in two steps.

Definition at line 60 of file normalize.cpp.

62 {
63  double avgbg;
64  double stddevbg;
65  double minbg;
66  double maxbg;
67  computeStats_within_binary_mask(bg_mask, I, minbg, maxbg, avgbg,
68  stddevbg);
69  I -= avgbg;
70  I /= stddevbg;
71  if (mask != nullptr)
72  I *= *mask;
74 }
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
void normalize_OldXmipp(MultidimArray< double > &I)
Definition: normalize.cpp:33

◆ normalize_ramp()

void normalize_ramp ( MultidimArray< double > &  I,
MultidimArray< int > *  bg_mask = nullptr 
)

Removal of inclined background densities (ramps).

fitting of a least squares plane through the pixels in the bg_mask, then subtraction of the plane, and division by the standard deviation of the pixels in the bg_mask

Definition at line 333 of file normalize.cpp.

334 {
335  int Npoints=0; // # points in mask.
336  double pA;
337  double pB;
338  double pC; // Least squares coefficients.
339 
340  // Only 2D ramps implemented
341  I.checkDimension(2);
342 
343  // Check if mask is NULL.
344  if (bg_mask == nullptr)
345  {
346  Npoints = I.xdim*I.ydim;
347  }
348  // Check if mask is not full of 0's.
349  else
350  {
351  Npoints=(int)bg_mask->sum();
352  }
353 
354  // Fit a least squares plane through the background pixels
355  I.setXmippOrigin();
356  if (bg_mask == nullptr)
357  {
358  least_squares_plane_fit_All_Points(I, pA, pB, pC);
359  }
360  else
361  {
362  int idx=0;
363  bg_mask->setXmippOrigin();
364  auto *allpoints=new FitPoint[Npoints];
365 
367  {
368  if (A2D_ELEM( *bg_mask, i, j))
369  {
370  FitPoint &p=allpoints[idx++];
371  p.x = j;
372  p.y = i;
373  p.z = A2D_ELEM(I, i, j);
374  p.w = 1.;
375  }
376  }
377 
378  least_squares_plane_fit(allpoints, Npoints, pA, pB, pC);
379  delete [] allpoints;
380  }
381 
382  // Subtract the plane from the image and compute stddev within mask
383  double sum1 = 0;
384  double sum2 = 0;
385  if (bg_mask == nullptr)
386  {
387  double *ref;
388  for (int i=STARTINGY(I); i<=FINISHINGY(I); i++)
389  {
390  double aux=pB * i + pC;
391  ref = &A2D_ELEM(I, i, STARTINGX(I));
392  for (int j=STARTINGX(I); j<=FINISHINGX(I); j++)
393  {
394  (*ref) -= pA * j + aux;
395  sum1 += (*ref);
396  sum2 += (*ref)*(*ref);
397  ref++;
398  }
399  }
400  }
401  else
402  {
403  for (int i=STARTINGY(I); i<=FINISHINGY(I); i++)
404  {
405  double aux=pB * i + pC;
406  for (int j=STARTINGX(I); j<=FINISHINGX(I); j++)
407  {
408  A2D_ELEM(I, i, j) -= pA * j + aux;
409  if (A2D_ELEM( *bg_mask, i, j))
410  {
411  double aux=A2D_ELEM(I,i,j);
412  sum1 += aux;
413  sum2 += aux*aux;
414  }
415  }
416  }
417  }
418 
419  double avgbg = sum1 / Npoints;
420  double stddevbg = sqrt(fabs(sum2 / Npoints - avgbg * avgbg) * Npoints / (Npoints - 1));
421  if (stddevbg>1e-6)
422  {
423  I *= 1.0/stddevbg;
424  }
425 }
#define A2D_ELEM(v, i, j)
void least_squares_plane_fit(FitPoint *IN_points, int Npoints, double &plane_a, double &plane_b, double &plane_c)
Definition: geometry.cpp:101
#define FINISHINGX(v)
double z
z coordinate, assumed to be a function of x and y
Definition: geometry.h:190
void sqrt(Image< double > &op)
double x
x coordinate
Definition: geometry.h:186
double w
Weight of the point in the Least-Squares problem.
Definition: geometry.h:192
#define STARTINGX(v)
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define STARTINGY(v)
double y
y coordinate
Definition: geometry.h:188
#define j
#define FINISHINGY(v)
double sum() const
void least_squares_plane_fit_All_Points(const MultidimArray< double > &Image, double &plane_a, double &plane_b, double &plane_c)
Definition: geometry.cpp:154

◆ normalize_remove_neighbours()

void normalize_remove_neighbours ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask,
const double &  threshold 
)

Removal of neighbouring particles.

....

Definition at line 427 of file normalize.cpp.

430 {
431  double pA;
432  double pB;
433  double pC;
434  double avgbg;
435  double stddevbg;
436  double minbg;
437  double maxbg;
438  double aux;
439  double newstddev;
440  double sum1 = 0.;
441  double sum2 = 0;
442  int N = 0;
443 
444  // Only implemented for 2D arrays
445  I.checkDimension(2);
446 
447  // Fit a least squares plane through the background pixels
448  auto Npoints=(int)bg_mask.sum();
449  auto *allpoints=new FitPoint[Npoints];
450  I.setXmippOrigin();
451 
452  // Get initial statistics
453  computeStats_within_binary_mask(bg_mask, I, minbg, maxbg, avgbg,stddevbg);
454 
455  // Fit plane through those pixels within +/- threshold*sigma
456  int idx=0;
458  {
459  if (A2D_ELEM(bg_mask, i, j))
460  {
461  if ( fabs(avgbg - A2D_ELEM(I, i, j)) < threshold * stddevbg)
462  {
463  FitPoint &p=allpoints[idx++];
464  p.x = j;
465  p.y = i;
466  p.z = A2D_ELEM(I, i, j);
467  p.w = 1.;
468  }
469  }
470  }
471  least_squares_plane_fit(allpoints, Npoints, pA, pB, pC);
472  delete []allpoints;
473 
474  // Subtract the plane from the image
476  {
477  A2D_ELEM(I, i, j) -= pA * j + pB * i + pC;
478  }
479 
480  // Get std.dev. of the background pixels within +/- threshold*sigma
482  {
483  if (A2D_ELEM(bg_mask, i, j))
484  {
485  if ( ABS(A2D_ELEM(I, i, j)) < threshold * stddevbg)
486  {
487  N++;
488  sum1 += (double) A2D_ELEM(I, i, j);
489  sum2 += ((double) A2D_ELEM(I, i, j)) *
490  ((double) A2D_ELEM(I, i, j));
491  }
492  }
493  }
494  // average and standard deviation
495  if (0 == N) {
496  REPORT_ERROR(ERR_NUMERICAL, "N is zero (0), which would lead to division by zero");
497  }
498  aux = sum1 / (double) N;
499  newstddev = sqrt(fabs(sum2 / N - aux*aux) * N / (N - 1));
500 
501  // Replace pixels outside +/- threshold*sigma by samples from
502  // a gaussian with avg-plane and newstddev
504  {
505  if (A2D_ELEM(bg_mask, i, j))
506  {
507  if ( fabs(A2D_ELEM(I, i, j)) > threshold * stddevbg)
508  {
509  // get local average
510  aux = pA * j + pB * i + pC;
511  A2D_ELEM(I, i, j)=rnd_gaus(aux, newstddev );
512  }
513  }
514  }
515 
516  // Divide the entire image by the new background
517  I /= newstddev;
518 }
#define A2D_ELEM(v, i, j)
void least_squares_plane_fit(FitPoint *IN_points, int Npoints, double &plane_a, double &plane_b, double &plane_c)
Definition: geometry.cpp:101
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
double z
z coordinate, assumed to be a function of x and y
Definition: geometry.h:190
void sqrt(Image< double > &op)
double x
x coordinate
Definition: geometry.h:186
double w
Weight of the point in the Least-Squares problem.
Definition: geometry.h:192
#define i
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
void threshold(double *phi, unsigned long nvox, double limit)
Definition: lib_vwk.cpp:524
Error related to numerical calculation.
Definition: xmipp_error.h:179
#define ABS(x)
Definition: xmipp_macros.h:142
double y
y coordinate
Definition: geometry.h:188
#define j
double rnd_gaus()
double sum() const

◆ normalize_Robust()

void normalize_Robust ( MultidimArray< double > &  I,
const MultidimArray< int > &  bg_mask,
bool  clip 
)

Definition at line 265 of file normalize.cpp.

266 {
267  std::vector<double> voxel_vector;
269 
270  if (bg_mask.computeMax() == 0)
271  {
272  Image<double> mask;
273  mask() = I;
274  static_cast<void>(EntropySegmentation(mask()));
276  {
277  if (DIRECT_MULTIDIM_ELEM(mask(), n) == 0)
278  DIRECT_MULTIDIM_ELEM(bg_mask,n) = 1;
279  }
280  }
281 
283  {
284  if (DIRECT_MULTIDIM_ELEM(bg_mask, n) == 0)
285  voxel_vector.push_back(DIRECT_MULTIDIM_ELEM(I,n));
286  }
287 
288  std::sort(voxel_vector.begin(), voxel_vector.end());
289 
290  double medianBg;
291  double p99;
292  double ip99;
293  int idx;
294  I.computeMedian_within_binary_mask(bg_mask, medianBg);
295  idx = (int)(voxel_vector.size() * 0.99);
296  p99 = voxel_vector[idx];
297  ip99 = 1 / p99;
299  DIRECT_MULTIDIM_ELEM(I,n)=(DIRECT_MULTIDIM_ELEM(I,n) - medianBg) * ip99;
300 
301  if (clip)
302  {
304  if (DIRECT_MULTIDIM_ELEM(I,n) > 1.3284)
305  {
306  DIRECT_MULTIDIM_ELEM(I,n) = 1.3284;
307  }
308  else if (DIRECT_MULTIDIM_ELEM(I,n) < -1.3284)
309  {
310  DIRECT_MULTIDIM_ELEM(I,n) = -1.3284;
311  }
312  }
313 }
void computeMedian_within_binary_mask(const MultidimArray< int > &mask, double &median) const
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY(v)
#define DIRECT_MULTIDIM_ELEM(v, n)
void sort(struct DCEL_T *dcel)
Definition: sorting.cpp:18
#define SPEED_UP_temps
Definition: xmipp_macros.h:419
double EntropySegmentation(MultidimArray< double > &V)
Definition: filters.cpp:1078
int * n
T computeMax() const

◆ normalize_tomography()

void normalize_tomography ( MultidimArray< double > &  I,
double  tilt,
double &  mui,
double &  sigmai,
bool  tiltMask,
bool  tomography0 = false,
double  mu0 = 0,
double  sigma0 = 1 
)

Tomography normalization.

This is similar to the OldXmipp normalization, but the mean and standard deviation of the images are computed only within a region determined by the tilt angle. Formula for tomography:

I'=(I-m(I))/(sqrt(v(I))*cos^2(tilt))

Formula for tomography0:

I'=(I/cos(tilt)-m0)/(sqrt(v(I))*cos(tilt))

The estimated mean of the image and the local variance are returned in sigmai and mui.

Definition at line 77 of file normalize.cpp.

80 {
81  // Tilt series are always 2D
82  I.checkDimension(2);
83 
84  const int L=2;
85 
86  // Build a mask using the tilt angle
87  I.setXmippOrigin();
88  MultidimArray<int> mask;
89  mask.initZeros(I);
90  int Xdimtilt=(int)XMIPP_MIN(FLOOR(0.5*(XSIZE(I)*cos(DEG2RAD(tilt)))),
91  0.5*(XSIZE(I)-(2*L+1)));
92  int N=0;
93  for (int i=STARTINGY(I); i<=FINISHINGY(I); i++)
94  for (int j=-Xdimtilt; j<=Xdimtilt;j++)
95  {
96  A2D_ELEM(mask,i,j)=1;
97  N++;
98  }
99 
100  // Estimate the local variance
101  MultidimArray<double> localVariance;
102  localVariance.initZeros(I);
103  double meanVariance=0;
105  {
106  // Center a mask of size 5x5 and estimate the variance within the mask
107  double meanPiece=0;
108  double variancePiece=0;
109  double Npiece=0;
110  for (int ii=i-L; ii<=i+L; ii++)
111  {
112  if (INSIDEY(I,ii))
113  for (int jj=j-L; jj<=j+L; jj++)
114  {
115  if (INSIDEX(I,jj))
116  {
117  double pixval=A2D_ELEM(I,ii,jj);
118  meanPiece+=pixval;
119  variancePiece+=pixval*pixval;
120  ++Npiece;
121  }
122  }
123  }
124  meanPiece/=Npiece;
125  variancePiece=variancePiece/(Npiece-1)-
126  Npiece/(Npiece-1)*meanPiece*meanPiece;
127  A2D_ELEM(localVariance,i,j)=variancePiece;
128  meanVariance+=variancePiece;
129  }
130  if (0 == N) {
131  REPORT_ERROR(ERR_NUMERICAL, "N is zero (0), which would lead to division by zero");
132  }
133  meanVariance*=1.0/N;
134 
135  // Test the hypothesis that the variance in this piece is
136  // the same as the variance in the whole image
137  double iFu=1/icdf_FSnedecor(4*L*L+4*L,N-1,0.975);
138  double iFl=1/icdf_FSnedecor(4*L*L+4*L,N-1,0.025);
139  double iMeanVariance=1.0/meanVariance;
140  FOR_ALL_ELEMENTS_IN_ARRAY2D(localVariance)
141  {
142  if (A2D_ELEM(localVariance,i,j)==0)
143  A2D_ELEM(mask,i,j)=-2;
144  if (A2D_ELEM(mask,i,j)==1)
145  {
146  double ratio=A2D_ELEM(localVariance,i,j)*iMeanVariance;
147  double thl=ratio*iFu;
148  double thu=ratio*iFl;
149  if (thl>1 || thu<1)
150  A2D_ELEM(mask,i,j)=-1;
151  }
152  }
153 #ifdef DEBUG
154  Image<double> save;
155  save()=I;
156  save.write("PPP.xmp");
157  save()=localVariance;
158  save.write("PPPLocalVariance.xmp");
159  Image<int> savemask;
160  savemask()=mask;
161  savemask.write("PPPmask.xmp");
162 #endif
163 
164  // Compute the statistics again in the reduced mask
165  double avg;
166  double stddev;
167  double min;
168  double max;
169  computeStats_within_binary_mask(mask, I, min, max, avg, stddev);
170  double cosTilt=cos(DEG2RAD(tilt));
171  double iCosTilt=1.0/cosTilt;
172  if (tomography0)
173  {
174  double iadjustedStddev=1.0/(sigma0*cosTilt);
176  switch (A2D_ELEM(mask,i,j))
177  {
178  case -2:
179  A2D_ELEM(I,i,j)=0;
180  break;
181  case 0:
182  if (tiltMask)
183  A2D_ELEM(I,i,j)=0;
184  else
185  A2D_ELEM(I,i,j)=(A2D_ELEM(I,i,j)*iCosTilt-mu0)*iadjustedStddev;
186  break;
187  case -1:
188  case 1:
189  A2D_ELEM(I,i,j)=(A2D_ELEM(I,i,j)*iCosTilt-mu0)*iadjustedStddev;
190  break;
191  }
192  }
193  else
194  {
195  double adjustedStddev=stddev*cosTilt;
196  double iAdjustedStddev=1.0/adjustedStddev;
198  switch (A2D_ELEM(mask,i,j))
199  {
200  case -2:
201  A2D_ELEM(I,i,j)=0;
202  break;
203  case 0:
204  if (tiltMask)
205  A2D_ELEM(I,i,j)=0;
206  else
207  A2D_ELEM(I,i,j)=(A2D_ELEM(I,i,j)-avg)*iAdjustedStddev;
208  break;
209  case -1:
210  case 1:
211  A2D_ELEM(I,i,j)=(A2D_ELEM(I,i,j)-avg)*iAdjustedStddev;
212  break;
213  }
214  }
215 
216  // Prepare values for returning
217  mui=avg;
218  sigmai=sqrt(meanVariance);
219 #ifdef DEBUG
220 
221  save()=I;
222  save.write("PPPafter.xmp");
223  std::cout << "Press any key\n";
224  char c;
225  std::cin >> c;
226 #endif
227 }
#define INSIDEX(v, x)
void min(Image< double > &op1, const Image< double > &op2)
#define A2D_ELEM(v, i, j)
#define REPORT_ERROR(nerr, ErrormMsg)
Definition: xmipp_error.h:211
doublereal * c
#define DEG2RAD(d)
Definition: xmipp_macros.h:312
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)
#define i
void computeStats_within_binary_mask(const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
Definition: mask.h:799
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
#define STARTINGY(v)
#define FLOOR(x)
Definition: xmipp_macros.h:240
#define INSIDEY(v, y)
#define XSIZE(v)
void max(Image< double > &op1, const Image< double > &op2)
Error related to numerical calculation.
Definition: xmipp_error.h:179
double icdf_FSnedecor(int d1, int d2, double p)
#define XMIPP_MIN(x, y)
Definition: xmipp_macros.h:181
#define j
#define FINISHINGY(v)
void initZeros(const MultidimArray< T1 > &op)