-
Notifications
You must be signed in to change notification settings - Fork 168
CUDA Zeng forward and back projectors in RTK #977
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: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -44,6 +44,7 @@ def build_parser(): | |
| "JosephAttenuated", | ||
| "CudaRayCast", | ||
| "Zeng", | ||
| "CudaZeng", | ||
| "MIP", | ||
| "CudaWrapRayCast", | ||
| ], | ||
|
|
@@ -161,6 +162,12 @@ def process(args_info): | |
| forwardProjection = rtk.ZengForwardProjectionImageFilter[ | ||
| OutputImageType, OutputImageType | ||
| ].New() | ||
| elif args_info.fp == "CudaZeng": | ||
| if hasattr(itk, "CudaImage"): | ||
| forwardProjection = rtk.CudaZengForwardProjectionImageFilter.New() | ||
| else: | ||
| print("The program has not been compiled with cuda option") | ||
| sys.exit(1) | ||
|
Comment on lines
+168
to
+170
Collaborator
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'd remove for consistency with the code below |
||
| elif args_info.fp == "MIP": | ||
| forwardProjection = rtk.MaximumIntensityProjectionImageFilter[ | ||
| OutputImageType, OutputImageType | ||
|
|
@@ -191,7 +198,7 @@ def process(args_info): | |
| print("The program has not been compiled with cuda option") | ||
| sys.exit(1) | ||
|
|
||
| if args_info.fp in ["CudaWrapRayCast", "CudaRayCast"]: | ||
| if args_info.fp in ["CudaWrapRayCast", "CudaRayCast", "CudaZeng"]: | ||
| forwardProjection.SetInput( | ||
| itk.cuda_image_from_image(constantImageSource.GetOutput()) | ||
| ) | ||
|
|
@@ -218,9 +225,9 @@ def process(args_info): | |
| forwardProjection.SetSuperiorClipImage(superiorClipImage) | ||
| elif args_info.fp == "MIP": | ||
| forwardProjection.SetSuperiorClipImage(superiorClipImage) | ||
| if args_info.sigmazero and args_info.fp == "Zeng": | ||
| if args_info.sigmazero and args_info.fp in ["Zeng", "CudaZeng"]: | ||
| forwardProjection.SetSigmaZero(args_info.sigmazero) | ||
| if args_info.alphapsf and args_info.fp == "Zeng": | ||
| if args_info.alphapsf and args_info.fp in ["Zeng", "CudaZeng"]: | ||
| forwardProjection.SetAlpha(args_info.alphapsf) | ||
|
|
||
| forwardProjection.SetGeometry(geometry) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,7 @@ def add_rtkprojectors_group(parser): | |
| "--fp", | ||
| "-f", | ||
| help="Forward projection method", | ||
| choices=["Joseph", "CudaRayCast", "JosephAttenuated", "Zeng"], | ||
| choices=["Joseph", "CudaRayCast", "JosephAttenuated", "Zeng", "CudaZeng"], | ||
| default="Joseph", | ||
| ) | ||
| rtkprojectors_group.add_argument( | ||
|
|
@@ -26,6 +26,7 @@ def add_rtkprojectors_group(parser): | |
| "CudaRayCast", | ||
| "JosephAttenuated", | ||
| "Zeng", | ||
| "CudaZeng", | ||
| ], | ||
| default="VoxelBasedBackProjection", | ||
| ) | ||
|
|
@@ -97,6 +98,14 @@ def SetBackProjectionFromArgParse(args_info, recon): | |
| recon.SetAlphaPSF(args_info.alphapsf) | ||
| if args_info.attenuationmap is not None: | ||
| recon.SetAttenuationMap(attenuation_map) | ||
| elif args_info.bp == "CudaZeng": | ||
| recon.SetBackProjectionFilter(ReconType.BackProjectionType_BP_CUDAZENG) | ||
| if args_info.sigmazero is not None: | ||
| recon.SetSigmaZero(args_info.sigmazero) | ||
| if args_info.alphapsf is not None: | ||
| recon.SetAlphaPSF(args_info.alphapsf) | ||
| if args_info.attenuationmap is not None: | ||
| recon.SetAttenuationMap(attenuation_map) | ||
|
|
||
|
Collaborator
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. This code duplicates "Zeng", I guess you can just add an |
||
|
|
||
| # Mimicks SetForwardProjectionFromGgo | ||
|
|
@@ -127,3 +136,11 @@ def SetForwardProjectionFromArgParse(args_info, recon): | |
| recon.SetAlphaPSF(args_info.alphapsf) | ||
| if args_info.attenuationmap is not None: | ||
| recon.SetAttenuationMap(attenuation_map) | ||
| elif args_info.fp == "CudaZeng": | ||
| recon.SetForwardProjectionFilter(ReconType.ForwardProjectionType_FP_CUDAZENG) | ||
| if args_info.sigmazero is not None: | ||
| recon.SetSigmaZero(args_info.sigmazero) | ||
| if args_info.alphapsf is not None: | ||
| recon.SetAlphaPSF(args_info.alphapsf) | ||
| if args_info.attenuationmap is not None: | ||
| recon.SetAttenuationMap(attenuation_map) | ||
|
Collaborator
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. Idem, duplicates Zeng code and can be mutualized. |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,9 @@ | ||
| section "Projectors" | ||
| option "fp" f "Forward projection method" values="Joseph","CudaRayCast","JosephAttenuated","Zeng" enum no default="Joseph" | ||
| option "bp" b "Back projection method" values="VoxelBasedBackProjection","Joseph","CudaVoxelBased","CudaRayCast","JosephAttenuated", "Zeng" enum no default="VoxelBasedBackProjection" | ||
| option "fp" f "Forward projection method" values="Joseph","CudaRayCast","JosephAttenuated","Zeng","CudaZeng" enum no default="Joseph" | ||
| option "bp" b "Back projection method" values="VoxelBasedBackProjection","Joseph","CudaVoxelBased","CudaRayCast","JosephAttenuated", "Zeng", "CudaZeng" enum no default="VoxelBasedBackProjection" | ||
| option "step" - "Step size along ray (for CudaRayCast only, default to the minimum voxel spacing of the input volume if set to 0)" double no default="0" | ||
| option "attenuationmap" - "Attenuation map relative to the volume to perfom the attenuation correction (JosephAttenuated and Zeng)" string no | ||
| option "sigmazero" - "PSF value at a distance of 0 meter of the detector (Zeng only)" double no | ||
| option "alphapsf" - "Slope of the PSF against the detector distance (Zeng only)" double no | ||
| option "attenuationmap" - "Attenuation map relative to the volume to perform the attenuation correction (JosephAttenuated, Zeng and CudaZeng)" string no | ||
| option "sigmazero" - "PSF value at a distance of 0 meter of the detector (Zeng and CudaZeng only)" double no | ||
| option "alphapsf" - "Slope of the PSF against the detector distance (Zeng and CudaZeng only)" double no | ||
| option "inferiorclipimage" - "Inferior clip of the ray for each pixel of the projections (Joseph only)" string no | ||
| option "superiorclipimage" - "Superior clip of the ray for each pixel of the projections (Joseph only)" string no |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /*========================================================================= | ||
| * | ||
| * Copyright RTK Consortium | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0.txt | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| *=========================================================================*/ | ||
| #ifndef rtkCudaZengBackProjectionImageFilter_h | ||
| #define rtkCudaZengBackProjectionImageFilter_h | ||
|
|
||
| #include "rtkConfiguration.h" | ||
| #ifdef RTK_USE_CUDA | ||
|
|
||
| # include "rtkBackProjectionImageFilter.h" | ||
| # include "RTKExport.h" | ||
| # include <itkCudaImage.h> | ||
| # include <itkCudaInPlaceImageFilter.h> | ||
| # include <itkImageBase.h> | ||
|
|
||
| namespace rtk | ||
| { | ||
|
|
||
| /** \class CudaZengBackProjectionImageFilter | ||
| * \brief CUDA implementation of the rotation-based Zeng backprojector. | ||
|
Collaborator
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. Can you add [Zeng et al, IEEE TMI, [Zeng et al, 1999, IEEE TMI, 10.1109/42.796285] |
||
| * | ||
| * The implementation reproduces the slice recursion of | ||
| * ZengBackProjectionImageFilter, including the depth-dependent Gaussian PSF | ||
| * and the optional attenuation map (input 2). | ||
| * | ||
| * \ingroup RTK Projector CudaImageToImageFilter | ||
| */ | ||
| class RTK_EXPORT CudaZengBackProjectionImageFilter | ||
| : public itk::CudaInPlaceImageFilter<itk::CudaImage<float, 3>, | ||
| itk::CudaImage<float, 3>, | ||
| BackProjectionImageFilter<itk::CudaImage<float, 3>, itk::CudaImage<float, 3>>> | ||
|
Collaborator
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. If I'm not mistaking, a large simplification would be to inherit from ZengBackProjectionImageFilter. Then all common members don't need to be declared. |
||
| { | ||
| public: | ||
| ITK_DISALLOW_COPY_AND_MOVE(CudaZengBackProjectionImageFilter); | ||
| using ImageType = itk::CudaImage<float, 3>; | ||
| /** Metadata-only image used to build the rotated-grid transforms. Using | ||
| * ImageBase avoids the CUDA image factory replacing itk::Image::New(). */ | ||
| using CPUImageType = itk::ImageBase<3>; | ||
| using ProjectorType = BackProjectionImageFilter<ImageType, ImageType>; | ||
| using Self = CudaZengBackProjectionImageFilter; | ||
| using Superclass = itk::CudaInPlaceImageFilter<ImageType, ImageType, ProjectorType>; | ||
| using Pointer = itk::SmartPointer<Self>; | ||
| using ConstPointer = itk::SmartPointer<const Self>; | ||
|
|
||
| itkNewMacro(Self); | ||
| itkOverrideGetNameOfClassMacro(CudaZengBackProjectionImageFilter); | ||
|
|
||
| itkGetConstMacro(SigmaZero, double); | ||
| itkSetMacro(SigmaZero, double); | ||
| itkGetConstMacro(Alpha, double); | ||
| itkSetMacro(Alpha, double); | ||
|
|
||
| protected: | ||
| CudaZengBackProjectionImageFilter(); | ||
| ~CudaZengBackProjectionImageFilter() override; | ||
| void | ||
| GPUGenerateData() override; | ||
|
|
||
| private: | ||
| double m_SigmaZero{ 1.5417233052142099 }; | ||
| double m_Alpha{ 0.016241189545787734 }; | ||
| void * m_CudaWorkspace{ nullptr }; | ||
| }; | ||
|
|
||
| } // namespace rtk | ||
| #endif // RTK_USE_CUDA | ||
| #endif // rtkCudaZengBackProjectionImageFilter_h | ||
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.
Can be mutualized with Zeng I believe