Fri, 03 May 2024 09:13:05 -0500
data sources
8
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
1 | # From https://github.com/LMescheder/Radon.jl/blob/master/src/Radon.jl |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
2 | # Updated to modern Julia. Fixed radon! to zero out `radonim`. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
3 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
4 | __precompile__() |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
5 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
6 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
7 | module Radon |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
8 | export radon!, backproject! |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
9 | # package code goes here |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
10 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
11 | function radon(im::AbstractArray{T, 2}) where T<:AbstractFloat |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
12 | Nx, Ny = size(im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
13 | radonim = similar(im, min(Nx, Ny), max(Nx, Ny)) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
14 | radon!(radonim, im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
15 | radonim |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
16 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
17 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
18 | function radon!(radonim::AbstractArray{T, 2}, im::AbstractArray{T, 2}) where T<:AbstractFloat |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
19 | Nφ, Ns = size(radonim) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
20 | Nx, Ny = size(im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
21 | Ldiag = hypot(Nx, Ny) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
22 | K = round(Int, Ldiag) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
23 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
24 | dLz = Ldiag/(K-1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
25 | dLs = Ldiag/(Ns-1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
26 | dφ = π/Nφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
27 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
28 | @inbounds for is = 1:Ns, iφ = 1:Nφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
29 | φ = (iφ-1)*dφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
30 | s = -Ldiag/2 + (is-1)*dLs |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
31 | tx = cos(φ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
32 | ty = sin(φ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
33 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
34 | radonim[iφ, is] = zero(T) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
35 | for k=1:K |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
36 | z = -Ldiag/2 + (k-1)*dLz |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
37 | x = round(Int, Nx/2 + z*ty + s*tx) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
38 | y = round(Int, Ny/2 - z*tx + s*ty) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
39 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
40 | if 1 <= x <= Nx && 1 <= y <= Ny |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
41 | radonim[iφ, is] += im[x, y]*dLz |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
42 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
43 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
44 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
45 | radonim |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
46 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
47 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
48 | function backproject(radonim::AbstractArray{T, 2}) where T<:AbstractFloat |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
49 | Nφ, Ns = size(radonim) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
50 | im = similar(radonim, Ns, Ns) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
51 | backproject!(im, radonim) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
52 | im |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
53 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
54 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
55 | function backproject!(im::AbstractArray{T, 2}, radonim::AbstractArray{T, 2}) where T<:AbstractFloat |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
56 | Nφ, Ns = size(radonim) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
57 | Nx, Ny = size(im) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
58 | Ldiag = hypot(Nx, Ny) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
59 | K = round(Int, Ldiag) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
60 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
61 | dLz = Ldiag/(K-1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
62 | dLs = Ldiag/(Ns-1) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
63 | dφ = π/Nφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
64 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
65 | im .= 0. |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
66 | @inbounds for is = 1:Ns, iφ = 1:Nφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
67 | φ = (iφ-1)*dφ |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
68 | s = -Ldiag/2 + (is-1)*dLs |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
69 | tx = cos(φ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
70 | ty = sin(φ) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
71 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
72 | for k=1:K |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
73 | z = -Ldiag/2 + (k-1)*dLz |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
74 | x = round(Int, Nx/2 + z*ty + s*tx) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
75 | y = round(Int, Ny/2 - z*tx + s*ty) |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
76 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
77 | if 1 <= x <= Nx && 1 <= y <= Ny |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
78 | im[x, y] += radonim[iφ, is]*dLz |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
79 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
80 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
81 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
82 | im |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
83 | end |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
84 | |
e4ad8f7ce671
Added PET and updated README
Neil Dizon <neil.dizon@helsinki.fi>
parents:
diff
changeset
|
85 | end # module |