From f97685375c9bbd50320a155ac3fe13e5977b037b Mon Sep 17 00:00:00 2001 From: roflmaostc Date: Fri, 22 Dec 2023 15:55:31 +0100 Subject: [PATCH] Remove not needed backend --- README.md | 2 +- src/iradon.jl | 24 +++++++++--------------- src/radon.jl | 21 +++++++++------------ 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/README.md b/README.md index 755192f..c268a01 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,7 @@ simshow(backproject) See either the [documentation](https://roflmaostc.github.io/RadonKA.jl/dev/tutorial). Otherwise, this [example](https://github.com/roflmaostc/RadonKA.jl/blob/main/examples/example_radon_iradon.jl) shows the main features, including CUDA support. There is one tutorial about [Least Square Optimization](https://github.com/roflmaostc/RadonKA.jl/blob/main/examples/CT_reconstruction.jl). -Another one cover how the Radon transform is used in [Volumetric Additive Manufacturing](https://github.com/roflmaostc/RadonKA.jl/blob/main/examples/volumetric_printing.jl). +Another one covers how the Radon transform is used in [Volumetric Additive Manufacturing](https://github.com/roflmaostc/RadonKA.jl/blob/main/examples/volumetric_printing.jl). # Development File an [issue](https://github.com/roflmaostc/RadonKA.jl/issues) on [GitHub](https://github.com/roflmaostc/RadonKA.jl) if you encounter any problems. diff --git a/src/iradon.jl b/src/iradon.jl index 4427e93..750c851 100644 --- a/src/iradon.jl +++ b/src/iradon.jl @@ -7,24 +7,21 @@ Calculates the simple Filtered Backprojection in CT with applying a ramp filter in Fourier space. """ -function filtered_backprojection(sinogram::AbstractArray{T}, θs::AbstractVector, μ=nothing; - backend=KernelAbstractions.get_backend(sinogram)) where T +function filtered_backprojection(sinogram::AbstractArray{T}, θs::AbstractVector, μ=nothing) where T filter = similar(sinogram, (size(sinogram, 1),)) filter .= rr(T, (size(sinogram, 1), )) p = plan_fft(sinogram, (1,)) sinogram = real(inv(p) * (p * sinogram .* ifftshift(filter))) - return iradon(sinogram, θs, μ, backend=backend) + return iradon(sinogram, θs, μ) end # handle 2D -iradon(sinogram::AbstractArray{T, 2}, angles::AbstractArray{T2, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(sinogram)) where {T, T2} = - view(iradon(reshape(sinogram, (size(sinogram)..., 1)), T.(angles), μ; backend), :, :, 1) +iradon(sinogram::AbstractArray{T, 2}, angles::AbstractArray{T2, 1}, μ=nothing) where {T, T2} = + view(iradon(reshape(sinogram, (size(sinogram)..., 1)), T.(angles), μ), :, :, 1) -iradon(sinogram::AbstractArray{T, 3}, angles::AbstractArray{T2, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(sinogram)) where {T, T2} = - iradon(sinogram, T.(angles), μ; backend) +iradon(sinogram::AbstractArray{T, 3}, angles::AbstractArray{T2, 1}, μ=nothing) where {T, T2} = + iradon(sinogram, T.(angles), μ) """ iradon(sinogram, θs, μ=nothing) @@ -44,12 +41,10 @@ If `μ != nothing`, then the rays are attenuated with `exp(-μ * dist)` where `d is the distance to the circular boundary of the field of view. `μ` is in units of pixel length. So `μ=1` corresponds to an attenuation of `exp(-1)` if propagated through one pixel. -# Keywords -* `backend` can be either `CPU()` for multithreaded CPU execution or `CUDABackend()` for CUDA execution. In principle, all backends of KernelAbstractions.jl should work but are not tested. +In principle, all backends of KernelAbstractions.jl should work but are not tested. CUDA and CPU arrays are actively tested. See also [`radon`](@ref). - # Examples ```jldoctest julia> arr = zeros((5,2)); arr[2,:] .= 1; arr[4, :] .= 1 @@ -76,10 +71,9 @@ julia> iradon(arr, [0, π/2], 1) # exponential 0.0 0.0 0.0183994 0.0 0.0183994 0.0 ``` """ -function iradon(sinogram::AbstractArray{T, 3}, angles::AbstractArray{T, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(sinogram)) where T +function iradon(sinogram::AbstractArray{T, 3}, angles::AbstractArray{T, 1}, μ=nothing) where T @assert isodd(size(sinogram, 1)) && size(sinogram, 2) == length(angles) - + backend=KernelAbstractions.get_backend(sinogram) absorption_f = let μ=μ if isnothing(μ) (x, y, x_start, y_start) -> one(T) diff --git a/src/radon.jl b/src/radon.jl index 8d89f05..fb98265 100644 --- a/src/radon.jl +++ b/src/radon.jl @@ -2,17 +2,15 @@ export radon -radon(img::AbstractArray{T, 3}, angles::AbstractArray{T2, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(img)) where {T, T2} = - radon(img, T.(angles), μ; backend) +radon(img::AbstractArray{T, 3}, angles::AbstractArray{T2, 1}, μ=nothing) where {T, T2} = + radon(img, T.(angles), μ) # handle 2D -radon(img::AbstractArray{T, 2}, angles::AbstractArray{T2, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(img)) where {T, T2} = - view(radon(reshape(img, (size(img)..., 1)), T.(angles), μ; backend), :, :, 1) +radon(img::AbstractArray{T, 2}, angles::AbstractArray{T2, 1}, μ=nothing) where {T, T2} = + view(radon(reshape(img, (size(img)..., 1)), T.(angles), μ), :, :, 1) """ - radon(I, θs, μ=nothing; backend=KernelAbstractions.get_backend(I)) + radon(I, θs, μ=nothing) Calculates the parallel Radon transform of the AbstractArray `I`. The first two dimensions are y and x. The third dimension is z, the rotational axis. @@ -28,8 +26,7 @@ If `μ != nothing`, then the rays are attenuated with `exp(-μ * dist)` where `d is the distance to the circular boundary of the field of view. `μ` is in units of pixel length. So `μ=1` corresponds to an attenuation of `exp(-1)` if propagated through one pixel. -# Keywords -* `backend` can be either `CPU()` for multithreaded CPU execution or `CUDABackend()` for CUDA execution. In principle, all backends of KernelAbstractions.jl should work but are not tested. +In principle, all backends of KernelAbstractions.jl should work but are not tested. CUDA and CPU arrays are actively tested. Please note: the implementation is not quite optimized for cache efficiency and @@ -50,10 +47,10 @@ julia> radon(arr, [0, π/4, π/2]) 0.0 0.0 0.0 ``` """ -function radon(img::AbstractArray{T, 3}, angles::AbstractArray{T, 1}, μ=nothing; - backend=KernelAbstractions.get_backend(img)) where T +function radon(img::AbstractArray{T, 3}, angles::AbstractArray{T, 1}, μ=nothing) where T @assert iseven(size(img, 1)) && iseven(size(img, 2)) && size(img, 1) == size(img, 2) "Arrays has to be quadratic and even sized shape" - + + backend = KernelAbstractions.get_backend(img) absorption_f = let μ=μ if isnothing(μ)