Repository navigation
SPECTGPU #1687
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
Open
danieldeidda
wants to merge
39
commits into
UCL:master
Choose a base branch
from
danieldeidda:GPUSPECT
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,727
−83
Open
SPECTGPU #1687
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
b06adca
SPECTGPU:starting point; created SPECTGPU_projector folder and schel…
danieldeidda c948b16
forward line integrals
williamuic 5d300cf
implemented a backward projection kernel in cuda
d4cd638
GPUSPECT: forward rotation and interpolation in cuda
9ca0e11
Adding kernel push
d731b5c
fixup! Adding kernel push
8dfbdd1
SPECTGPU: run pre-commit hooks on SPECTGPURotateAndGaussianInterpolate
aec9adf
joining all contributions; created an actual_forward_project() that …
danieldeidda edc60a8
fixup! joining all contributions; created an actual_forward_project(…
f91d680
SPECTGPU: creation of parfile for FP and BP;
danieldeidda e29f6f2
SPECTGPU: creation of parfile for FP and BP;
danieldeidda 74a840c
SPECTGPU added Attenuation and depth dependent PSF;
danieldeidda e7cbf28
Update authorship in SPECTGPURotateAndGaussianInterpolate.cu
jchan192 5d162c3
Update SPECTGPUProjection.cu
jchan192 864c871
Update SPECTGPURotateAndGaussianInterpolate.cu
jchan192 8f0ab94
update contributors;
danieldeidda f79f532
relax condition of spacing
danieldeidda 3c39f43
Merge branch 'UCL:master' into GPUSPECT
danieldeidda 9413bf5
Working: adressing comments and keeping cxx class
danieldeidda e0eb2d6
Moving copying function definition into cuda_utilities.cu and instat…
danieldeidda b33fadf
Fixing scaling factor and pre-commit
danieldeidda bc28f3a
adding SPECTGPU recon test
danieldeidda c260566
adding python recon example
danieldeidda 88e84be
skip SPECTGPU test if no CUDA run-time
KrisThielemans 1257a9c
pre-commit: fix pymarkdown
casperdcl 8f08cbc
fixing codacy issues and updating parfile
danieldeidda a9a3390
fixing bug on noPSF branch using empty blurred image in FP and additi…
danieldeidda f65ccee
Merge branch 'master' into GPUSPECT
danieldeidda 7637dd4
To make things faster and given that all arrays are of the same size…
danieldeidda 48d82ba
To make things faster and given that all arrays are of the same size…
danieldeidda 708ddfe
reducing double exp() calculation in pull kernel for a little speed up;
danieldeidda dd22df7
reverting to cuda malloc(free) fixes problem with free()
danieldeidda eeabb81
adding working demo using SIMIND;
danieldeidda ecff145
exposing SPECTGPU to SWIGPy
danieldeidda b2276d2
making allocatedSatck it's own file; running FBP for SPECTGPU updatin…
danieldeidda e487850
moving SPECTGPU test within if stir_with_cuda
danieldeidda cf5d756
moving SPECTGPU test within if stir_with_cuda
danieldeidda a0d8edb
some clean up
danieldeidda 208f897
hopefully fixing test error related to no GPU
danieldeidda File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # Demo of how to use STIR from python to reconstruct some data | ||
| # To run in "normal" Python, you would type the following in the command line | ||
| # execfile('recon_demo.py') | ||
| # In ipython, you can use | ||
| # %run recon_demo.py | ||
|
|
||
| # Copyright 2012-06-05 - 2013 Kris Thielemans | ||
| # Copyright 2015 University College London | ||
|
|
||
| # This file is part of STIR. | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # | ||
| # See STIR/LICENSE.txt for details | ||
|
|
||
| import stir | ||
| import matplotlib.pyplot as pylab | ||
| import os | ||
|
|
||
| # go to directory with input files | ||
| os.chdir('../recon_demo') | ||
|
|
||
| # initialise reconstruction object | ||
| # we will do this here via a .par file | ||
| recon = stir.OSMAPOSLReconstruction3DFloat('recon_demo_OSEM_SPECTGPU.par') | ||
| # now modify a few settings from in Python for illustration | ||
| recon.set_num_subsets(2) | ||
| num_subiterations = 4 | ||
| # set filenames to save subset sensitivities (for illustration purposes) | ||
| poissonobj = recon.get_objective_function() | ||
| poissonobj.set_subsensitivity_filenames('sens_subset%d.hv') | ||
| poissonobj.set_recompute_sensitivity(True) | ||
|
|
||
| # get initial image | ||
| target = recon.get_initial_data()#stir.FloatVoxelsOnCartesianGrid.read_from_file('init.hv') | ||
| # we will just fill the whole array with 1 here | ||
| target.fill(1) | ||
|
|
||
| # run a few iterations and plot intermediate results | ||
|
|
||
| # Switch 'interactive' mode on for pylab. | ||
| # Without it, the python shell will wait after every pylab.show() for you | ||
| # to close the window. | ||
| try: | ||
| pylab.ion() | ||
| except: | ||
| print("Enabling interactive-mode for plotting failed. Continuing.") | ||
|
|
||
| s = recon.set_up(target) | ||
| if (s.succeeded()): | ||
| pylab.figure() | ||
| for i in range(1,num_subiterations+1): | ||
| print('\n--------------------- Subiteration ', i) | ||
| recon.set_start_subiteration_num(i) | ||
| recon.set_num_subiterations(i) | ||
| s = recon.reconstruct(target) | ||
| # currently we need to explicitly prevent recomputing sensitivity | ||
| # when we call reconstruct() again in the next iteration | ||
| poissonobj.set_recompute_sensitivity(False) | ||
| # extract to python for plotting | ||
| npimage = target.as_array() | ||
| pylab.plot(npimage[10, 30, :]) | ||
| pylab.show() | ||
|
|
||
| # Save the final image | ||
| recon_filename = f"recon_image_{num_subiterations}.hv" | ||
| print(f"Saving Image as: {recon_filename}") | ||
| target.write_to_file(recon_filename) | ||
|
|
||
| # plot slice of final image | ||
| pylab.figure() | ||
| pylab.imshow(npimage[10, :, :]) | ||
| # Keep figures open until user closes them | ||
| pylab.show(block=True) | ||
| else: | ||
| print('Error setting-up reconstruction object') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| # %% | ||
| import stir | ||
| import matplotlib.pyplot as plt | ||
| import os | ||
|
|
||
| # go to directory with input files | ||
| os.chdir('../recon_demo') | ||
|
|
||
| # %% | ||
| # initialise reconstruction object | ||
| # we will do this here via a .par file | ||
| recon = stir.OSMAPOSLReconstruction3DFloat('recon_demo_OSEM_SPECTGPU.par') | ||
| # now modify a few settings from in Python for illustration | ||
| recon.set_num_subsets(2) | ||
| num_subiterations = 4 | ||
| # set filenames to save subset sensitivities (for illustration purposes) | ||
| poissonobj = recon.get_objective_function() | ||
| poissonobj.set_subsensitivity_filenames('sens_subset{}.hv') | ||
| poissonobj.set_recompute_sensitivity(True) | ||
| help(recon) | ||
|
|
||
|
|
||
| # %% | ||
| # construct image related to the data to reconstruct | ||
| projdata=recon.get_input_data()#recon.tir.ProjData.read_from_file('smalllong.hs'); | ||
| # use smaller voxels than the default | ||
| # zoom=2.216842; | ||
| target=recon.get_initial_data() #stir.FloatVoxelsOnCartesianGrid(projdata.get_proj_data_info(), zoom); | ||
| # get initial image | ||
| # help(target) | ||
| # target = stir.FloatVoxelsOnCartesianGrid.read_from_file('init.hv') | ||
| # we will just fill the whole array with 1 here | ||
| # target.fill(1) | ||
| s = recon.set_up(target) | ||
|
|
||
| # %% | ||
|
|
||
| # compute gradient of objective function | ||
| # create a copy to store the gradient | ||
| gradient=target.get_empty_copy(); | ||
| # compute gradient | ||
| subset_num=1; | ||
| poissonobj.compute_sub_gradient(gradient,target,subset_num) | ||
|
|
||
| # extract to python for plotting | ||
| npimage = gradient.as_array() | ||
| plt.plot(npimage[10, 30, :]) | ||
| plt.show() | ||
|
|
||
| # this is useful to find the EM update (i.e. multiply with image) | ||
| poissonobj.compute_sub_gradient_without_penalty_plus_sensitivity(gradient,target,subset_num) | ||
| # extract to python for plotting | ||
| npimage = gradient.as_array() | ||
| plt.plot(npimage[10, 30, :]) | ||
| plt.show() | ||
|
|
||
| # The followin is just the first iteration you need to create a for | ||
| # loop to run all the iterations and subsets | ||
| EMupdate = target*gradient | ||
| # extract to python for plotting | ||
| npimage = EMupdate.as_array() | ||
| plt.plot(npimage[10, 30, :]) | ||
| plt.show() | ||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| OSMAPOSLParameters := | ||
|
|
||
| objective function type:= PoissonLogLikelihoodWithLinearModelForMeanAndProjData | ||
| PoissonLogLikelihoodWithLinearModelForMeanAndProjData Parameters:= | ||
|
|
||
| input file := ../../recon_test_pack/SPECT/SPECTUB/input.hs | ||
| projector pair type := SPECTGPU | ||
| Projector Pair Using SPECTGPU Parameters := | ||
| ; width of PSF | ||
|
|
||
| ;PSF type of correction { 3D } | ||
| ; | ||
| ; These values are mostly dependent on your collimator. | ||
| ; the PSF is modelled as a Gaussian with sigma dependent on the distance from the collimator | ||
| ; sigma_at_depth = collimator_slope * depth_in_cm + collimator sigma 0(cm) | ||
| collimator slope := 0.0163 | ||
| collimator sigma 0(cm) := 0.1466 | ||
| number of PSF sigmas := 2 ; default 2 (95% of the PSF) | ||
|
|
||
|
|
||
| attenuation image filename := ../../recon_test_pack/SPECT/SPECTUB/attMapRec.hv | ||
|
|
||
| End Projector Pair Using SPECTGPU Parameters := | ||
|
|
||
| end PoissonLogLikelihoodWithLinearModelForMeanAndProjData Parameters:= | ||
|
|
||
| initial estimate := ../../recon_test_pack/SPECT/SPECTUB/init.hv | ||
| output filename prefix := my_SPECTGPU_image | ||
|
|
||
| number of subsets:= 4 | ||
| number of subiterations:= 16 | ||
| save estimates at subiteration intervals:= 4 | ||
|
|
||
|
|
||
|
|
||
|
|
||
| END := |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| OSMAPOSLParameters := | ||
| ; sample .par file to use OSEM on SPECT data. | ||
| ; Any of the algorithm parameters illustrated for PET (such as filtering, prior etc) | ||
| ; will work for SPECT as well, as would OSSPS. | ||
| ; The only thing different here is the projector. | ||
|
|
||
| objective function type:= PoissonLogLikelihoodWithLinearModelForMeanAndProjData | ||
|
|
||
| PoissonLogLikelihoodWithLinearModelForMeanAndProjData Parameters:= | ||
|
|
||
| input file := peak.hs | ||
|
|
||
| projector pair type := SPECTGPU | ||
| Projector Pair Using SPECTGPU Parameters := | ||
| ; width of PSF | ||
|
|
||
| ;PSF type of correction { 3D } | ||
| ; next 2 parameters define the PSF. They are ignored if psf_type is "Geometrical" | ||
| ; These values are mostly dependent on your collimator. | ||
| ; the PSF is modelled as a Gaussian with sigma dependent on the distance from the collimator | ||
| ; sigma_at_depth = collimator_slope * depth_in_cm + collimator sigma 0(cm) | ||
| collimator slope := 0.0163 | ||
| collimator sigma 0(cm) := 0.1466 | ||
| number of PSF sigmas := 2 ; default 2 (95% of the PSF) | ||
|
|
||
| attenuation image filename := umap_zoomed.hv | ||
|
|
||
| End Projector Pair Using SPECTGPU Parameters := | ||
| subset sensitivity filenames := sens_%d | ||
| recompute sensitivity := 1 | ||
| z zoom := 0.5 | ||
| xy output image size (in pixels) := 128 | ||
| z output image size (in pixels) := 128 | ||
| end PoissonLogLikelihoodWithLinearModelForMeanAndProjData Parameters:= | ||
|
|
||
| ; best to specifiy an initial image (e.g. filled with 1) for sizes | ||
| ; or see OSMAPOSL_osem_with_interfiltering.par and FBP2D_SPECT.par for some keywords | ||
| ;initial estimate:= init.hv | ||
| output filename prefix := outgpu | ||
|
|
||
| ; needs to be a divisor of the number of views | ||
| number of subsets:= 8 | ||
| number of subiterations:= 16 | ||
| Save estimates at subiteration intervals:= 16 | ||
|
|
||
| END := |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Back Projector parameters:= | ||
| type := SPECTGPU | ||
| Back projector Using SPECTGPU Parameters := | ||
| attenuation image filename := umap_inverted.hv | ||
| collimator slope := 0.01 | ||
| collimator sigma 0(cm) := 0.07 | ||
| number of PSF sigmas := 2 ; default 2 (95% of the PSF) | ||
| End Back Projector Using SPECTGPU Parameters := | ||
| End:= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| Forward Projector parameters:= | ||
| type := SPECTGPU | ||
| Forward projector Using SPECTGPU Parameters := | ||
| attenuation image filename := umap_inverted.hv | ||
| collimator slope := 0.01 | ||
| collimator sigma 0(cm) := 0.07 | ||
| number of PSF sigmas := 2 ; default 2 (95% of the PSF) | ||
| End Forward Projector Using SPECTGPU Parameters := | ||
| End:= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| projector pair parameters:= | ||
| projector pair type := SPECTGPU | ||
| Projector Pair Using SPECTGPU Parameters := | ||
| ; width of PSF | ||
|
|
||
| ;PSF type of correction { 3D } | ||
| ; | ||
| ; These values are mostly dependent on your collimator. | ||
| ; the PSF is modelled as a Gaussian with sigma dependent on the distance from the collimator | ||
| ; sigma_at_depth = collimator_slope * depth_in_cm + collimator sigma 0(cm) | ||
| ;collimator slope := 0.0163 | ||
| ;collimator sigma 0(cm) := 0.1466 | ||
| ;number of PSF sigmas := 2 ; default 2 (95% of the PSF) | ||
|
|
||
|
|
||
| ;attenuation image filename := ${CMAKE_SOURCE_DIR}/recon_test_pack/SPECT/SPECTUB/attMapRec.hv | ||
|
|
||
| End Projector Pair Using SPECTGPU Parameters := | ||
| End projector pair parameters:= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| projector pair parameters:= | ||
| projector pair type:= Matrix | ||
| Projector Pair Using Matrix Parameters := | ||
| Matrix type := SPECT UB | ||
| Projection Matrix By Bin SPECT UB Parameters:= | ||
| ; width of PSF | ||
| ;maximum number of sigmas:= 1.3 | ||
|
|
||
| ;PSF type of correction { 2D // 3D // Geometrical } | ||
| psf type:= Geometrical | ||
| ; next 2 parameters define the PSF. They are ignored if psf_type is "Geometrical" | ||
| ; These values are mostly dependent on your collimator. | ||
| ; the PSF is modelled as a Gaussian with sigma dependent on the distance from the collimator | ||
| ; sigma_at_depth = collimator_slope * depth_in_cm + collimator sigma 0(cm) | ||
| ;collimator slope := 0.0163 | ||
| ;collimator sigma 0(cm) := 0.1466 | ||
|
|
||
| ;Attenuation correction { Simple // Full // No } | ||
| ;attenuation type := Simple | ||
| ;Values in attenuation map in cm-1 | ||
| ;attenuation map := umap_zoomed.hv | ||
|
|
||
| ;Mask properties { Cylinder // Attenuation Map // Explicit Mask // No} | ||
| ;mask type := Explicit Mask | ||
| ;mask file := mask.hv | ||
|
|
||
| ; if next variable is set to 0, only a single view is kept in memory | ||
| keep all views in cache:=1 | ||
|
|
||
| End Projection Matrix By Bin SPECT UB Parameters:= | ||
| End Projector Pair Using Matrix Parameters := | ||
| End projector pair parameters:= |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| FBP2DParameters := | ||
| output filename prefix := out/FBP | ||
| input file := ../SPECTUB/input.hs | ||
| Z output image size (in pixels):=64 | ||
| z zoom:=.5 | ||
| xy output image size (in pixels) := 129 | ||
| Back Projector type:= matrix | ||
| Back Projector Using Matrix Parameters := | ||
| Matrix type := SPECT UB | ||
| Projection Matrix By Bin SPECT UB Parameters:= | ||
|
danieldeidda marked this conversation as resolved.
Outdated
|
||
| psf type:= Geometrical | ||
| attenuation type := No | ||
| mask type := No | ||
| ;mask file := ../SPECTUB/mask.hv | ||
|
|
||
| ; no point in keeping things in memory as FBP runs the projector only once | ||
| keep all views in cache := 0 | ||
|
|
||
| End Projection Matrix By Bin SPECT UB Parameters:= | ||
| End Back Projector Using Matrix Parameters := | ||
| end:= | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.