Skip to content

Commit

Permalink
Add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roflmaostc committed Dec 2, 2023
1 parent 5fe9c17 commit b9f3767
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
18 changes: 13 additions & 5 deletions test/notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ end
simshow(sinogram[:, :, 1])

# ╔═╡ 7fcb40e4-4530-4ce1-a267-84b46309ab2a
@show iradon(sinogram, [0f0, π*1f0])
@show iradon(sinogram, [0f0, π*0.5])

# ╔═╡ c4cd76e9-1685-40b4-bde6-2d1b6c03fa09
simshow(iradon(sinogram, [0f0, π*0.5]))[:, :, 1]

# ╔═╡ 49629e15-c5f4-42ff-b196-24e13124f8f3
@show I_r = iradon(sinogram, Float32[2pi - pi/4])
@show I_r = iradon(sinogram, Float32[π/4 + π])

# ╔═╡ be118fec-3051-47a4-bf15-ac9d8d8c8e2e
sum(iradon(sinogram, Float32[2pi - pi/4]))
Expand Down Expand Up @@ -93,7 +96,7 @@ md"# Radon"
# ╔═╡ 372f9ed3-a1d0-4368-bdba-800b4650af9e
begin
array = zeros((16, 16,1))
array[12,9] = 1
array[12,11] = 1
end

# ╔═╡ 2312af02-941f-4ab2-b8b8-02ba437bf5d0
Expand All @@ -115,7 +118,7 @@ begin
i = 1
for θ in angles
cc = size(sg, 1) ÷ 2 + 1
x,y = (11, 8) .- (cc)
x,y = (11, 10) .- (cc)

y,x = [cos(θ) sin(θ); -sin(θ) cos(θ)] * [x, y]

Expand All @@ -142,8 +145,11 @@ size(sg)
# ╔═╡ d35fcf11-fe18-494e-b5af-c5cba4b0a1a3
simshow(theory[:, :, 1])

# ╔═╡ e44d43b1-e54e-44f7-bd5d-44bd6a79b8e4
simshow(sg[:, :, 1])

# ╔═╡ a3c4fd5b-a297-4875-8389-b42d82fc0dfc
(sg, theory, rtol=0.3)
(sg, theory, rtol=0.4)

# ╔═╡ 937726a1-64af-4fac-8d86-d115533183a0
begin
Expand Down Expand Up @@ -206,6 +212,7 @@ radon(zeros((128, 128, 1)), range(0, 2pi, 300))
# ╠═071b6c72-86ec-461a-ad7d-adf0fc696399
# ╠═575487cf-faa2-41eb-9062-f030741be67b
# ╠═7fcb40e4-4530-4ce1-a267-84b46309ab2a
# ╠═c4cd76e9-1685-40b4-bde6-2d1b6c03fa09
# ╠═49629e15-c5f4-42ff-b196-24e13124f8f3
# ╠═be118fec-3051-47a4-bf15-ac9d8d8c8e2e
# ╠═80970ba6-a09f-46db-8b15-fa7226cdc400
Expand Down Expand Up @@ -234,6 +241,7 @@ radon(zeros((128, 128, 1)), range(0, 2pi, 300))
# ╠═a9719576-ce8a-4adf-95e2-18e748bd5a02
# ╠═5bceb117-c839-4bfb-84fe-2a92be024fa6
# ╠═d35fcf11-fe18-494e-b5af-c5cba4b0a1a3
# ╠═e44d43b1-e54e-44f7-bd5d-44bd6a79b8e4
# ╠═a3c4fd5b-a297-4875-8389-b42d82fc0dfc
# ╠═937726a1-64af-4fac-8d86-d115533183a0
# ╠═8ce53564-3bdf-4ab7-9ec5-cd4560fdd4be
Expand Down
10 changes: 9 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,16 @@ using Test

@testset "RadonKA.jl" begin

@testset "Simple iradon test" begin
sinogram = zeros(Float32, (9, 2, 1))
sinogram[5, :, 1] .= 1
@test iradon(sinogram, [0.0f0, π * 0.5]) [0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 1.0 1.0 1.0 1.0 2.0 1.0 1.0 1.0 0.5; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.5 0.0 0.0 0.0 0.0;;;]

@testset "radon without absorption" begin
@test iradon(sinogram, Float32[π / 4 + π]) [0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.46446568 6.7434956f-7 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 1.4142132 0.0 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 1.4142135 0.0 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 1.4142132 0.0 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 1.4142137 0.0 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.4142133 0.0 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.4142135 0.0; 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0;;;]

end

@testset "Compare with theoretical radon" begin

array = zeros((16, 16,1))
array[12,9] = 1
Expand Down

0 comments on commit b9f3767

Please sign in to comment.