Xmipp  v3.23.11-Nereus
monogenic_signal.h
Go to the documentation of this file.
1 /***************************************************************************
2  *
3  * Authors: Jose Luis Vilas (jlvilas@cnb.csic.es)
4  *
5  * Unidad de Bioinformatica of Centro Nacional de Biotecnologia , CSIC
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
20  * 02111-1307 USA
21  *
22  * All comments concerning this program package may be sent to the
23  * e-mail address 'xmipp@cnb.csic.es'
24  ***************************************************************************/
25 #ifndef _MONOGENIC_HH
26 #define _MONOGENIC_HH
27 
28 #include <complex>
29 #include "core/matrix1d.h"
30 
31 template<typename T>
32 class MultidimArray;
33 class FourierTransformer;
34 
40 class Monogenic
41 {
42 public:
43  // PROTEINRADIUSVOLUMEANDSHELLSTATISTICS: This function takes as input a "mask" and returns
44  // the radius and the volumen "vol" of the protein. The radius is defines has the distance
45  // from the center of the cube to the farthest point of the protein measured from the center.
46  // The volumen "vol" represent the number of voxels of the mask.
47  void proteinRadiusVolumeAndShellStatistics(const MultidimArray<int> &mask, int &radius,
48  long &vol);
49 
50 
51  // FINDCLIFFVALUE: This function determines the radius of noise, "radiuslimit". It means given
52  // a map, "inputmap", the radius measured from the origin for which the map is masked with a
53  // spherical mask is detected. Outside of this sphere there is no noise. Once the all voxels of
54  // of the mask with corresponding radiues greater than "radiuslimit" has been set to -1, the
55  // parameter "rsmooth" does not affect to the output of this function, it is only used to
56  // provide information to the user when the "radiuslimit" is close to the boxsize. Note that
57  // the perimeter of the box is sometimes smoothed when a Fourier Transform is carried out.
58  // To prevent this situation this parameter is provided, but it is only informative via
59  // the standard output
61  int &radius, int &radiuslimit, MultidimArray<int> &mask, double rsmooth);
62 
63 
64  //FOURIERFREQVECTOR: It defines a vector, freq_fourier, that contains
65  // the frequencies of the Fourier direction. Where dimarrayFourier is the
66  // number of components of the vector, and dimarrayReal is the dimensions
67  // of the map along the direction for which the fft is computed
68  Matrix1D<double> fourierFreqVector(size_t dimarrayFourier, size_t dimarrayReal);
69 
70  //FOURIERFREQS_3D: Determine the map of frequencies in the Fourier Space as an output.
71  // Also, the accesible frequencies along each direction are calculated, they are
72  // "freq_fourier_x", "freq_fourier_y", and "freq_fourier_z".
73  MultidimArray<double> fourierFreqs_3D(const MultidimArray< std::complex<double> > &myfftV,
74  const MultidimArray<double> &inputVol,
75  Matrix1D<double> &freq_fourier_x,
76  Matrix1D<double> &freq_fourier_y,
77  Matrix1D<double> &freq_fourier_z);
78 
79  //RESOLUTION2EVAL: Determines the resoltion to be analzed in the estimation
80  //of the local resolution. These resolution are freq, freqL (digital units)
81  // being freqL the tail of the raise cosine centered at freq. The parameter
82  // resolution is the frequency freq in converted into Angstrom. The parameters
83  //minRes and maxRes, determines the limits of the resolution range to be
84  // analyzed (in Angstrom). Sampling is the sampling rate in A/px, and step,
85  // is the resolution step for which analyze the local resolution.
86  void resolution2eval(int &count_res, double step,
87  double &resolution, double &last_resolution,
88  double &freq, double &freqL,
89  int &last_fourier_idx,
90  int &volsize,
91  bool &continueIter, bool &breakIter,
92  double &sampling, double &maxRes);
93 
94  // AMPLITUDEMONOSIG3D_LPF: Estimates the monogenic amplitude of a HPF map, myfftV is the
95  // Fourier transform of that map. The monogenic amplitude is "amplitude", and the
96  // parameters "fftVRiesz", "fftVRiesz_aux", "VRiesz", are auxiliar variables that will
97  // be defined inside the function (they are input to speed up monores algorithm).
98  // Freq, freqL and freqH, are the frequency of the HPF and the tails of a raise cosine.
99  // Note that once the monogenic amplitude is estimated, it is low pass filtered to obtain
100  // a smooth version and avoid rippling. freq_fourier_x, freq_fourier_y, freq_fourier_z,
101  // are the accesible Fourier frequencies along each axis.
102  void amplitudeMonoSig3D_LPF(const MultidimArray< std::complex<double> > &myfftV,
103  FourierTransformer &transformer_inv,
104  MultidimArray< std::complex<double> > &fftVRiesz,
105  MultidimArray< std::complex<double> > &fftVRiesz_aux, MultidimArray<double> &VRiesz,
106  double freq, double freqH, double freqL, MultidimArray<double> &iu,
107  Matrix1D<double> &freq_fourier_x, Matrix1D<double> &freq_fourier_y,
108  Matrix1D<double> &freq_fourier_z, MultidimArray<double> &amplitude,
109  int count, FileName fnDebug);
110 
111  // STATISTICSINBINARYMASK2: Estimates the staticstics of two maps:
112  // Signal map "volS" and Noise map "volN". The signal statistics
113  // are obtained by mean of a binary mask. The results are the mean
114  // and variance of noise and signal, as well as the number of voxels
115  // of signal and noise NS and NN respectively. The thr95 represents
116  // the percentile 95 of noise distribution.
118  const MultidimArray<double> &volN,
119  MultidimArray<int> &mask, double &meanS, double &sdS2,
120  double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN);
121 
122  // STATISTICSINOUTBINARYMASK2: Estimates the staticstics of a single
123  // map. The signal statistics are obtained by mean of a binary mask.
124  // The results are the mean and variance of noise and signal, as well
125  // as the number of voxels of signal and noise NS and NN respectively.
126  // The thr95 represents the percentile 95 of noise distribution.
128  MultidimArray<int> &mask, double &meanS, double &sdS2,
129  double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN);
130 
131  // SETLOCALRESOLUTIONHALFMAPS: Set the local resolution of a voxel, by
132  // determining if the monogenic amplitude "amplitudeMS" is higher than
133  // the threshold of noise "thresholdNoise". Thus the local resolution
134  // map "plocalResolution" is set, with the resolution value "resolution"
135  // or with "resolution_2". "resolution" is the resolution for with
136  // the hypohtesis test is carried out, and "resolution_2" is the resolution
137  // of the analisys two loops ago (see monores method)
138  void setLocalResolutionHalfMaps(const MultidimArray<double> &amplitudeMS,
139  MultidimArray<int> &pMask, MultidimArray<double> &plocalResolutionMap,
140  double thresholdNoise, double resolution, double resolution_2);
141 
142  // SETLOCALRESOLUTIONMAP: Set the local resolution of a voxel, by
143  // determining if the monogenic amplitude "amplitudeMS" is higher than
144  // the threshold of noise "thresholdNoise". Thus the local resolution
145  // map "plocalResolution" is set, with the resolution value "resolution"
146  // or with "resolution_2". "resolution" is the resolution for with
147  // the hypohtesis test is carried out, and "resolution_2" is the resolution
148  // of the analisys two loops ago (see monores method)
149  void setLocalResolutionMap(const MultidimArray<double> &amplitudeMS,
150  MultidimArray<int> &pMask, MultidimArray<double> &plocalResolutionMap,
151  double thresholdNoise, double resolution, double resolution_2);
152 
153  // MONOGENICAMPLITUDE_3D_FOURIER: Given the fourier transform of a map
154  // "myfftV", this function computes the monogenic amplitude "amplitude"
155  // iu is the inverse of the frequency in Fourier space.
156  void monogenicAmplitude_3D_Fourier(const MultidimArray< std::complex<double> > &myfftV,
157  MultidimArray<double> &iu, MultidimArray<double> &amplitude, int numberOfThreads);
158 
159  //ADDNOISE: This function add gaussian with mean = double mean and standard deviation
160  // equal to double stddev to a map given by "vol"
161  void addNoise(MultidimArray<double> &vol, double mean, double stddev);
162 
163  //CREATEDATATEST: This function generates fringe pattern (rings) map returned
164  // as a multidimArray, with dimensions given by xdim, ydim and zdim. The
165  // wavelength of the pattern is given by double wavelength
166  MultidimArray<double> createDataTest(size_t xdim, size_t ydim, size_t zdim,
167  double wavelength);
168 
169 };
170 
172 #endif
void statisticsInOutBinaryMask2(const MultidimArray< double > &volS, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void findCliffValue(MultidimArray< double > &inputmap, int &radius, int &radiuslimit, MultidimArray< int > &mask, double rsmooth)
void statisticsInBinaryMask2(const MultidimArray< double > &volS, const MultidimArray< double > &volN, MultidimArray< int > &mask, double &meanS, double &sdS2, double &meanN, double &sdN2, double &significance, double &thr95, double &NS, double &NN)
void resolution2eval(int &count_res, double step, double &resolution, double &last_resolution, double &freq, double &freqL, int &last_fourier_idx, int &volsize, bool &continueIter, bool &breakIter, double &sampling, double &maxRes)
void setLocalResolutionHalfMaps(const MultidimArray< double > &amplitudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
#define sampling
MultidimArray< double > fourierFreqs_3D(const MultidimArray< std::complex< double > > &myfftV, const MultidimArray< double > &inputVol, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z)
Matrix1D< double > fourierFreqVector(size_t dimarrayFourier, size_t dimarrayReal)
void amplitudeMonoSig3D_LPF(const MultidimArray< std::complex< double > > &myfftV, FourierTransformer &transformer_inv, MultidimArray< std::complex< double > > &fftVRiesz, MultidimArray< std::complex< double > > &fftVRiesz_aux, MultidimArray< double > &VRiesz, double freq, double freqH, double freqL, MultidimArray< double > &iu, Matrix1D< double > &freq_fourier_x, Matrix1D< double > &freq_fourier_y, Matrix1D< double > &freq_fourier_z, MultidimArray< double > &amplitude, int count, FileName fnDebug)
void monogenicAmplitude_3D_Fourier(const MultidimArray< std::complex< double > > &myfftV, MultidimArray< double > &iu, MultidimArray< double > &amplitude, int numberOfThreads)
void proteinRadiusVolumeAndShellStatistics(const MultidimArray< int > &mask, int &radius, long &vol)
MultidimArray< double > createDataTest(size_t xdim, size_t ydim, size_t zdim, double wavelength)
void setLocalResolutionMap(const MultidimArray< double > &amplitudeMS, MultidimArray< int > &pMask, MultidimArray< double > &plocalResolutionMap, double thresholdNoise, double resolution, double resolution_2)
void addNoise(MultidimArray< double > &vol, double mean, double stddev)