-
Notifications
You must be signed in to change notification settings - Fork 204
Modify and update the code related to the PICCS algorithm module. #650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,6 +112,8 @@ def __init__(self, proj, geo, angles, niter, **kwargs): | |
self.alpha = 0.002 if "alpha" not in kwargs else kwargs["alpha"] | ||
self.alpha_red = 0.95 if "alpha_red" not in kwargs else kwargs["alpha_red"] | ||
self.rmax = 0.95 if "rmax" not in kwargs else kwargs["rmax"] | ||
self.ratio = 0.5 if "ratio" not in kwargs else kwargs["ratio"] | ||
self.regularization = "minimizeTV" if "regularization" not in kwargs else kwargs["regularization"] | ||
if "maxl2err" not in kwargs: | ||
self.epsilon = ( | ||
im3DNORM(Ax(FDK(proj, geo, angles, gpuids=self.gpuids), geo, angles) - proj, 2) | ||
|
@@ -128,6 +130,10 @@ def __init__(self, proj, geo, angles, niter, **kwargs): | |
def run_main_iter(self): | ||
stop_criteria = False | ||
n_iter = 0 | ||
if (self.regularization=="PICCS"): | ||
# Modify the `set_res` function in the `Python\tigre\algorithms\iterative_recon_alg.py` file as needed. | ||
res_prior = copy.deepcopy(self.res) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hum not sure about this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My approach is to add the following code in the
And then call
Of course a better approach would be to add a kwarg with a name like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think that should be the right way. In MATLAB we have PICCS as a separate function, ideally we want to have an alias (like Let me know if you want to implement this change, or want me to do it before the merge (I will make commits in your branch if so). |
||
|
||
while not stop_criteria: | ||
if self.verbose: | ||
self._estimate_time_until_completion(n_iter) | ||
|
@@ -146,7 +152,12 @@ def run_main_iter(self): | |
dtvg = self.alpha * dp | ||
|
||
res_prev = copy.deepcopy(self.res) | ||
self.res = getattr(self, self.regularization)(self.res, dtvg) | ||
# self.res = getattr(self, self.regularization)(self.res, dtvg) | ||
if (self.regularization=="PICCS"): | ||
self.res = getattr(self, self.regularization)(self.res, res_prior, dtvg, self.ratio) | ||
else: | ||
self.res = getattr(self, self.regularization)(self.res, dtvg) | ||
|
||
dg_vec = self.res - res_prev | ||
dg = im3DNORM(dg_vec, 2) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
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 "PICCS.hpp": | ||
cdef void piccs_tv(float* img, float* prior, float* dst, float alpha, float ratio, long* image_size, int maxiter, c_GpuIds gpuids) | ||
|
||
|
||
def cuda_raise_errors(error_code): | ||
if error_code: | ||
raise TigreCudaCallError('PICCS:PICCS_TV:', error_code) | ||
|
||
|
||
def PICCS(np.ndarray[np.float32_t, ndim=3] src,np.ndarray[np.float32_t, ndim=3] prior,float alpha = 15.0,float ratio=0.5,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) | ||
prior = np.ascontiguousarray(prior) | ||
|
||
cdef float* c_src = <float*> src.data | ||
cdef float* c_prior = <float*> prior.data | ||
cdef np.npy_intp c_maxiter = <np.npy_intp> maxiter | ||
cuda_raise_errors(piccs_tv(c_src, c_prior, c_imgout, alpha, ratio, 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you remove
const
here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modification is an attempt I made while debugging the incorrect return value of this operator. Keeping
const
is a better choice.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@coldly01 makes sense :) can you put it back then?