Blame view

stim/math/filters/gauss3.cuh 1.88 KB
bb7275b6   Pavel Govyadinov   added a gauss3.h ...
1
2
  #ifndef STIM_CUDA_GAUSS3_H
  #define STIM_CUDA_GAUSS3_H
817b3aba   David Mayerich   changed filter fi...
3
4
  #include <stim/math/filters/sepconv3.cuh>
  #include <stim/math/filters/gauss2.cuh>
bb7275b6   Pavel Govyadinov   added a gauss3.h ...
5
6
7
8
9
10
11
12
13
14
15
  #include <stim/math/constants.h>
  
  namespace stim
  {
  	///Perform a 3D gaussian convolution on an input image.
          ///@param in is a pointer to the input data.
  	///@param dimx is the size of in* in the x direction.
  	///@param dimx is the size of in* in the y direction.
  	///@param dimx is the size of in* in the z direction.
          ///@param stdx is the standard deviation (in pixels) along the x axis.
          ///@param stdy is the standard deviation (in pixels) along the y axis.
d8072434   David Mayerich   minor modificatio...
16
          ///@param nstds specifies the number of standard deviations of the Gaussian that will be kept in the kernel.
bb7275b6   Pavel Govyadinov   added a gauss3.h ...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  	template<typename T, typename K>
  	void cpu_gauss3(T* in, K dimx, K dimy, K dimz, K stdx, K stdy, K stdz, size_t nstds = 3)
  	{
  		//Set up the sizes of the gaussian Kernels.
  		size_t kx = stdx * nstds * 2;
  		size_t ky = stdy * nstds * 2;
  		size_t kz = stdz * nstds * 2;
  	
  		//Set up the sizes of the new output, which will be kx, ky, kz, smaller than the input.
  		size_t X = dimx - kx +1; 
  		size_t Y = dimy - ky +1; 
  		size_t Z = dimz - kz +1; 
  		T* out = (T*) malloc(X*Y*Z* sizeof(T));
  
  		///Set up the memory that will store the gaussians
  		K* gaussx = (K*)malloc(kx *sizeof(K));
  		K* gaussy = (K*)malloc(ky *sizeof(K));
  		K* gaussz = (K*)malloc(kz *sizeof(K));
  
  		///Set up the midpoints of the gaussians.
  		K midgaussx = (K) kx/ (K)2;
  		K midgaussy = (K) ky/ (K)2;
  		K midgaussz = (K) kz/ (K)2;
  
  		///Evaluate the kernels in each cardinal direction.
  		for(size_t i = 0; i < kx; i++)
  			gaussx[i] = gauss1d((K) i, midgaussx, stdx);
  
  		for(size_t i = 0; i < kx; i++)
  			gaussy[i] = gauss1d((K) i, midgaussy, stdy);
  
  		for(size_t i = 0; i < kx; i++)
  			gaussz[i] = gauss1d((K) i, midgaussz, stdz);
  
  		cpu_sepconv3(out, in, gaussx, gaussy, gaussz, dimx, dimy, dimz, kx, ky, kz);
  
  	}
  }
  #endif