summaryrefslogtreecommitdiffstats
path: root/Wrappers
diff options
context:
space:
mode:
Diffstat (limited to 'Wrappers')
-rw-r--r--Wrappers/Python/src/fista_module_gpu.pyx192
1 files changed, 149 insertions, 43 deletions
diff --git a/Wrappers/Python/src/fista_module_gpu.pyx b/Wrappers/Python/src/fista_module_gpu.pyx
index 41cf4a6..f18181b 100644
--- a/Wrappers/Python/src/fista_module_gpu.pyx
+++ b/Wrappers/Python/src/fista_module_gpu.pyx
@@ -26,6 +26,10 @@ cdef extern void NLM_GPU_kernel(float *A, float* B, float *Eucl_Vec,
int N, int M, int Z, int dimension,
int SearchW, int SimilW,
int SearchW_real, float denh2, float lambdaf);
+cdef extern float pad_crop(float *A, float *Ap,
+ int OldSizeX, int OldSizeY, int OldSizeZ,
+ int NewSizeX, int NewSizeY, int NewSizeZ,
+ int padXY, int switchpad_crop);
def Diff4thHajiaboli(inputData,
regularization_parameter,
@@ -152,46 +156,148 @@ def Diff4thHajiaboli3D(np.ndarray[np.float32_t, ndim=3, mode="c"] inputData,
return B
-def NML(inputData,
- regularization_parameter,
- iterations,
- edge_preserving_parameter):
- if inputData.ndim == 2:
- return NML2D(inputData,
- regularization_parameter,
- iterations,
- edge_preserving_parameter)
- elif inputData.ndim == 3:
- return NML3D(inputData,
- regularization_parameter,
- iterations,
- edge_preserving_parameter)
-
- #SearchW_real = (int) mxGetScalar(prhs[1]); /* the searching window ratio */
- #SimilW = (int) mxGetScalar(prhs[2]); /* the similarity window ratio */
- #h = (float) mxGetScalar(prhs[3]); /* parameter for the PB filtering function */
- #lambda = (float) mxGetScalar(prhs[4]);
-
-def NML2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
- SearchW_real,
- SimilW,
- h,
- lambdaf):
- N, M = inputData.shape
- if h < 0:
- raise ValueError('Parameter for the PB filtering function must be > 0')
-
- SearchW = SearchW_real + 2*SimilW;
-
- SearchW_full = 2*SearchW + 1; #/* the full searching window size */
- SimilW_full = 2*SimilW + 1; #/* the full similarity window size */
- h2 = h*h;
-
- padXY = SearchW + 2*SimilW; #/* padding sizes */
- newsizeX = N + 2*(padXY); #/* the X size of the padded array */
- newsizeY = M + 2*(padXY); #/* the Y size of the padded array */
- newsizeZ = Z + 2*(padXY); #/* the Z size of the padded array */
-
- B = np.zeros((N,M), dtype=np.float )
-
- \ No newline at end of file
+#def NML(inputData,
+# regularization_parameter,
+# iterations,
+# edge_preserving_parameter):
+# if inputData.ndim == 2:
+# return NML2D(inputData,
+# regularization_parameter,
+# iterations,
+# edge_preserving_parameter)
+# elif inputData.ndim == 3:
+# return NML3D(inputData,
+# regularization_parameter,
+# iterations,
+# edge_preserving_parameter)
+#
+# #SearchW_real = (int) mxGetScalar(prhs[1]); /* the searching window ratio */
+# #SimilW = (int) mxGetScalar(prhs[2]); /* the similarity window ratio */
+# #h = (float) mxGetScalar(prhs[3]); /* parameter for the PB filtering function */
+# #lambda = (float) mxGetScalar(prhs[4]);
+#
+#def NML2D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
+# SearchW_real,
+# SimilW,
+# h,
+# lambdaf):
+# N = inputData.shape[0]
+# M = inputData.shape[1]
+# Z = 0
+# numdims = inputData.ndim
+#
+# if h < 0:
+# raise ValueError('Parameter for the PB filtering function must be > 0')
+#
+# SearchW = SearchW_real + 2*SimilW;
+#
+# SearchW_full = 2*SearchW + 1; #/* the full searching window size */
+# SimilW_full = 2*SimilW + 1; #/* the full similarity window size */
+# h2 = h*h;
+#
+# padXY = SearchW + 2*SimilW; #/* padding sizes */
+# newsizeX = N + 2*(padXY); #/* the X size of the padded array */
+# newsizeY = M + 2*(padXY); #/* the Y size of the padded array */
+# #newsizeZ = Z + 2*(padXY); #/* the Z size of the padded array */
+#
+# #output
+# B = np.zeros((N,M), dtype=np.float )
+# #/*allocating memory for the padded arrays */
+#
+# Ap = np.zeros((newsizeX, newsizeY), dtype=np.float)
+# Bp = np.zeros((newsizeX, newsizeY), dtype=np.float)
+# Eucl_Vec = np.zeros((SimilW_full*SimilW_full), dtype=np.float)
+#
+# #/*Gaussian kernel */
+# cdef int count, i_n, j_n;
+# cdef float val;
+# count = 0
+# for i_n in range (-SimilW, SimilW +1):
+# for j_n in range(-SimilW, SimilW +1):
+# val = (float)(i_n*i_n + j_n*j_n)/(2*SimilW*SimilW)
+# Eucl_Vec[count] = np.exp(-val)
+# count = count + 1
+#
+# #/*Perform padding of image A to the size of [newsizeX * newsizeY] */
+# switchpad_crop = 0; # /*padding*/
+# pad_crop(&inputData[0,0], &Ap[0,0], M, N, 0, newsizeY, newsizeX, 0, padXY,
+# switchpad_crop);
+#
+# #/* Do PB regularization with the padded array */
+# NLM_GPU_kernel(&Ap[0,0], &Bp[0,0], &Eucl_Vec[0,0], newsizeY, newsizeX, 0,
+# numdims, SearchW, SimilW, SearchW_real,
+# h2, lambdaf);
+#
+# switchpad_crop = 1; #/*cropping*/
+# pad_crop(&Bp[0,0], &B[0,0], M, N, 0, newsizeX, newsizeY, 0, padXY,
+# switchpad_crop)
+#
+# return B
+#
+#def NML3D(np.ndarray[np.float32_t, ndim=2, mode="c"] inputData,
+# SearchW_real,
+# SimilW,
+# h,
+# lambdaf):
+# N = inputData.shape[0]
+# M = inputData.shape[1]
+# Z = inputData.shape[2]
+# numdims = inputData.ndim
+#
+# if h < 0:
+# raise ValueError('Parameter for the PB filtering function must be > 0')
+#
+# SearchW = SearchW_real + 2*SimilW;
+#
+# SearchW_full = 2*SearchW + 1; #/* the full searching window size */
+# SimilW_full = 2*SimilW + 1; #/* the full similarity window size */
+# h2 = h*h;
+#
+# padXY = SearchW + 2*SimilW; #/* padding sizes */
+# newsizeX = N + 2*(padXY); #/* the X size of the padded array */
+# newsizeY = M + 2*(padXY); #/* the Y size of the padded array */
+# newsizeZ = Z + 2*(padXY); #/* the Z size of the padded array */
+#
+# #output
+# B = np.zeros((N,M,Z), dtype=np.float )
+# #/*allocating memory for the padded arrays */
+#
+# Ap = np.zeros((newsizeX, newsizeY, newsizeZ), dtype=np.float)
+# Bp = np.zeros((newsizeX, newsizeY, newsizeZ), dtype=np.float)
+# Eucl_Vec = np.zeros((SimilW_full*SimilW_full*SimilW_full), dtype=np.float)
+#
+# #/*Gaussian kernel */
+# cdef int count, i_n, j_n, k_n;
+# cdef float val;
+# count = 0
+# for i_n in range (-SimilW, SimilW +1):
+# for j_n in range(-SimilW, SimilW +1):
+# for k_n in range(-SimilW, SimilW+1):
+# val = (i_n*i_n + j_n*j_n + k_n*k_n)/(2*SimilW*SimilW*SimilW)
+# Eucl_Vec[count] = np.exp(-val)
+# count = count + 1
+#
+# #/*Perform padding of image A to the size of [newsizeX * newsizeY] */
+# switchpad_crop = 0; # /*padding*/
+# pad_crop(&inputData[0,0,0], &Ap[0,0,0],
+# M, N, Z,
+# newsizeY, newsizeX, newsizeZ,
+# padXY,
+# switchpad_crop);
+#
+# #/* Do PB regularization with the padded array */
+# NLM_GPU_kernel(&Ap[0,0,0], &Bp[0,0,0], &Eucl_Vec[0,0,0],
+# newsizeY, newsizeX, newsizeZ,
+# numdims, SearchW, SimilW, SearchW_real,
+# h2, lambdaf);
+#
+# switchpad_crop = 1; #/*cropping*/
+# pad_crop(&Bp[0,0,0], &B[0,0,0],
+# M, N, Z,
+# newsizeX, newsizeY, newsizeZ,
+# padXY,
+# switchpad_crop)
+#
+# return B
+#
+# \ No newline at end of file