Skip to content

Commit f18f5b4

Browse files
authored
Add axes (#41)
* Add axes * Test axes * Use Base.axes * Use axes
1 parent 0de04f2 commit f18f5b4

File tree

11 files changed

+55
-49
lines changed

11 files changed

+55
-49
lines changed

docs/lit/examples/01-tomography.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [Tomography overview](@id 01-tomography)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [Tomography overview](@id 01-tomography)
3+
64
This page gives an overview of the Julia package
75
[`Sinograms.jl`](https://github.com/JuliaImageRecon/Sinograms.jl).
86
@@ -30,7 +28,7 @@ using MIRTjim: jim, prompt
3028
using InteractiveUtils: versioninfo
3129

3230

33-
# The following line is helpful when running this example.jl file as a script;
31+
# The following line is helpful when running this file as a script;
3432
# this way it will prompt user to hit a key after each figure is displayed.
3533

3634
isinteractive() ? jim(:prompt, true) : prompt(:draw);

docs/lit/examples/02-sino-geom.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [2D sinogram geometry](@id 02-sino-geom)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [2D sinogram geometry](@id 02-sino-geom)
3+
64
This page describes the 2D sinogram geometries
75
available in the Julia package
86
[`Sinograms.jl`](https://github.com/JuliaImageRecon/Sinograms.jl).
@@ -34,7 +32,7 @@ using MIRTjim: jim, prompt
3432
using InteractiveUtils: versioninfo
3533

3634

37-
# The following line is helpful when running this example.jl file as a script;
35+
# The following line is helpful when running this file as a script;
3836
# this way it will prompt user to hit a key after each figure is displayed.
3937

4038
isinteractive() ? jim(:prompt, true) : prompt(:draw);

docs/lit/examples/03-parallel-beam.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [Parallel-beam tomography](@id 03-parallel-beam)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [Parallel-beam tomography](@id 03-parallel-beam)
3+
64
This page describes parallel-beam tomographic image reconstruction
75
using the Julia package
86
[`Sinograms.jl`](https://github.com/JuliaImageRecon/Sinograms.jl).
@@ -33,7 +31,7 @@ using Unitful: mm
3331
using MIRTjim: jim, prompt
3432

3533

36-
# The following line is helpful when running this example.jl file as a script;
34+
# The following line is helpful when running this file as a script;
3735
# this way it will prompt user to hit a key after each figure is displayed.
3836

3937
isinteractive() ? jim(:prompt, true) : prompt(:draw);
@@ -65,7 +63,7 @@ ob = shepp_logan(SheppLogan(); fovs = fovs(ig), u = (1, 1, μ))
6563

6664
# Radon transform of Shepp-Logan phantom:
6765
sino = radon(rays(sg), ob)
68-
jim(sg.r, sg.ad, sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
66+
jim(axes(sg), sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
6967

7068
## Image reconstruction via FBP
7169
# Here we start with a "plan",

docs/lit/examples/04-fan-arc.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [Fan-beam tomography: arc detector](@id 04-fan-arc)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [Fan-beam tomography: arc detector](@id 04-fan-arc)
3+
64
This page describes fan-beam tomographic image reconstruction
75
using the Julia package
86
[`Sinograms.jl`](https://github.com/JuliaImageRecon/Sinograms.jl).
@@ -43,14 +41,14 @@ using ImagePhantoms: SheppLogan, shepp_logan, radon, phantom
4341
using MIRTjim: jim, prompt
4442

4543

46-
# The following line is helpful when running this example.jl file as a script;
44+
# The following line is helpful when running this file as a script;
4745
# this way it will prompt user to hit a key after each figure is displayed.
4846

4947
isinteractive() ? jim(:prompt, true) : prompt(:draw);
5048

5149

5250
#=
53-
### Fan-beam sinogram of Shepp-Logan phantom
51+
## Fan-beam sinogram of Shepp-Logan phantom
5452
5553
For illustration,
5654
we start by synthesizing
@@ -81,7 +79,7 @@ ob = shepp_logan(SheppLogan(); fovs = fovs(ig), u = (1, 1, μ))
8179

8280
# Arc fan-beam sinogram for Shepp-Logan phantom:
8381
sino = radon(rays(sg), ob)
84-
jim(sg.r, sg.ad, sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
82+
jim(axes(sg), sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
8583

8684

8785
#=

docs/lit/examples/05-fan-flat.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [Fan-beam tomography: flat detector](@id 05-fan-flat)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [Fan-beam tomography: flat detector](@id 05-fan-flat)
3+
64
This page describes fan-beam tomographic image reconstruction
75
using the Julia package
86
[`Sinograms.jl`](https://github.com/JuliaImageRecon/Sinograms.jl).
@@ -38,7 +36,7 @@ using ImagePhantoms: SheppLogan, shepp_logan, radon, phantom
3836
using MIRTjim: jim, prompt
3937

4038

41-
# The following line is helpful when running this example.jl file as a script;
39+
# The following line is helpful when running this file as a script;
4240
# this way it will prompt user to hit a key after each figure is displayed.
4341

4442
isinteractive() ? jim(:prompt, true) : prompt(:draw);
@@ -77,7 +75,7 @@ ob = shepp_logan(SheppLogan(); fovs = fovs(ig), u = (1, 1, μ))
7775

7876
# Arc fan-beam sinogram for Shepp-Logan phantom:
7977
sino = radon(rays(sg), ob)
80-
jim(sg.r, sg.ad, sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
78+
jim(axes(sg), sino; title="Shepp-Logan sinogram", xlabel="r", ylabel="ϕ")
8179

8280

8381
#=

docs/lit/examples/06-fan-short.jl

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#=
2-
# [Fan-beam tomography: arc detector](@id 06-fan-short)
2+
# [Fan-beam tomography: short scan](@id 06-fan-short)
33
44
This page describes fan-beam tomographic image reconstruction
55
using the Julia package
@@ -45,14 +45,14 @@ using ImagePhantoms: SheppLogan, shepp_logan, radon, phantom
4545
using MIRTjim: jim, prompt
4646

4747

48-
# The following line is helpful when running this example.jl file as a script;
48+
# The following line is helpful when running this file as a script;
4949
# this way it will prompt user to hit a key after each figure is displayed.
5050

5151
isinteractive() ? jim(:prompt, true) : prompt(:draw);
5252

5353

5454
#=
55-
### Fan-beam sinogram of Shepp-Logan phantom
55+
## Fan-beam sinogram of Shepp-Logan phantom
5656
5757
For illustration,
5858
we start by synthesizing
@@ -67,13 +67,19 @@ but units are optional.
6767
# Use `ImageGeom` to define the image geometry.
6868
ig = ImageGeom(MaskCircle(); dims=(128,126), deltas = (2mm,2mm) )
6969

70-
# Use `SinoFanArc` to define the sinogram geometry,
71-
# with the `:short` option for `orbit` to make a short scan.
70+
#=
71+
Use `SinoFanArc` to define the sinogram geometry,
72+
with the `:short` option for `orbit` to make a short scan.
73+
Note that even though we specify `na = 100`
74+
we end up with `na = 67` views
75+
because of the `:short` option.
76+
=#
7277
sg = SinoFanArc( :short, ;
7378
nb = 130, d = 3.2mm, na = 100, dsd = 400mm, dod = 140mm,
7479
)
7580

76-
# Examine the geometry to verify the FOV:
81+
# Examine the geometry to verify the FOV.
82+
# The `na=67` blue dots show the `:short` scan.
7783
jim(axes(ig), ig.mask; prompt=false)
7884
sino_geom_plot!(sg, ig)
7985

@@ -86,7 +92,7 @@ ob = shepp_logan(SheppLogan(); fovs = fovs(ig), u = (1, 1, μ))
8692

8793
# Short arc fan-beam sinogram for Shepp-Logan phantom:
8894
sino = radon(rays(sg), ob)
89-
jim(sg.r, sg.ad, sino; title="Shepp-Logan 'short' sinogram",
95+
jim(axes(sg), sino; title="Shepp-Logan 'short' sinogram",
9096
xlabel="r", ylabel="ϕ")
9197

9298

@@ -98,17 +104,21 @@ which would save work if we were reconstructing many images.
98104

99105
plan = plan_fbp(sg, ig)
100106

101-
# Examine Parker weights
102-
jim(sg.r, sg.ad, plan.parker_weight; title = "Parker weights",
107+
# Examine Parker weights:
108+
jim(axes(sg), plan.parker_weight; title = "Parker weights",
103109
xlabel="r", ylabel="ϕ")
104110

105-
# Finally perform FBP
111+
# Finally perform FBP:
106112
fbp_image, sino_filt = fbp(plan, sino);
107113

108114
# A narrow color window is needed to see the soft tissue structures:
109115
clim = (0.9, 1.1) .* μ
110116
jim(axes(ig), fbp_image, "FBP image for 'short' arc case"; clim)
111117

112-
# For comparison, here is the ideal phantom image
118+
# For comparison, here is the ideal phantom image:
113119
true_image = phantom(axes(ig)..., ob, 2)
114120
jim(axes(ig)..., true_image, "True phantom image"; clim)
121+
122+
# Here is the difference image.
123+
# Better sampling would reduce the errors.
124+
jim(axes(ig)..., fbp_image - true_image, "Error image")

docs/lit/examples/07-fdk.jl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
#---------------------------------------------------------
2-
# # [CBCT FDK](@id 07-fdk)
3-
#---------------------------------------------------------
4-
51
#=
2+
# [CBCT FDK](@id 07-fdk)
3+
64
This page describes image reconstruction
75
for cone-beam computed tomography (CBCT)
86
with both arc and flat detectors
@@ -38,7 +36,7 @@ using ImagePhantoms: radon, phantom
3836
using MIRTjim: jim, prompt
3937

4038

41-
# The following line is helpful when running this example.jl file as a script;
39+
# The following line is helpful when running this file as a script;
4240
# this way it will prompt user to hit a key after each figure is displayed.
4341

4442
isinteractive() ? jim(:prompt, true) : prompt(:draw);

src/geom/ct-geom.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@ using the parallel, fan beam arc, or flat fan beam geometry.
66
2022-05-11, Jason Hu, Jeff Fessler translated from ct_geom.m in MIRT
77
=#
88

9-
export dims, downsample, oversample, rays
9+
export dims, downsample, oversample, rays, axes
1010

1111

1212
# Methods common to all types
1313

1414
dims(st::CtGeom) = (st.ns, st.nt, st.na)::NTuple{3,Int}
1515

16+
# use ° via `angles()` because mainly for plots
17+
Base.axes(st::CtGeom) = (ct_geom_s(st), ct_geom_t(st), angles(st))
18+
1619
ct_geom_ws(st::CtGeom) = ((st.ns-1)//2 + st.offset_s)::Toffset
1720
ct_geom_wt(st::CtGeom) = ((st.nt-1)//2 + st.offset_t)::Toffset
1821

src/geom/sino-geom.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,16 @@ sinogram geometry definitions for 2D tomographic image reconstruction
55
2022-01-22, copied from MIRT.jl and updated to support Unitful values
66
=#
77

8-
export dims, downsample, oversample, rays
8+
export dims, downsample, oversample, rays, axes
99
export sino_w, sino_s
1010

1111
# Methods common to all types
1212

1313
dims(sg::SinoGeom) = (sg.nb, sg.na)::NTuple{2,Int}
1414

15+
# use ° via `angles()` because mainly for plots
16+
Base.axes(sg::SinoGeom) = (sino_s(sg), angles(sg))
17+
1518
sino_w(sg::SinoGeom) = Toffset((sg.nb-1)/2 + sg.offset)::Toffset
1619

1720
#sino_s(sg::SinoGeom) = sg.d * ((0:sg.nb-1) .- sino_w(sg))

test/geom/ct-geom.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ test/geom/ct-geom.jl
55
using Sinograms: RealU, CtSourceHelix
66
using Sinograms: CtGeom, CtParallel, CtFan
77
using Sinograms: CtPar, CtFanArc, CtFanFlat
8-
using Sinograms: dims, ones, zeros, angles, rays, downsample, oversample
8+
using Sinograms: dims, ones, zeros, angles, rays, axes, downsample, oversample
99
using Sinograms: footprint_size
1010
import Sinograms as SG
1111
using ImageGeoms: ImageGeom
@@ -78,6 +78,7 @@ function _test_prop(
7878
# common methods
7979
D = length(dims(st))
8080
@test (@inferred dims(st)) isa Dims{D}
81+
@test (@inferred axes(st)) isa Tuple
8182
@test (@inferred angles(st)) isa AbstractVector
8283
@test (@inferred ones(st)) isa Array{Float32,D}
8384
@test (@inferred zeros(st)) isa Array{Float32,D}

0 commit comments

Comments
 (0)