Xmipp  v3.23.11-Nereus
Classes | Functions | Variables
Collaboration diagram for Masks:

Classes

class  Mask
 
class  ProgMask
 

Functions

void apply_geo_binary_2D_mask (MultidimArray< int > &mask, const Matrix2D< double > &A)
 
void apply_geo_cont_2D_mask (MultidimArray< double > &mask, const Matrix2D< double > &A)
 

Variables

constexpr int INNER_MASK = 1
 
constexpr int OUTSIDE_MASK = 2
 
constexpr int NO_ACTIVATE = 0
 
constexpr int ACTIVATE = 1
 

Actual masks

void RaisedCosineMask (MultidimArray< double > &mask, double r1, double r2, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void RaisedCrownMask (MultidimArray< double > &mask, double r1, double r2, double pix_width, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void KaiserMask (MultidimArray< double > &mask, double delta=0.01, double Deltaw=1.0/12.0)
 
void SincMask (MultidimArray< double > &mask, double omega, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void SincKaiserMask (MultidimArray< double > &mask, double omega, double delta=0.01, double Deltaw=1.0/12.0)
 
void BlackmanMask (MultidimArray< double > &mask, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void SincBlackmanMask (MultidimArray< double > &mask, double omega, double power_percentage, double x0=0, double y0=0, double z0=0)
 
void BinaryCircularMask (MultidimArray< int > &mask, double radius, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void BlobCircularMask (MultidimArray< double > &mask, double r1, blobtype blob, int mode, double x0=0, double y0=0, double z0=0)
 
void BinaryCrownMask (MultidimArray< int > &mask, double R1, double R2, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void BlobCrownMask (MultidimArray< double > &mask, double r1, double r2, blobtype blob, int mode, double x0=0, double y0=0, double z0=0)
 
void GaussianMask (MultidimArray< double > &mask, double sigma, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void BinaryDWTCircularMask2D (MultidimArray< int > &mask, double radius, int smin, int smax, const std::string &quadrant)
 
void SeparableSincKaiserMask2D (MultidimArray< double > &mask, double omega, double delta=0.01, double Deltaw=1.0/12.0)
 
void mask2D_4neig (MultidimArray< int > &mask, int value=1, int center=NO_ACTIVATE)
 
void mask2D_8neig (MultidimArray< int > &mask, int value1=1, int value2=1, int center=NO_ACTIVATE)
 
void BinaryDWTSphericalMask2D (MultidimArray< int > &mask, double radius, int smin, int smax, const std::string &quadrant)
 
void BinaryCylinderMask (MultidimArray< int > &mask, double R, double H, int mode=INNER_MASK, double x0=0, double y0=0, int z0=0)
 
void BinaryFrameMask (MultidimArray< int > &mask, int Xrect, int Yrect, int Zrect, int mode=INNER_MASK, double x0=0, double y0=0, double z0=0)
 
void BinaryConeMask (MultidimArray< int > &mask, double theta, int mode=INNER_MASK, bool centerOrigin=false)
 
void BinaryWedgeMask (MultidimArray< int > &mask, double theta0, double thetaF, const Matrix2D< double > &A, bool centerOrigin=false)
 
void mask3D_6neig (MultidimArray< int > &mask, int value=1, int center=NO_ACTIVATE)
 
void mask3D_18neig (MultidimArray< int > &mask, int value1=1, int value2=1, int center=NO_ACTIVATE)
 
void mask3D_26neig (MultidimArray< int > &mask, int value1=1, int value2=1, int value3=1, int center=NO_ACTIVATE)
 

Mask Tools

All Mask tools work only in the overlapping area of the given image/volume and the mask in logical coordinates. Ie, if you have a mask defined from -2 to 2 and you apply it to an image defined from 0 to 63 then only those values of the mask between 0 and 2 will be applied. The rest of the image will remain untouched. This region where the mask is active within the overlapping area will be called in this documentation: active area.

constexpr int COUNT_ABOVE = 1
 
constexpr int COUNT_BELOW = 2
 
constexpr int COUNT_BETWEEN = 3
 
template<typename T1 , typename T >
void computeStats_within_binary_mask (const MultidimArray< T1 > &mask, const MultidimArray< T > &m, double &min_val, double &max_val, double &avg, double &stddev)
 
void computeStats_within_binary_mask (const MultidimArray< int > &mask, const MultidimArrayGeneric &m, double &min_val, double &max_val, double &avg, double &stddev)
 
template<typename T >
void apply_binary_mask (const MultidimArray< int > &mask, const MultidimArray< T > &m_in, MultidimArray< T > &m_out, T subs_val=(T) 0)
 
template<typename T >
void apply_cont_mask (const MultidimArray< double > &mask, const MultidimArray< T > &m_in, MultidimArray< T > &m_out)
 
template<typename T >
void compute_hist_within_binary_mask (const MultidimArray< int > &mask, MultidimArray< T > &v, Histogram1D &hist, int no_steps)
 
template<typename T >
void compute_hist_within_binary_mask (const MultidimArray< int > &mask, const MultidimArray< T > &v, Histogram1D &hist, T min, T max, int no_steps)
 
template<typename T >
int count_with_mask (const MultidimArray< int > &mask, const MultidimArray< T > &m, int mode, double th1, double th2)
 
int count_with_mask (const MultidimArray< int > &mask, const MultidimArray< std::complex< double > > &m, int mode, double th1, double th2)
 
template<typename T >
void invert_binary_mask (MultidimArray< T > &mask)
 
void rangeAdjust_within_mask (const MultidimArray< double > *mask, const MultidimArray< double > &m1, MultidimArray< double > &m2)
 
#define count_with_mask_above(mask, m, th)   count_with_mask(mask, m, COUNT_ABOVE, th, 0);
 
#define count_with_mask_below(mask, m, th)   count_with_mask(mask, m, COUNT_BELOW, th, 0);
 
#define count_with_mask_between(mask, m, th1, th2)   count_with_mask(mask, m, COUNT_BETWEEN, th1, th2);
 

Detailed Description

Macro Definition Documentation

◆ count_with_mask_above

#define count_with_mask_above (   mask,
  m,
  th 
)    count_with_mask(mask, m, COUNT_ABOVE, th, 0);

Count pixels/voxels with mask and above a threshold

Those pixels within the mask with a value greater or equal than a threshold are counted. This function makes a call to count_with_mask

Definition at line 951 of file mask.h.

◆ count_with_mask_below

#define count_with_mask_below (   mask,
  m,
  th 
)    count_with_mask(mask, m, COUNT_BELOW, th, 0);

Count pixels/voxels with mask and below a threshold

Those pixels within the mask with a value smaller or equal than a threshold are counted. This function makes a call to count_with_mask

Definition at line 959 of file mask.h.

◆ count_with_mask_between

#define count_with_mask_between (   mask,
  m,
  th1,
  th2 
)    count_with_mask(mask, m, COUNT_BETWEEN, th1, th2);

Count pixels/voxels with mask and between two thresholds

Those pixels within the mask with a value greater or equal than th1 and smaller or equal than th2 are counted. This function makes a call to count_with_mask

Definition at line 968 of file mask.h.

Function Documentation

◆ apply_binary_mask()

template<typename T >
void apply_binary_mask ( const MultidimArray< int > &  mask,
const MultidimArray< T > &  m_in,
MultidimArray< T > &  m_out,
subs_val = (T) 0 
)

Apply mask to a MultidimArray

The volume values for which the input mask is 0 are set to 0. The input and output volumes can be the same ones.

Definition at line 857 of file mask.h.

859 {
860  m_out.resize(m_in);
862  // If in common with the mask
863  if (k >= STARTINGZ(mask) && k <= FINISHINGZ(mask) &&
864  i >= STARTINGY(mask) && i <= FINISHINGY(mask) &&
865  j >= STARTINGX(mask) && j <= FINISHINGX(mask))
866  if (A3D_ELEM(mask, k, i, j) == 0)
867  A3D_ELEM(m_out, k, i, j) = subs_val;
868  else
869  A3D_ELEM(m_out, k, i, j) = A3D_ELEM(m_in, k, i, j);
870  // It is not in common, leave the original one
871  else
872  A3D_ELEM(m_out, k, i, j) = A3D_ELEM(m_in, k, i, j);
873 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define FINISHINGX(v)
#define FINISHINGZ(v)
#define STARTINGX(v)
#define i
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 STARTINGY(v)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define j
#define FINISHINGY(v)
#define STARTINGZ(v)

◆ apply_cont_mask()

template<typename T >
void apply_cont_mask ( const MultidimArray< double > &  mask,
const MultidimArray< T > &  m_in,
MultidimArray< T > &  m_out 
)

Apply continuous mask to a MultidimArray

The image is multiplied by the mask. The input and output matrices can be the same ones. Only the overlapping values are affected by the mask.

Definition at line 881 of file mask.h.

883 {
884  m_out.resize(m_in);
886  // If in common with the mask
887  if ((k >= STARTINGZ(mask)) && (k <= FINISHINGZ(mask)) &&
888  (i >= STARTINGY(mask)) && (i <= FINISHINGY(mask)) &&
889  (j >= STARTINGX(mask) && j <= FINISHINGX(mask)))
890  {
891  A3D_ELEM(m_out, k, i, j) = (T)(A3D_ELEM(m_in, k, i, j) * A3D_ELEM(mask, k, i, j));
892  }
893  // It is not in common, leave the original one
894  else
895  A3D_ELEM(m_out, k, i, j) = A3D_ELEM(m_in, k, i, j);
896 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define FINISHINGX(v)
#define FINISHINGZ(v)
#define STARTINGX(v)
#define i
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 STARTINGY(v)
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define j
#define FINISHINGY(v)
#define STARTINGZ(v)

◆ apply_geo_binary_2D_mask()

void apply_geo_binary_2D_mask ( MultidimArray< int > &  mask,
const Matrix2D< double > &  A 
)

Apply geometric transformation to a binary (2D) mask

Definition at line 1682 of file mask.cpp.

1684 {
1686  tmp.resize(mask);
1687  typeCast(mask, tmp);
1688  double outside = DIRECT_A2D_ELEM(tmp, 0, 0);
1689  MultidimArray<double> tmp2;
1690  tmp2 = tmp;
1691  // Instead of IS_INV for images use IS_NOT_INV for masks!
1692  applyGeometry(xmipp_transformation::LINEAR, tmp, tmp2, A, xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, outside);
1693  // The type cast gives strange results here, using round instead
1694  //typeCast(tmp, mask);
1696  {
1697  dAij(mask,i,j)=ROUND(dAij(tmp,i,j));
1698  // std::cout << "i, j = " << i << "," << j <<std::endl;
1699  }
1700 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define FOR_ALL_DIRECT_ELEMENTS_IN_ARRAY2D(m)
#define dAij(M, i, j)
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
#define DIRECT_A2D_ELEM(v, i, j)
#define i
#define ROUND(x)
Definition: xmipp_macros.h:210
#define j
void typeCast(const Matrix1D< T1 > &v1, Matrix1D< T2 > &v2)
Definition: matrix1d.h:1227

◆ apply_geo_cont_2D_mask()

void apply_geo_cont_2D_mask ( MultidimArray< double > &  mask,
const Matrix2D< double > &  A 
)

Apply geometric transformation to a continuous (2D) mask

Definition at line 1703 of file mask.cpp.

1705 {
1706  double outside = DIRECT_A2D_ELEM(mask, 0, 0);
1707  MultidimArray<double> tmp = mask;
1708  // Instead of IS_INV for images use IS_NOT_INV for masks!
1709  applyGeometry(xmipp_transformation::LINEAR, tmp, mask, A, xmipp_transformation::IS_NOT_INV, xmipp_transformation::DONT_WRAP, outside);
1710 }
void applyGeometry(int SplineDegree, MultidimArray< std::complex< double > > &V2, const MultidimArray< std::complex< double > > &V1, const Matrix2D< double > &A, bool inv, bool wrap, std::complex< double > outside, MultidimArray< double > *BcoeffsPtr)
#define DIRECT_A2D_ELEM(v, i, j)

◆ BinaryCircularMask()

void BinaryCircularMask ( MultidimArray< int > &  mask,
double  radius,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a circular mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the radius indicated. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 193 of file mask.cpp.

195 {
196  mask.initZeros();
197  double radius2 = radius * radius;
198  for (int k=STARTINGZ(mask); k<=FINISHINGZ(mask); ++k)
199  {
200  double diff=k - z0;
201  double z2=diff*diff;
202  for (int i=STARTINGY(mask); i<=FINISHINGY(mask); ++i)
203  {
204  diff=i - y0;
205  double z2y2=z2+diff*diff;
206  for (int j=STARTINGX(mask); j<=FINISHINGX(mask); ++j)
207  {
208  diff=j - x0;
209  double r2 = z2y2+diff*diff;
210  if (r2 <= radius2 && mode == INNER_MASK)
211  A3D_ELEM(mask, k, i, j) = 1;
212  else if (r2 >= radius2 && mode == OUTSIDE_MASK)
213  A3D_ELEM(mask, k, i, j) = 1;
214  }
215  }
216  }
217 }
#define FINISHINGX(v)
#define z0
#define FINISHINGZ(v)
#define STARTINGX(v)
#define i
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 STARTINGY(v)
#define A3D_ELEM(V, k, i, j)
#define y0
#define x0
void mode
#define j
#define FINISHINGY(v)
constexpr int OUTSIDE_MASK
Definition: mask.h:48
float r2
void initZeros(const MultidimArray< T1 > &op)
#define STARTINGZ(v)
double radius
Spatial radius in Universal System units.
Definition: blobs.h:115
constexpr int INNER_MASK
Definition: mask.h:47

◆ BinaryConeMask()

void BinaryConeMask ( MultidimArray< int > &  mask,
double  theta,
int  mode = INNER_MASK,
bool  centerOrigin = false 
)

Creates a 3D cone mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A cone with angle theta is placed parallel to the Z-axis and centered at (x0,y0,z0). The only two valid modes are INNER_MASK (by default, inside the crown is zero, outside is 1) or OUTSIDE_MASK (the negative of the crown).

When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 488 of file mask.cpp.

489 {
490  int halfX = mask.xdim/2;
491  int halfY = mask.ydim/2;
492  int halfZ = mask.zdim/2;
493 
494  int minX = -halfX;
495  int minY = -halfY;
496  int minZ = -halfZ;
497 
498  int maxX = (int)((mask.xdim-0.5)/2);
499  int maxY = (int)((mask.ydim-0.5)/2);
500  int maxZ = (int)((mask.zdim-0.5)/2);
501 
503  {
504  int kpp = k;
505  int ipp = i;
506  int jpp = j;
507  if (centerOrigin)
508  {
509  kpp = intWRAP (k+halfZ,minZ,maxZ);
510  ipp = intWRAP (i+halfY,minY,maxY);
511  jpp = intWRAP (j+halfX,minX,maxX);
512  }
513 
514  double rad = tan(PI * theta / 180.) * (double)k;
515  if ((double)(i*i + j*j) < (rad*rad))
516  A3D_ELEM(mask, kpp, ipp, jpp) = 0;
517  else
518  A3D_ELEM(mask, kpp, ipp, jpp) = 1;
519  if (mode == OUTSIDE_MASK)
520  A3D_ELEM(mask, kpp, ipp, jpp) = 1 - A3D_ELEM(mask, kpp, ipp, jpp);
521  }
522 }
#define i
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
double theta
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
#define PI
Definition: tools.h:43
#define intWRAP(x, x0, xF)
Definition: xmipp_macros.h:272

◆ BinaryCrownMask()

void BinaryCrownMask ( MultidimArray< int > &  mask,
double  R1,
double  R2,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a crown mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the two radii indicated. The only two valid modes are INNER_MASK (by default, between the two radii) or OUTSIDE_MASK (the negative of the crown). It is supposed that R1 is smaller than R2.

When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 244 of file mask.cpp.

246 {
247  mask.initZeros();
248  double R12 = R1 * R1;
249  double R22 = R2 * R2;
251  {
252  double r2 = (k - z0) * (k - z0) + (i - y0) * (i - y0) + (j - x0) * (j - x0);
253  bool in_crown = (r2 >= R12 && r2 <= R22);
254  if (in_crown && mode == INNER_MASK)
255  A3D_ELEM(mask, k, i, j) = 1;
256  else if (!in_crown && mode == OUTSIDE_MASK)
257  A3D_ELEM(mask, k, i, j) = 1;
258  }
259 }
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
float r2
void initZeros(const MultidimArray< T1 > &op)
constexpr int INNER_MASK
Definition: mask.h:47

◆ BinaryCylinderMask()

void BinaryCylinderMask ( MultidimArray< int > &  mask,
double  R,
double  H,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
int  z0 = 0 
)

Creates a 3D Cylinder mask for already sized masks

The mask is supposed to be already resized and with its logical origin defined. A cylinder placed logically at (z0,x0,y0), by default (0,0,0), is created with the radius and height indicated. The only two valid modes ar INNER_MASK (by default) or OUTSIDE_MASK. When entering the mask is initialiazed to 0 and then the mask is created.

◆ BinaryDWTCircularMask2D()

void BinaryDWTCircularMask2D ( MultidimArray< int > &  mask,
double  radius,
int  smin,
int  smax,
const std::string &  quadrant 
)

Binary Circular 2D mask in wavelet space

Definition at line 356 of file mask.cpp.

358 {
359  double radius2 = radius * radius / (4 * (smin + 1));
360  mask.initZeros();
361  for (int s = smin; s <= smax; s++)
362  {
363  Matrix1D<int> corner1(2);
364  Matrix1D<int> corner2(2);
365  Matrix1D<int> r(2);
366  Matrix1D<double> center(2);
367  if (quadrant == "xx")
368  {
369  DWTCIRCULAR2D_BLOCK(s, "01");
370  DWTCIRCULAR2D_BLOCK(s, "10");
371  DWTCIRCULAR2D_BLOCK(s, "11");
372  }
373  else
374  DWTCIRCULAR2D_BLOCK(s, quadrant);
375  radius2 /= 4;
376  }
377 }
#define DWTCIRCULAR2D_BLOCK(s, quadrant)
Definition: mask.cpp:346
void initZeros(const MultidimArray< T1 > &op)
double radius
Spatial radius in Universal System units.
Definition: blobs.h:115

◆ BinaryDWTSphericalMask2D()

void BinaryDWTSphericalMask2D ( MultidimArray< int > &  mask,
double  radius,
int  smin,
int  smax,
const std::string &  quadrant 
)

Creates a 3D DWT spherical for already sized masks

The mask size must be a power of 2. The radius must be expressed in pixel units corresponding to the size of the image. For instance, a 64x64x64 image might have a radius of 32 pixels to concentrate on the central part only.

If quadrant=xxx then 001,010,011,100,101,110 and 111 are generated together

◆ BinaryFrameMask()

void BinaryFrameMask ( MultidimArray< int > &  mask,
int  Xrect,
int  Yrect,
int  Zrect,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a 3D frame mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A square placed logically at (x0,y0,z0), by default (0,0,0), is created with the two rectangular dimensions indicated. The only two valid modes are INNER_MASK (by default, between the two radii) or OUTSIDE_MASK (the negative of the crown). It is supposed that R1 is smaller than R2.

When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 309 of file mask.cpp.

311 {
312  mask.initZeros();
314  {
315  bool in_frame =
316  (j >= x0 + FIRST_XMIPP_INDEX(Xrect)) && (j <= x0 + LAST_XMIPP_INDEX(Xrect)) &&
317  (i >= y0 + FIRST_XMIPP_INDEX(Yrect)) && (i <= y0 + LAST_XMIPP_INDEX(Yrect)) &&
318  (k >= z0 + FIRST_XMIPP_INDEX(Zrect)) && (k <= z0 + LAST_XMIPP_INDEX(Zrect));
319 
320  if ((in_frame && mode == INNER_MASK) || (!in_frame && mode == OUTSIDE_MASK))
321  A3D_ELEM(mask, k, i, j) = 1;
322  }
323 }
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
#define FIRST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:439
constexpr int OUTSIDE_MASK
Definition: mask.h:48
void initZeros(const MultidimArray< T1 > &op)
#define LAST_XMIPP_INDEX(size)
Definition: xmipp_macros.h:448
constexpr int INNER_MASK
Definition: mask.h:47

◆ BinaryWedgeMask()

void BinaryWedgeMask ( MultidimArray< int > &  mask,
double  theta0,
double  thetaF,
const Matrix2D< double > &  A,
bool  centerOrigin = false 
)

Creates a 3D missing wedge mask

The mask is supposed to be resized and with its logical origin already set. theta0 and thetaF are the tilting angles (around the Y-axis) wherin between the data is supposed to be collected. In this region the mask will be one, outside (ie in the missing wedge) it will be zero. The mask is centered at (x0,y0,z0), and rotated with respect to euler angle matrix A.

Definition at line 524 of file mask.cpp.

526 {
527  int halfX = mask.xdim/2;
528  int halfY = mask.ydim/2;
529  int halfZ = mask.zdim/2;
530 
531  int minX = -halfX;
532  int minY = -halfY;
533  int minZ = -halfZ;
534 
535  int maxX = (int)((mask.xdim-0.5)/2);
536  int maxY = (int)((mask.ydim-0.5)/2);
537  int maxZ = (int)((mask.zdim-0.5)/2);
538 
539  auto tg0 = -tan(PI * (-90. - thetaF) / 180.);
540  auto tgF = -tan(PI * (90. - theta0) / 180.);
541  if (ABS(tg0) < XMIPP_EQUAL_ACCURACY)
542  tg0=0.;
543  if (ABS(tgF) < XMIPP_EQUAL_ACCURACY)
544  tgF=0.;
545  // ROB: A=A.inv(); A no const
547  {
548  auto di=(double)i;
549  auto dj=(double)j;
550  auto dk=(double)k;
551  auto xp = MAT_ELEM(A, 0, 0) * dj + MAT_ELEM(A, 0, 1) * di + MAT_ELEM(A, 0, 2) * dk;
552  auto zp = MAT_ELEM(A, 2, 0) * dj + MAT_ELEM(A, 2, 1) * di + MAT_ELEM(A, 2, 2) * dk;
553 
554  int kpp = k;
555  int ipp = i;
556  int jpp = j;
557 
558  if (centerOrigin)
559  {
560  kpp = intWRAP (k+halfZ,minZ,maxZ);
561  ipp = intWRAP (i+halfY,minY,maxY);
562  jpp = intWRAP (j+halfX,minX,maxX);
563  }
564 
565  auto limx0 = tg0 * zp;// + 0.5;
566  auto limxF = tgF * zp;// + 0.5;
567  if (zp >= 0)
568  {
569  if (xp <= limx0 || xp >= limxF)
570  {
571  A3D_ELEM(mask, kpp, ipp, jpp) = 1;
572  }
573  else
574  A3D_ELEM(mask, kpp, ipp, jpp) = 0;
575  }
576  else
577  {
578  if (xp <= limxF || xp >= limx0)
579  {
580  A3D_ELEM(mask, kpp, ipp, jpp) = 1;
581  }
582  else
583  A3D_ELEM(mask, kpp, ipp, jpp) = 0;
584  }
585  }
586 }
double * di
#define i
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 MAT_ELEM(m, i, j)
Definition: matrix2d.h:116
#define A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define XMIPP_EQUAL_ACCURACY
Definition: xmipp_macros.h:119
#define ABS(x)
Definition: xmipp_macros.h:142
#define j
#define PI
Definition: tools.h:43
#define intWRAP(x, x0, xF)
Definition: xmipp_macros.h:272

◆ BlackmanMask()

void BlackmanMask ( MultidimArray< double > &  mask,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Blackman selfWindow

It receives no parameter.

Definition at line 151 of file mask.cpp.

153 {
154  double Xdim2 = XMIPP_MAX(1, (XSIZE(mask) - 1) * (XSIZE(mask) - 1));
155  double Ydim2 = XMIPP_MAX(1, (YSIZE(mask) - 1) * (YSIZE(mask) - 1));
156  double Zdim2 = XMIPP_MAX(1, (ZSIZE(mask) - 1) * (ZSIZE(mask) - 1));
158  {
159  double r = sqrt((k - z0) * (k - z0) / Zdim2 + (i - y0) * (i - y0) / Xdim2 + (j - x0) * (j - x0) / Ydim2);
160  A3D_ELEM(mask, k, i, j) = 0.42 + 0.5 * cos(2 * PI * r) + 0.08 * cos(4 * PI * r);
161  if (mode == OUTSIDE_MASK)
162  A3D_ELEM(mask, k, i, j) = 1 - A3D_ELEM(mask, k, i, j);
163  }
164 }
#define YSIZE(v)
#define XMIPP_MAX(x, y)
Definition: xmipp_macros.h:193
void sqrt(Image< double > &op)
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
#define XSIZE(v)
#define ZSIZE(v)
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
#define PI
Definition: tools.h:43

◆ BlobCircularMask()

void BlobCircularMask ( MultidimArray< double > &  mask,
double  r1,
blobtype  blob,
int  mode,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a circular mask with blob-shaped edges for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the radius indicated. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 219 of file mask.cpp.

222 {
224  {
225  double r = sqrt((k - z0) * (k - z0) + (i - y0) * (i - y0) + (j - x0) * (j - x0));
226  if (mode == INNER_MASK)
227  {
228  if (r <= r1)
229  A3D_ELEM(mask, k, i, j) = 1;
230  else
231  A3D_ELEM(mask, k, i, j) = blob_val(r-r1, blob);
232  }
233  else
234  {
235  if (r >= r1)
236  A3D_ELEM(mask, k, i, j) = 1;
237  else
238  A3D_ELEM(mask, k, i, j) = blob_val(r1-r, blob);
239  }
240  }
241 
242 }
void sqrt(Image< double > &op)
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
#define blob_val(r, blob)
Definition: blobs.h:139
float r1
constexpr int INNER_MASK
Definition: mask.h:47

◆ BlobCrownMask()

void BlobCrownMask ( MultidimArray< double > &  mask,
double  r1,
double  r2,
blobtype  blob,
int  mode,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a crown mask with blob-shaped edges for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the two radii indicated. The only two valid modes are INNER_MASK (by default, between the two radii) or OUTSIDE_MASK (the negative of the crown). It is supposed that R1 is smaller than R2.

When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 278 of file mask.cpp.

281 {
283  aux.resize(mask);
284  if (mode == INNER_MASK)
285  {
286  BlobCircularMask(mask, r1, blob,
287  OUTSIDE_MASK, x0, y0, z0);
288  BlobCircularMask(aux, r2, blob,
289  INNER_MASK, x0, y0, z0);
291  {
292  A3D_ELEM(mask, k, i, j) *= A3D_ELEM(aux, k, i, j);
293  }
294  }
295  else
296  {
297  BlobCircularMask(mask, r1, blob,
298  INNER_MASK, x0, y0, z0);
299  BlobCircularMask(aux, r2, blob,
300  OUTSIDE_MASK, x0, y0, z0);
302  {
303  A3D_ELEM(mask, k, i, j) += A3D_ELEM(aux, k, i, j);
304  }
305  }
306 
307 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void BlobCircularMask(MultidimArray< double > &mask, double r1, blobtype blob, int mode, double x0, double y0, double z0)
Definition: mask.cpp:219
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
float r2
float r1
constexpr int INNER_MASK
Definition: mask.h:47

◆ compute_hist_within_binary_mask() [1/2]

template<typename T >
void compute_hist_within_binary_mask ( const MultidimArray< int > &  mask,
MultidimArray< T > &  v,
Histogram1D hist,
int  no_steps 
)

Compute histogram inside mask within its minimum and maximum value (3D)

Given a volume as input, this function returns the histogram of values inside the mask within the minimum and maximum of the volume, in this way all the values in the volume are counted. The volume can be of any numerical type (short int, int, double, ...). The number of steps must always be given.

Definition at line 906 of file mask.h.

909 {
910  T min_val;
911  T max_val;
912  double avg;
913  double stddev;
914 
915  computeStats_within_binary_mask(mask, v, min_val, max_val, avg, stddev);
916  compute_hist_within_binary_mask(mask, v, hist, min_val, max_val, no_steps);
917 }
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 compute_hist_within_binary_mask(const MultidimArray< int > &mask, MultidimArray< T > &v, Histogram1D &hist, int no_steps)
Definition: mask.h:906

◆ compute_hist_within_binary_mask() [2/2]

template<typename T >
void compute_hist_within_binary_mask ( const MultidimArray< int > &  mask,
const MultidimArray< T > &  v,
Histogram1D hist,
min,
max,
int  no_steps 
)

Compute histogram inside mask within two values (3D)

Given a volume as input, this function returns the histogram of the values inside the mask within two values, the volume values outside this range are not counted. This can be used to avoid the effect of outliers which causes a "compression" in the histogram. The volume can be of any numerical type (short int, int, double, ...). The number of steps must always be given.

Definition at line 928 of file mask.h.

931 {
933  hist.init(min, max, no_steps);
935  if (A3D_ELEM(mask, k, i, j) != 0)
936  {
937  double value=A3D_ELEM(v, k, i, j);
938  INSERT_VALUE(hist,value);
939  }
940 }
void min(Image< double > &op1, const Image< double > &op2)
#define INSERT_VALUE(histogram, value)
Definition: histogram.h:205
void init(double min_val, double max_val, int n_steps)
Definition: histogram.cpp:71
#define i
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 A3D_ELEM(V, k, i, j)
void max(Image< double > &op1, const Image< double > &op2)
#define j
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)

◆ computeStats_within_binary_mask() [1/2]

template<typename T1 , typename T >
void computeStats_within_binary_mask ( const MultidimArray< T1 > &  mask,
const MultidimArray< T > &  m,
double &  min_val,
double &  max_val,
double &  avg,
double &  stddev 
)

Compute statistics in the active area

Only the statistics for values in the overlapping between the mask and the volume for those the mask is not 0 are computed.

Definition at line 799 of file mask.h.

803 {
805  double sum1 = 0;
806  double sum2 = 0;
807  int N = 0;
808 
809  max_val = min_val = DIRECT_A3D_ELEM(m, 0, 0, 0);
810 
812  {
813  if (A3D_ELEM(mask, k, i, j) > 0)
814  {
815  N++;
816 
817  double aux=A3D_ELEM(m, k, i, j);
818  // Minimum and maximum
819  if (aux < min_val)
820  min_val = aux;
821  else if (aux > max_val)
822  max_val = aux;
823 
824  // cumulative sums for average and standard deviation
825  sum1 += aux;
826  sum2 += aux*aux;
827  }
828  }
829 
830  // average and standard deviation
831  avg = sum1 / (double) N;
832  if (N > 1)
833  stddev = sqrt(fabs(sum2 / N - avg * avg) * N / (N - 1));
834  else
835  stddev = 0;
836 }
void sqrt(Image< double > &op)
#define i
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 A3D_ELEM(V, k, i, j)
#define DIRECT_A3D_ELEM(v, k, i, j)
#define j
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)

◆ computeStats_within_binary_mask() [2/2]

void computeStats_within_binary_mask ( const MultidimArray< int > &  mask,
const MultidimArrayGeneric m,
double &  min_val,
double &  max_val,
double &  avg,
double &  stddev 
)
inline

Definition at line 838 of file mask.h.

842 {
843 #define COMPUTESTATS(type) \
844 computeStats_within_binary_mask(mask,*((MultidimArray<type>*)m.im),min_val,max_val,avg,stddev);
845 
847 
848 #undef COMPUTESTATS
849 }
#define COMPUTESTATS(type)
#define SWITCHDATATYPE(datatype, OP)

◆ count_with_mask() [1/2]

template<typename T >
int count_with_mask ( const MultidimArray< int > &  mask,
const MultidimArray< T > &  m,
int  mode,
double  th1,
double  th2 
)

Count voxels with mask and threshold.

This function returns the number of voxels in the ACTIVE area of an volume with a value:

COUNT_ABOVE: greater or equal than th1 COUNT_BELOW: smaller or equal than th1 COUNT_BETWEEN: smaller or equal than th1 and greater or equal than th2

For complex matrices the absolute value is compared.

Definition at line 983 of file mask.h.

985 {
987  int N = 0;
989  if (A3D_ELEM(mask, k, i, j))
990  switch (mode)
991  {
992  case COUNT_ABOVE:
993  if (A3D_ELEM(m, k, i, j) >= th1)
994  N++;
995  break;
996 
997  case COUNT_BELOW:
998  if (A3D_ELEM(m, k, i, j) <= th1)
999  N++;
1000  break;
1001 
1002  case COUNT_BETWEEN:
1003  if (A3D_ELEM(m, k, i, j) >= th1 && A3D_ELEM(m, k, i, j) <= th2)
1004  N++;
1005  break;
1006  }
1007  return N;
1008 }
#define i
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 A3D_ELEM(V, k, i, j)
constexpr int COUNT_BETWEEN
Definition: mask.h:944
void mode
#define j
constexpr int COUNT_BELOW
Definition: mask.h:943
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)
constexpr int COUNT_ABOVE
Definition: mask.h:942

◆ count_with_mask() [2/2]

int count_with_mask ( const MultidimArray< int > &  mask,
const MultidimArray< std::complex< double > > &  m,
int  mode,
double  th1,
double  th2 
)

Definition at line 1712 of file mask.cpp.

1715 {
1717  int N = 0;
1719  if (A2D_ELEM(mask, i, j))
1720  switch (mode)
1721  {
1722  case COUNT_ABOVE:
1723  if (abs(A3D_ELEM(m, k, i, j)) >= th1)
1724  N++;
1725  break;
1726  case COUNT_BELOW:
1727  if (abs(A3D_ELEM(m, k, i, j)) <= th1)
1728  N++;
1729  break;
1730  case COUNT_BETWEEN:
1731  if (abs(A3D_ELEM(m, k, i, j)) >= th1 && abs(A3D_ELEM(m, k, i, j)) <= th2)
1732  N++;
1733  break;
1734  }
1735  return N;
1736 }
#define A2D_ELEM(v, i, j)
void abs(Image< double > &op)
#define i
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 A3D_ELEM(V, k, i, j)
constexpr int COUNT_BETWEEN
Definition: mask.h:944
void mode
#define j
constexpr int COUNT_BELOW
Definition: mask.h:943
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)
constexpr int COUNT_ABOVE
Definition: mask.h:942

◆ GaussianMask()

void GaussianMask ( MultidimArray< double > &  mask,
double  sigma,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a gaussian mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the radius indicated. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. Inner mask are normal sincs, and outside masks are 1 -gaussian.

When entering the mask is initialiazed to 0 and then the mask is created.

Definition at line 325 of file mask.cpp.

327 {
328  double sigma2 = sigma * sigma;
329 
330  double K = 1. / pow(sqrt(2.*PI)*sigma,(double)mask.getDim());
331 
333  {
334  double r2 = (k - z0) * (k - z0) + (i - y0) * (i - y0) + (j - x0) * (j - x0);
335  A3D_ELEM(mask, k, i, j) = K * exp(-0.5 * r2 / sigma2);
336 
337  if (mode == OUTSIDE_MASK)
338  A3D_ELEM(mask, k, i, j) = 1 - A3D_ELEM(mask, k, i, j);
339  }
340 }
void sqrt(Image< double > &op)
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
constexpr int K
float r2
#define PI
Definition: tools.h:43

◆ invert_binary_mask()

template<typename T >
void invert_binary_mask ( MultidimArray< T > &  mask)

Invert binary mask.

0's are converted in 1's and viceversa

Definition at line 1020 of file mask.h.

1021 {
1022  T* ptr=NULL;
1023  unsigned long int n;
1025  *ptr = 1-(*ptr);
1026 }
#define FOR_ALL_DIRECT_ELEMENTS_IN_MULTIDIMARRAY_ptr(v, n, ptr)
int * n

◆ KaiserMask()

void KaiserMask ( MultidimArray< double > &  mask,
double  delta = 0.01,
double  Deltaw = 1.0/12.0 
)

Kaiser selfWindow The mask is resized. delta=ripple (in natural units) in the pass band. Deltaw=transition bandwidth (normalized to 1.0).

Definition at line 83 of file mask.cpp.

84 {
85  // Convert Deltaw from a frequency normalized to 1, to a freq. normalized to PI
86  Deltaw *= PI;
87 
88  // Design Kaiser selfWindow
89  double A = -20 * log10(delta);
90  int M = CEIL((A - 8) / (2.285 * Deltaw));
91  double beta;
92  if (A > 50)
93  beta = 0.1102 * (A - 8.7);
94  else if (A >= 21)
95  beta = 0.5842 * pow(A - 21, 0.4) + 0.07886 * (A - 21);
96  else
97  beta = 0;
98 
99  // "Draw" Kaiser selfWindow
100  if (YSIZE(mask)==1 && ZSIZE(mask)==1)
101  {
102  // 1D
103  mask.resize(2*M + 1);
104  }
105  else if (ZSIZE(mask)==1)
106  {
107  // 2D
108  mask.resize(2*M + 1, 2*M + 1);
109  }
110  else
111  {
112  // 3D
113  mask.resize(2*M + 1, 2*M + 1, 2*M + 1);
114  }
115 
116  mask.setXmippOrigin();
117  double iI0Beta = 1.0 / bessi0(beta);
119  {
120  double r = sqrt((double)(i * i + j * j + k * k));
121  if (r <= M)
122  A3D_ELEM(mask, k, i, j) = bessi0(beta * sqrt(1-(r/M)*(r/M))) * iI0Beta;
123  }
124 
125 }
#define YSIZE(v)
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double beta(const double a, const double b)
void sqrt(Image< double > &op)
#define i
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 A3D_ELEM(V, k, i, j)
__device__ float bessi0(float x)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define CEIL(x)
Definition: xmipp_macros.h:225
#define ZSIZE(v)
void log10(Image< double > &op)
#define j
#define PI
Definition: tools.h:43
double * delta

◆ mask2D_4neig()

void mask2D_4neig ( MultidimArray< int > &  mask,
int  value = 1,
int  center = NO_ACTIVATE 
)

Creates a 3x3 mask with value (1 by default) for those 4-neighbours of the central point (0 otherwise).

The parameter center controls whether the center pixel is set to 1 or not

Definition at line 409 of file mask.cpp.

410 {
411  mask.resize(3, 3);
412  mask.initZeros();
413  mask(0, 1) = mask(1, 0) = mask(1, 2) = mask(2, 1) = value;
414  mask(1, 1) = center;
415 
416 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initZeros(const MultidimArray< T1 > &op)

◆ mask2D_8neig()

void mask2D_8neig ( MultidimArray< int > &  mask,
int  value1 = 1,
int  value2 = 1,
int  center = NO_ACTIVATE 
)

Creates a 3x3 mask with value1 for those 4-neighbors of the central point and value2 for the 8 neighbours.

The parameter center controls whether the center pixel is set to 1 or not

Definition at line 417 of file mask.cpp.

418 {
419  mask.resize(3, 3);
420  mask.initZeros();
421  mask(0, 1) = mask(1, 0) = mask(1, 2) = mask(2, 1) = value1;
422  mask(0, 0) = mask(0, 2) = mask(2, 0) = mask(2, 2) = value2;
423  mask(1, 1) = center;
424 
425 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initZeros(const MultidimArray< T1 > &op)

◆ mask3D_18neig()

void mask3D_18neig ( MultidimArray< int > &  mask,
int  value1 = 1,
int  value2 = 1,
int  center = NO_ACTIVATE 
)

Creates a 3x3x3 mask with value1 (1 by default) for those 6-neighbors and value2 for the 18 neighbors of the central point (0 otherwise).

The parameter center controls whether the center pixel is set to 1 or not

Definition at line 598 of file mask.cpp.

599 {
600  mask.resize(3, 3, 3);
601  mask.initZeros();
602  mask(1, 1, 1) = center;
603  //Face neighbors
604  mask(1, 1, 0) = mask(1, 1, 2) = mask(0, 1, 1) = mask(2, 1, 1) = mask(1, 0, 1) = mask(1, 2, 1) = value1;
605  //Edge neighbors
606  mask(0, 1, 0) = mask(0, 0, 1) = mask(0, 1, 2) = mask(0, 2, 1) = value2;
607  mask(1, 0, 0) = mask(1, 2, 0) = mask(1, 0, 2) = mask(1, 2, 2) = value2;
608  mask(2, 1, 0) = mask(2, 0, 1) = mask(2, 1, 2) = mask(2, 2, 1) = value2;
609 
610 
611 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initZeros(const MultidimArray< T1 > &op)

◆ mask3D_26neig()

void mask3D_26neig ( MultidimArray< int > &  mask,
int  value1 = 1,
int  value2 = 1,
int  value3 = 1,
int  center = NO_ACTIVATE 
)

Creates a 3x3x3 mask with value1 (1 by default) for those 6-neighbors, value2 for the 18 neighbors and value3 for the 26 neighbors of the central point (0 otherwise).

The parameter center controls whether the center pixel is set to 1 or not

Definition at line 612 of file mask.cpp.

614 {
615  mask.resize(3, 3, 3);
616  mask.initZeros();
617  mask(1, 1, 1) = center;
618  //Face neighbors
619  mask(1, 1, 0) = mask(1, 1, 2) = mask(0, 1, 1) = mask(2, 1, 1) = mask(1, 0, 1) = mask(1, 2, 1) = value1;
620  //Edge neighbors
621  mask(0, 1, 0) = mask(0, 0, 1) = mask(0, 1, 2) = mask(0, 2, 1) = value2;
622  mask(1, 0, 0) = mask(1, 2, 0) = mask(1, 0, 2) = mask(1, 2, 2) = value2;
623  mask(2, 1, 0) = mask(2, 0, 1) = mask(2, 1, 2) = mask(2, 2, 1) = value2;
624  //Vertex neighbors
625  mask(0, 0, 0) = mask(0, 0, 2) = mask(0, 2, 0) = mask(0, 2, 2) = value3;
626  mask(2, 0, 0) = mask(2, 0, 2) = mask(2, 2, 0) = mask(2, 2, 2) = value3;
627 
628 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initZeros(const MultidimArray< T1 > &op)

◆ mask3D_6neig()

void mask3D_6neig ( MultidimArray< int > &  mask,
int  value = 1,
int  center = NO_ACTIVATE 
)

Creates a 3x3x3 mask with value (1 by default) for those 6-neighbors of the central point (0 otherwise).

The parameter center controls whether the center pixel is set to 1 or not

Definition at line 589 of file mask.cpp.

590 {
591  mask.resize(3, 3, 3);
592  mask.initZeros();
593  mask(1, 1, 1) = center;
594  mask(1, 1, 0) = mask(1, 1, 2) = mask(0, 1, 1) = mask(2, 1, 1) = mask(1, 0, 1) = mask(1, 2, 1) = value;
595 
596 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void initZeros(const MultidimArray< T1 > &op)

◆ RaisedCosineMask()

void RaisedCosineMask ( MultidimArray< double > &  mask,
double  r1,
double  r2,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a RaisedCosine mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0,z0), by default (0,0,0), is created with the radius indicated. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. Inner mask are normal RaisedCosines, and outside masks are 1 - RaisedCosine. When entering, the mask is initialiazed to 0 and then the mask is created.

Definition at line 36 of file mask.cpp.

38 {
39  double K = PI / (r2 - r1);
40  double r1_2=r1*r1;
41  double r2_2=r2*r2;
42  for (int k=STARTINGZ(mask); k<=FINISHINGZ(mask); ++k)
43  {
44  double k2=(k - z0) * (k - z0);
45  for (int i=STARTINGY(mask); i<=FINISHINGY(mask); ++i)
46  {
47  double i2_k2=k2+(i - y0) * (i - y0);
48  for (int j=STARTINGX(mask); j<=FINISHINGX(mask); ++j)
49  {
50  double r2=i2_k2+(j - x0) * (j - x0);
51  if (r2 <= r1_2)
52  A3D_ELEM(mask, k, i, j) = 1;
53  else if (r2 < r2_2)
54  {
55  double r=sqrt(r2);
56  A3D_ELEM(mask, k, i, j) = 0.5*(1 + cos(K * (r - r1)));
57  }
58  else
59  A3D_ELEM(mask, k, i, j) = 0;
60  if (mode == OUTSIDE_MASK)
61  A3D_ELEM(mask, k, i, j) = 1 - A3D_ELEM(mask, k, i, j);
62  }
63  }
64  }
65 }
#define FINISHINGX(v)
void sqrt(Image< double > &op)
#define z0
#define FINISHINGZ(v)
#define STARTINGX(v)
#define i
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 STARTINGY(v)
#define A3D_ELEM(V, k, i, j)
#define y0
#define x0
void mode
#define j
#define FINISHINGY(v)
constexpr int OUTSIDE_MASK
Definition: mask.h:48
constexpr int K
float r2
#define PI
Definition: tools.h:43
#define STARTINGZ(v)
float r1

◆ RaisedCrownMask()

void RaisedCrownMask ( MultidimArray< double > &  mask,
double  r1,
double  r2,
double  pix_width,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a RaisedCrown mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0,y0), by default (0,0), is created within the two the radii indicated with an extra region of (pix_width) pixels. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. Inner mask are normal RaisedCrowns, and outside masks are 1 - RaisedCrowns. When entering, the mask is initialiazed to 0 and then the mask is created.

Definition at line 67 of file mask.cpp.

70 {
71  RaisedCosineMask(mask, r1 - pix_width, r1 + pix_width, OUTSIDE_MASK, x0, y0, z0);
73  aux.resize(mask);
74  RaisedCosineMask(aux, r2 - pix_width, r2 + pix_width, INNER_MASK, x0, y0, z0);
76  {
77  A3D_ELEM(mask, k, i, j) *= A3D_ELEM(aux, k, i, j);
78  if (mode == OUTSIDE_MASK)
79  A3D_ELEM(mask, k, i, j) = 1 - A3D_ELEM(mask, k, i, j);
80  }
81 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
float r2
void RaisedCosineMask(MultidimArray< double > &mask, double r1, double r2, int mode, double x0, double y0, double z0)
Definition: mask.cpp:36
float r1
constexpr int INNER_MASK
Definition: mask.h:47

◆ rangeAdjust_within_mask()

void rangeAdjust_within_mask ( const MultidimArray< double > *  mask,
const MultidimArray< double > &  m1,
MultidimArray< double > &  m2 
)

Range adjust within binary mask

Make the grey values of m2 fit, in L2 sense, with those in m1. Only the voxels within the mask are used to compute the linear transformation. If no mask is provided then all voxels are used.

Definition at line 1738 of file mask.cpp.

1741 {
1742  Matrix2D<double> A(2, 2);
1743  A.initZeros();
1744  Matrix1D<double> b(2);
1745  b.initZeros();
1747  // Compute Least squares solution
1748  if (mask == nullptr)
1749  {
1751  {
1752  A(0, 0) += m2(k, i, j) * m2(k, i, j);
1753  A(0, 1) += m2(k, i, j);
1754  A(1, 1) += 1;
1755  b(0) += m1(k, i, j) * m2(k, i, j);
1756  b(1) += m1(k, i, j);
1757  }
1758  A(1, 0) = A(0, 1);
1759  }
1760  else
1761  {
1763  {
1764  if ((*mask)(k, i, j))
1765  {
1766  A(0, 0) += m2(k, i, j) * m2(k, i, j);
1767  A(0, 1) += m2(k, i, j);
1768  A(1, 1) += 1;
1769  b(0) += m1(k, i, j) * m2(k, i, j);
1770  b(1) += m1(k, i, j);
1771  }
1772  }
1773  A(1, 0) = A(0, 1);
1774  }
1775  b = A.inv() * b;
1776 
1777  // Apply to m2
1778  FOR_ALL_ELEMENTS_IN_ARRAY3D(m2) m2(k, i, j) = b(0) * m2(k, i, j) + b(1);
1779 }
#define i
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_ARRAY3D(V)
doublereal * b
#define j
#define SPEED_UP_tempsInt
Definition: xmipp_macros.h:408
#define FOR_ALL_ELEMENTS_IN_COMMON_IN_ARRAY3D(V1, V2)

◆ SeparableSincKaiserMask2D()

void SeparableSincKaiserMask2D ( MultidimArray< double > &  mask,
double  omega,
double  delta = 0.01,
double  Deltaw = 1.0/12.0 
)

Creates a 2D separable-sinc-kaiser mask, the mask is resized. This function returns a sinc mask windowed by a Kaiser selfWindow. delta=ripple (in natural units) in the pass band. Deltaw=transition bandwidth (normalized to 1). omega=low pass frequency (normalized to 1).

Definition at line 379 of file mask.cpp.

381 {
382  // Convert Deltaw from a frequency normalized to 1, to a freq. normalized to PI
383  Deltaw *= PI;
384  omega *= PI;
385 
386  // Design Kaiser selfWindow
387  double A = -20 * log10(delta);
388  double M = CEIL((A - 8) / (2.285 * Deltaw));
389  double beta;
390  if (A > 50)
391  beta = 0.1102 * (A - 8.7);
392  else if (A >= 21)
393  beta = 0.5842 * pow(A - 21, 0.4) + 0.07886 * (A - 21);
394  else
395  beta = 0;
396 
397  // "Draw" Separable Kaiser Sinc selfWindow
398  mask.resize((size_t)(2*M + 1),(size_t)(2*M + 1));
399  mask.setXmippOrigin();
400  double iI0Beta = 1.0 / bessi0(beta);
402  {
403  mask(i, j) = omega/PI * SINC(omega/PI * i) * omega/PI * SINC(omega/PI * j) *
404  bessi0(beta * sqrt((double)(1 - (i / M) * (i / M)))) * iI0Beta *
405  bessi0(beta * sqrt((double)(1 - (j / M) * (j / M)))) * iI0Beta;
406  }
407 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
double beta(const double a, const double b)
void sqrt(Image< double > &op)
#define i
#define FOR_ALL_ELEMENTS_IN_ARRAY2D(m)
__device__ float bessi0(float x)
#define CEIL(x)
Definition: xmipp_macros.h:225
void log10(Image< double > &op)
#define j
#define PI
Definition: tools.h:43
#define SINC(x)
Definition: xmipp_macros.h:362
double * delta

◆ SincBlackmanMask()

void SincBlackmanMask ( MultidimArray< double > &  mask,
double  omega,
double  power_percentage,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a sinc-blackman mask, the mask is resized

This function returns a sinc mask windowed by a Blackman selfWindow. The selfWindow is designed to cover a certain power of the sinc

Definition at line 166 of file mask.cpp.

169 {
170  MultidimArray<double> blackman;
171 
172  int N = CEIL(1 / omega * CEIL(-1 / 2 + 1 / (PI * (1 - power_percentage / 100))));
173 
174  if (ZSIZE(mask)==1)
175  {
176  // 2D
177  mask.resize(N, N);
178  blackman.resize(N, N);
179  }
180  else
181  {
182  // 3D
183  mask.resize(N, N, N);
184  blackman.resize(N, N, N);
185  }
186  mask.setXmippOrigin();
187  SincMask(mask,omega,INNER_MASK,x0,y0,z0);
188  blackman.setXmippOrigin();
189  BlackmanMask(blackman);
190  mask *= blackman;
191 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void SincMask(MultidimArray< double > &mask, double omega, int mode, double x0, double y0, double z0)
Definition: mask.cpp:127
#define z0
#define y0
#define x0
#define CEIL(x)
Definition: xmipp_macros.h:225
void BlackmanMask(MultidimArray< double > &mask, int mode, double x0, double y0, double z0)
Definition: mask.cpp:151
#define ZSIZE(v)
#define PI
Definition: tools.h:43
constexpr int INNER_MASK
Definition: mask.h:47

◆ SincKaiserMask()

void SincKaiserMask ( MultidimArray< double > &  mask,
double  omega,
double  delta = 0.01,
double  Deltaw = 1.0/12.0 
)

Creates a radial-sinc-kaiser mask, the mask is resized. This function returns a sinc mask windowed by a Kaiser selfWindow. delta=ripple (in natural units) in the pass band. Deltaw=transition bandwidth (normalized to 1). omega=low pass frequency (normalized to 1).

Definition at line 139 of file mask.cpp.

141 {
142  MultidimArray<double> kaiser;
143  kaiser.resizeNoCopy(mask);
144  KaiserMask(kaiser, delta, Deltaw);
145  mask.resize(kaiser);
146  mask.setXmippOrigin();
147  SincMask(mask, omega*PI, INNER_MASK);
148  mask *= kaiser;
149 }
void resize(size_t Ndim, size_t Zdim, size_t Ydim, size_t Xdim, bool copy=true)
void resizeNoCopy(const MultidimArray< T1 > &v)
void SincMask(MultidimArray< double > &mask, double omega, int mode, double x0, double y0, double z0)
Definition: mask.cpp:127
void KaiserMask(MultidimArray< double > &mask, double delta, double Deltaw)
Definition: mask.cpp:83
#define PI
Definition: tools.h:43
double * delta
constexpr int INNER_MASK
Definition: mask.h:47

◆ SincMask()

void SincMask ( MultidimArray< double > &  mask,
double  omega,
int  mode = INNER_MASK,
double  x0 = 0,
double  y0 = 0,
double  z0 = 0 
)

Creates a sinc mask for already sized masks

The mask is supposed to be resized and with its logical origin already set. A circle placed logically at (x0), by default (0), is created with the radius indicated. The only two valid modes are INNER_MASK (by default) or OUTSIDE_MASK. Inner mask are normal sincs, and outside masks are 1 - sinc. When entering the mask is initialiazed to 0 and then the mask is created.

Remind that sinc(w*n) is zero at n=1/w;

Definition at line 127 of file mask.cpp.

129 {
131  {
132  double r = sqrt( (k - z0) * (k - z0) + (i - y0) * (i - y0) + (j - x0) * (j - x0) );
133  A3D_ELEM(mask, k, i, j) = omega/PI * SINC(omega/PI * r);
134  if (mode == OUTSIDE_MASK)
135  A3D_ELEM(mask, k, i, j) = 1 - A3D_ELEM(mask, k, i, j);
136  }
137 }
void sqrt(Image< double > &op)
#define z0
#define i
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 A3D_ELEM(V, k, i, j)
#define FOR_ALL_ELEMENTS_IN_ARRAY3D(V)
#define y0
#define x0
void mode
#define j
constexpr int OUTSIDE_MASK
Definition: mask.h:48
#define PI
Definition: tools.h:43
#define SINC(x)
Definition: xmipp_macros.h:362

Variable Documentation

◆ ACTIVATE

constexpr int ACTIVATE = 1

Definition at line 50 of file mask.h.

◆ COUNT_ABOVE

constexpr int COUNT_ABOVE = 1

Definition at line 942 of file mask.h.

◆ COUNT_BELOW

constexpr int COUNT_BELOW = 2

Definition at line 943 of file mask.h.

◆ COUNT_BETWEEN

constexpr int COUNT_BETWEEN = 3

Definition at line 944 of file mask.h.

◆ INNER_MASK

constexpr int INNER_MASK = 1

Definition at line 47 of file mask.h.

◆ NO_ACTIVATE

constexpr int NO_ACTIVATE = 0

Definition at line 49 of file mask.h.

◆ OUTSIDE_MASK

constexpr int OUTSIDE_MASK = 2

Definition at line 48 of file mask.h.