-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy path_minTV.pyx
64 lines (46 loc) · 2.36 KB
/
_minTV.pyx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
56
57
58
59
60
61
62
63
64
# This file is part of the TIGRE Toolbox
# Copyright (c) 2015, University of Bath and
# CERN-European Organization for Nuclear Research
# All rights reserved.
# License: Open Source under BSD.
# See the full license at
# https://github.com/CERN/TIGRE/license.txt
# Contact: [email protected]
# Codes: https://github.com/CERN/TIGRE/
# --------------------------------------------------------------------------
# Coded by: MATLAB (original code): Ander Biguri
# PYTHON : Sam Loescher, Reuben Lindroos
cimport numpy as np
import numpy as np
from tigre.utilities.errors import TigreCudaCallError
from tigre.utilities.cuda_interface._gpuUtils cimport GpuIds as c_GpuIds, convert_to_c_gpuids, free_c_gpuids
np.import_array()
from libc.stdlib cimport malloc, free
cdef extern from "numpy/arrayobject.h":
void PyArray_ENABLEFLAGS(np.ndarray arr, int flags)
void PyArray_CLEARFLAGS(np.ndarray arr, int flags)
cdef extern from "GD_TV.hpp":
cdef void pocs_tv(float* img, float* dst, float alpha, long* image_size, int maxiter, c_GpuIds gpuids)
def cuda_raise_errors(error_code):
if error_code:
raise TigreCudaCallError('minimizeTV:POCS_TV:', error_code)
def minTV(np.ndarray[np.float32_t, ndim=3] src,float alpha = 15.0,int maxiter = 100, gpuids=None):
cdef c_GpuIds* c_gpuids = convert_to_c_gpuids(gpuids)
if not c_gpuids:
raise MemoryError()
cdef np.npy_intp size_img[3]
size_img[0]= <np.npy_intp> src.shape[0]
size_img[1]= <np.npy_intp> src.shape[1]
size_img[2]= <np.npy_intp> src.shape[2]
cdef float* c_imgout = <float*> malloc(<unsigned long>size_img[0] *size_img[1] *size_img[2]* sizeof(float))
cdef long imgsize[3]
imgsize[0] = <long> size_img[2]
imgsize[1] = <long> size_img[1]
imgsize[2] = <long> size_img[0]
src = np.ascontiguousarray(src)
cdef float* c_src = <float*> src.data
cdef np.npy_intp c_maxiter = <np.npy_intp> maxiter
cuda_raise_errors(pocs_tv(c_src, c_imgout, alpha, imgsize, c_maxiter, c_gpuids[0]))
imgout = np.PyArray_SimpleNewFromData(3, size_img, np.NPY_FLOAT32, c_imgout)
PyArray_ENABLEFLAGS(imgout, np.NPY_OWNDATA)
return imgout