Skip to content

Commit

Permalink
Remove not needed backend
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmaostc committed Dec 22, 2023
1 parent b13fa67 commit f976853
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 28 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
24 changes: 9 additions & 15 deletions src/iradon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand Down
21 changes: 9 additions & 12 deletions src/radon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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(μ)
Expand Down

0 comments on commit f976853

Please sign in to comment.