Skip to content

Commit 89e3472

Browse files
authored
Merge pull request #8 from JuliaImageRecon/nh/docs
Add documentation
2 parents 226fb4c + aa9b060 commit 89e3472

27 files changed

+1141
-13
lines changed

.github/workflows/CI.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,25 @@ jobs:
4848
${{ runner.os }}-
4949
- uses: julia-actions/julia-buildpkg@v1
5050
- uses: julia-actions/julia-runtest@v1
51+
52+
docs:
53+
name: Documentation
54+
runs-on: ubuntu-latest
55+
steps:
56+
- uses: actions/checkout@v4
57+
- uses: julia-actions/setup-julia@v1
58+
with:
59+
version: '1'
60+
- run: |
61+
julia --project=docs -e '
62+
using Pkg
63+
Pkg.develop(PackageSpec(path=pwd()))
64+
Pkg.instantiate()'
65+
- run: |
66+
julia --project=docs -e '
67+
using Documenter: DocMeta, doctest
68+
using AbstractImageReconstruction'
69+
- run: julia --project=docs docs/make.jl
70+
env:
71+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
72+
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,10 @@
1+
*.jl.cov
2+
*.jl.*.cov
3+
*.jl.mem
4+
docs/build/
5+
docs/site/
6+
docs/src/generated/
7+
8+
Manifest.toml
9+
110
/Manifest.toml

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
[![Build Status](https://github.com/JuliaImageRecon/AbstractImageReconstruction.jl/actions/workflows/CI.yml/badge.svg?branch=main)](https://github.com/JuliaImageRecon/AbstractImageReconstruction.jl/actions/workflows/CI.yml?query=branch%3Amain)
44

5+
[![](https://img.shields.io/badge/docs-latest-blue.svg)](https://JuliaImageRecon.github.io/AbstractImageReconstruction.jl/latest)
6+
7+
58
This package contains an interface and type hierarchy for image reconstruction algorithms and their parameters, together with associated utility tools.
69

710
## Installation

docs/Project.toml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[deps]
2+
AbstractImageReconstruction = "a4b4fdbf-6459-4ec9-990d-77e1fa24a91b"
3+
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
4+
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
5+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
6+
ImageGeoms = "9ee76f2b-840d-4475-b6d6-e485c9297852"
7+
ImagePhantoms = "71a99df6-f52c-4da1-bd2a-69d6f37f3252"
8+
LinearOperatorCollection = "a4a2c56f-fead-462a-a3ab-85921a5f2575"
9+
Literate = "98b081ad-f1c9-55d3-8b20-4c87d4299306"
10+
Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
11+
RadonKA = "86de8297-835b-47df-b249-c04e8db91db5"
12+
RegularizedLeastSquares = "1e9c538a-f78c-5de5-8ffb-0b6dbe892d23"
13+
14+
[compat]
15+
Documenter = "1"

docs/make.jl

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
using Documenter, Literate, AbstractImageReconstruction, Observables
2+
3+
# Generate examples
4+
OUTPUT_BASE = joinpath(@__DIR__(), "src/generated")
5+
INPUT_BASE = joinpath(@__DIR__(), "src/literate")
6+
for (_, dirs, _) in walkdir(INPUT_BASE)
7+
for dir in dirs
8+
OUTPUT = joinpath(OUTPUT_BASE, dir)
9+
INPUT = joinpath(INPUT_BASE, dir)
10+
for file in filter(f -> endswith(f, ".jl"), readdir(INPUT))
11+
Literate.markdown(joinpath(INPUT, file), OUTPUT)
12+
end
13+
end
14+
end
15+
16+
makedocs(
17+
format = Documenter.HTML(;
18+
prettyurls=get(ENV, "CI", "false") == "true",
19+
canonical="https://github.com/JuliaImageRecon/AbstractImageReconstruction.jl",
20+
assets=String[],
21+
collapselevel=1,
22+
),
23+
repo="https://github.com/JuliaImageRecon/AbstractImageReconstruction.jl/blob/{commit}{path}#{line}",
24+
modules = [AbstractImageReconstruction],
25+
sitename = "AbstractImageReconstruction.jl",
26+
authors = "Niklas Hackelberg, Tobias Knopp",
27+
pages = [
28+
"Home" => "index.md",
29+
"Example: Radon Reconstruction Package" => Any[
30+
"Introduction" => "example_intro.md",
31+
"Radon Data" => "generated/example/0_radon_data.md",
32+
"Interface" => "generated/example/1_interface.md",
33+
"Direct Reconstruction" => "generated/example/2_direct.md",
34+
"Direct Reconstruction Result" => "generated/example/3_direct_result.md",
35+
"Iterative Reconstruction" => "generated/example/4_iterative.md",
36+
"Iterative Reconstruction Result" => "generated/example/5_iterative_result.md",
37+
],
38+
"How to" => Any[
39+
"Serialization" => "generated/howto/serialization.md",
40+
"Caching" => "generated/howto/caching.md",
41+
"Observables" => "generated/howto/observables.md",
42+
],
43+
"API Reference" => "API/api.md",
44+
#"Regularization Terms" => "API/regularization.md"],
45+
46+
],
47+
pagesonly = true,
48+
checkdocs = :none,
49+
doctest = false,
50+
doctestfilters = [r"(\d*)\.(\d{4})\d+"]
51+
)
52+
53+
deploydocs(repo = "github.com/JuliaImageRecon/AbstractImageReconstruction.jl.git", push_preview = true)

docs/src/API/api.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# API for Solvers
2+
This page contains documentation of the public API of the AbstractImageReconstruction. In the Julia
3+
REPL one can access this documentation by entering the help mode with `?`
4+
5+
## Algorithm and Parameters
6+
```@docs
7+
AbstractImageReconstruction.AbstractImageReconstructionAlgorithm
8+
AbstractImageReconstruction.reconstruct
9+
Base.put!(::AbstractImageReconstructionAlgorithm, ::Any)
10+
Base.take!(::AbstractImageReconstructionAlgorithm)
11+
AbstractImageReconstruction.AbstractImageReconstructionParameters
12+
AbstractImageReconstruction.process
13+
AbstractImageReconstruction.parameter
14+
```
15+
16+
## RecoPlan
17+
```@docs
18+
AbstractImageReconstruction.RecoPlan
19+
Base.propertynames(::RecoPlan)
20+
Base.getproperty(::RecoPlan, ::Symbol)
21+
Base.getindex(::RecoPlan, ::Symbol)
22+
Base.setproperty!(::RecoPlan, ::Symbol, ::Any)
23+
AbstractImageReconstruction.setAll!
24+
AbstractImageReconstruction.clear!
25+
Base.ismissing(::RecoPlan, ::Symbol)
26+
Observables.on(::Any, ::RecoPlan, ::Symbol)
27+
Observables.off(::RecoPlan, ::Symbol, ::Any)
28+
AbstractImageReconstruction.build
29+
AbstractImageReconstruction.toPlan
30+
AbstractImageReconstruction.savePlan
31+
AbstractImageReconstruction.loadPlan
32+
AbstractImageReconstruction.loadListener!
33+
AbstractImageReconstruction.parent(::RecoPlan)
34+
AbstractImageReconstruction.parent!(::RecoPlan, ::RecoPlan)
35+
AbstractImageReconstruction.parentproperty
36+
AbstractImageReconstruction.parentproperties
37+
```
38+
39+
## Miscellaneous
40+
```@docs
41+
AbstractImageReconstruction.LinkedPropertyListener
42+
AbstractImageReconstruction.ProcessResultCache
43+
Base.hash(::AbstractImageReconstructionParameters, ::UInt64)
44+
AbstractImageReconstruction.toKwargs(::AbstractImageReconstructionParameters)
45+
AbstractImageReconstruction.fromKwargs
46+
AbstractImageReconstruction.toDict
47+
AbstractImageReconstruction.toDict!
48+
AbstractImageReconstruction.toDictValue
49+
AbstractImageReconstruction.toDictValue!
50+
```

docs/src/example_intro.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Small Reconstruction Package for Radon projections
2+
In this example we will implement a small image reconstruction package using `AbstractImageReconstruction.jl`. Our reconstruction package `OurRadonreco` aims to provide direct and iterative reconstruction algorithms for Radon projection data.
3+
4+
Most of the desired functionality is already implemented in various Julia packages. Our reconstruction package now needs to properly link these packages and transform the data into the appropriate formats for each package.
5+
6+
!!! note
7+
The example is intended for developers of reconstruction packages that use `AbstractImageReconstruction`. End-users of such a package can consult the result sections of the example to see the high-level interface of `AbstractImagerReconstruction` and should otherwise consult the documentation of the concrete reconstruction package itself.
8+
9+
## Installation
10+
We can install `AbstractImageReconstruction` using the Julia package manager. Open a Julia REPL and run the following command:
11+
12+
```julia
13+
using Pkg
14+
Pkg.add("AbstractImageReconstruction")
15+
```
16+
This will download and install AbstractImageReconstruction.jl and its dependencies. To install a different version, please consult the [Pkg documentation](https://pkgdocs.julialang.org/dev/managing-packages/#Adding-packages). In addition to AbstractImageReconstruction.jl, we will need a few more packages to get started, which we can install the same way.
17+
18+
19+
[RadonKA.jl](https://github.com/roflmaostc/RadonKA.jl/tree/main) provides us with fast Radon forward and backward projections, which we can use for direct reconstructions and to prepare sample data for our package.
20+
21+
[LinearOperatorCollection.jl](https://github.com/JuliaImageRecon/LinearOperatorCollection.jl) wraps the functionality of RadonKA.jl into a matrix-free linear operator, that can be used in iterative solvers.
22+
23+
[RegularizedLeastSquares.jl](https://github.com/JuliaImageRecon/RegularizedLeastSquares.jl) offers a variety of iterative solvers and regularization options.
24+
25+
[ImagePhantoms.jl](https://github.com/JuliaImageRecon/ImagePhantoms.jl) and [ImageGeoms.jl](https://github.com/JuliaImageRecon/ImageGeoms.jl) allow us to define digital software "phantoms", which we will use to test our reconstruction algorithms.
26+
27+
Lastly, we will use [CairoMakie.jl](https://docs.makie.org/stable/) to visualize our results.
28+
29+
## Outline
30+
[Radon Data](generated/example/0_radon_data.md): this section we will familiarise ourselves with RadonKA.jl and define a small data format for three-dimensional time series sinograms. We also create the inverse problem that we will solve in the rest of the example
31+
32+
[Interface](generated/example/1_interface.md): Here we define the abstract types we will use in our package and take a look at what we need to implement to interact with `AbstractImageReconstruction`. We also start with a first processing step of our algorithms.
33+
34+
[Direct Reconstruction](generated/example/2_direct.md): Now we extend our abstract types with a concrete implementation of reconstruction algorithms using the backprojection and filtered backprojection.
35+
36+
[Direct Reconstruction Result](generated/example/3_direct_result.md): This section shows how to use the algorithm we have just implemented.
37+
38+
[Iterative Reconstruction](generated/example/4_iterative.md): We finish our small example package by implementing an iterative reconstruction algorithm. For this algorithm we require more complex parametrization and data processing.
39+
40+
[Iterative Reconstruction Result](generated/example/5_iterative_result.md): The last section shows again how to use the just implemented algorithm. But it also highlights `RecoPlans`, which are a core utility of `AbstractImageReconstruction`. These plans allow a user to easily configure, save and load algorithms as templates.
41+
42+
For an even more detailed reconstruction package we refer to the magnetic particle imaging reconstruction package [MPIReco.jl](https://github.com/MagneticParticleImaging/MPIReco.jl).

docs/src/index.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# AbstractImageReconstruction.jl
2+
3+
*Abstract Interface for Medical Image Reconstruction Packages*
4+
5+
## Introduction
6+
7+
AbstractImageReconstruction.jl is a Julia package that serves as the core API for medical imaging packages. It provides implementations an interface and type hierarchy to represent and implement image reconstruction algorithms, their parameters and runtime behaviour. In particular, this package serves as the API of the Julia packages [MPIReco.jl](https://github.com/MagneticParticleImaging/MPIReco.jl).
8+
9+
## Features
10+
11+
* Reconstruction control flow defined with multiple-dispatch on extensible and exchangable type hierarchies
12+
* Storing, loading and manipulating of reconstruction algorithms with (partially) set parameters
13+
* Attaching callbacks to parameter changes with Observables.jl
14+
* Various generic utilities such as transparent caching of intermediate reconstruction results
15+
16+
## Installation
17+
18+
Within Julia, use the package manager:
19+
```julia
20+
using Pkg
21+
Pkg.add("AbstractImageReconstruction")
22+
```
23+
AbstractImageReconstruction is not intended to be used alone, but together with an image reconstruction package that implements the provided interface, such as [MPIReco.jl](https://github.com/MagneticParticleImaging/MPIReco.jl).
24+
25+
## Usage
26+
The actual construction of reconstruction algorithms depends on the implementation of the reconstruction package. Once an algorithm is constructed with the given parameters, images can be reconstructed as follows:
27+
28+
```julia
29+
using AbstractImageReconstruction, MPIReco
30+
31+
params = ... # Setup reconstruction paramter
32+
algo = ... # Setup chosen algorithm with params
33+
raw = ... # Setup raw data
34+
35+
image = reconstruct(algo, raw)
36+
```
37+
An algorithm can be transformed into a `RecoPlan`. These are mutable and transparent wrappers around the nested types of the algorithm and its parameters, which can be saved and restored to and from TOML files.
38+
39+
```julia
40+
plan = toPlan(algo)
41+
savePlan(MPIReco, "Example", plan)
42+
plan = loadPlan(MPIReco, "Example", [MPIReco, RegularizedLeastSquares, MPIFiles])
43+
44+
algo2 = build(plan)
45+
algo == algo2 # true
46+
```
47+
Unlike concrete algorithm instances, a `RecoPlan` may still be missing certain values of its properties. Futhermore, they can encode the structure of an image reconstruction algorithm without concrete parameterization.
48+
49+
It is also possible to attach functions to `RecoPlan` properties, that call user-specified functions if they are changed using `Observables.jl`. This allows specific `RecoPlans` to provide smart default parameter choices or embedding a plan into a GUI.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# # Radon Data
2+
3+
# In this example we will set up our radon data using RadonKA.jl, ImagePhantoms.jl and ImageGeoms.jl. We will start with simple 2D images and their sinograms and continue with a time series of 3D images and sinograms.
4+
5+
# ## Background
6+
# The Radon transform is an integral transform that projects the values of a function(or a phantom) along straight lines onto a detector.
7+
# These projections are recorded for a number of different angles and form the so-called sinogram. The Radon transform and its adjoint form the mathematical basis
8+
# for computed tomography (CT) and other imaging modalities such as single photon emission computed tomography (SPECT) and positron emission tomography (PET).
9+
10+
# ## 2D Phantom
11+
# We will use a simple Shepp-Logan phantom to generate our Radon data. The phantom is a standard test image for medical imaging and consists of a number of ellipses with different intensities.
12+
# It can be generated using ImagePhantoms.jl and ImageGeoms.jl. as follows:
13+
14+
using ImagePhantoms, ImageGeoms
15+
N = 256
16+
image = shepp_logan(N, SheppLoganToft())
17+
size(image)
18+
19+
# This produces a 256x256 image of a Shepp-Logan phantom. Next, we will generate the Radon data using `radon` from RadonKA.jl.
20+
# The arguments of this function are the image or phantom to be transformed, the angles at which the projections are taken, and the used geometry of the system. For this example we will use the default parallel circle geometry.
21+
# For more details, we refer to the RadonKA.jl documentation. We will use 256 angles for the projections, between 0 and π.
22+
using RadonKA
23+
angles = collect(range(0, π, 256))
24+
sinogram = Array(RadonKA.radon(image, angles))
25+
size(sinogram)
26+
27+
28+
# To visualize our progress so far, we will use CairoMakie.jl and a small helper function:
29+
using CairoMakie
30+
function plot_image(figPos, img; title = "", width = 150, height = 150)
31+
ax = CairoMakie.Axis(figPos[1, 1]; yreversed=true, title, width, height)
32+
hidedecorations!(ax)
33+
hm = heatmap!(ax, img)
34+
Colorbar(figPos[1, 2], hm)
35+
end
36+
fig = Figure()
37+
plot_image(fig[1,1], image, title = "Image")
38+
plot_image(fig[1,2], sinogram, title = "Sinogram")
39+
resize_to_layout!(fig)
40+
fig
41+
42+
# ## 3D Pnantom
43+
# RadonKA.jl also supports 3D Radon transforms. The first two dimensions are interpreted as the XY plane where the transform applied and the last dimensions is the rotational axis z of the projections.
44+
# For that we need to create a 3D Shepp-Logan phantom. First we retrieve the parameters of the ellipsoids of the Shepp-Logan phantom:
45+
shape = (64, 64, 64)
46+
params = map(collect, ellipsoid_parameters(; fovs = shape));
47+
48+
# We then scale the intensities of the ellipsoids to [0.0, ..., 1.0]:
49+
toft_settings = [1.0, -0.8, -0.2, -0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1]
50+
for idx in eachindex(toft_settings)
51+
params[idx][10] = toft_settings[idx]
52+
end
53+
54+
# Finally, we create the 3D Shepp-Logan phantom by defining and sampling our image geometry:
55+
ob = ellipsoid(map(Tuple, params))
56+
ig = ImageGeom(;dims = shape)
57+
image = phantom(axes(ig)..., ob)
58+
size(image)
59+
60+
# Now we can compute the 3D Radon transform of our phantom:
61+
sinogram = Array(RadonKA.radon(image, angles))
62+
size(sinogram)
63+
64+
# Let's visualize the 3D Radon data:
65+
fig = Figure()
66+
plot_image(fig[1,1], reverse(image[26,:,:]), title = "Slice YZ at z=26")
67+
plot_image(fig[1,2], image[:,40,:], title = "Slice XZ at y=40")
68+
plot_image(fig[2,1], reverse(image[:, :, 24]), title = "Slice XY at z=24")
69+
plot_image(fig[2,2], reverse(sinogram[:,:,24]), title = "Sinogram at z=24")
70+
plot_image(fig[3,1], reverse(image[:, :,16]), title = "Slice XY at z=16")
71+
plot_image(fig[3,2], reverse(sinogram[:,:,16]), title = "Sinogram at z=16")
72+
resize_to_layout!(fig)
73+
fig
74+
75+
76+
# ## Time Series of 3D Phantoms
77+
# Lastly, we want to add a time dimension to our 3D phantom. For our example we will increase the intensity of the third ellipsoid every time step or frame.
78+
images = similar(image, size(image)..., 5)
79+
sinograms = similar(sinogram, size(sinogram)..., 5)
80+
for (i, intensity) in enumerate(range(params[3][end], 0.3, 5))
81+
params[3][end] = intensity
82+
local ob = ellipsoid(map(Tuple, params))
83+
local ig = ImageGeom(;dims = shape)
84+
images[:, :, :, i] = phantom(axes(ig)..., ob)
85+
sinograms[:, :, :, i] = Array(RadonKA.radon(images[:, :, :, i], angles))
86+
end
87+
size(sinograms)
88+
89+
fig = Figure()
90+
for i = 1:5
91+
plot_image(fig[i,1], reverse(images[:, :, 24, i]))
92+
plot_image(fig[i,2], sinograms[:, :, 24, i])
93+
end
94+
resize_to_layout!(fig)
95+
fig
96+
97+
# The goal of our reconstruction package is now to recover an approximation of the time-series 3D phantoms from a given time-series of sinograms.
98+
# In the next section we will introduce our class hierarchies and explore the API of AbstractImageReconstruction.jl.

0 commit comments

Comments
 (0)