Skip to content

Commit 6c49a9d

Browse files
docstrings; draft docu site
1 parent 898c687 commit 6c49a9d

6 files changed

Lines changed: 129 additions & 4 deletions

File tree

.github/workflows/CI.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: CI
22
on:
33
pull_request:
44
branches:
5-
- master
5+
- main
66
push:
77
branches:
8-
- master
8+
- main
99
tags: '*'
1010
jobs:
1111
test:

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# MRIRealign.jl
2+
3+
4+
| **Documentation** | **Build Status** |
5+
|:------------------------- |:------------------------------------- |
6+
| [![][docs-img]][docs-url] | [![][gh-actions-img]][gh-actions-url] |
7+
| | [![][codecov-img]][codecov-url] |
8+
9+
10+
TODO
11+
12+
[docs-img]: https://img.shields.io/badge/docs-latest%20release-blue.svg
13+
[docs-url]: https://MagneticResonanceImaging.github.io/MRIRealign.jl/dev
14+
15+
[gh-actions-img]: https://github.com/MagneticResonanceImaging/MRIRealign.jl/workflows/CI/badge.svg
16+
[gh-actions-url]: https://github.com/MagneticResonanceImaging/MRIRealign.jl/actions
17+
18+
[codecov-img]: https://codecov.io/gh/MagneticResonanceImaging/MRIRealign.jl/branch/main/graph/badge.svg
19+
[codecov-url]: https://codecov.io/gh/MagneticResonanceImaging/MRIRealign.jl
20+

docs/Project.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[deps]
2+
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
3+
MRIRealign = "9689932d-8765-44d0-985b-2d9644d92569"
4+
5+
[extras]

docs/make.jl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using Pkg
2+
Pkg.activate("docs")
3+
Pkg.develop(PackageSpec(path=pwd()))
4+
Pkg.instantiate()
5+
6+
using MRIRealign
7+
using Documenter
8+
9+
DocMeta.setdocmeta!(MRIRealign, :DocTestSetup, :(using MRIRealign); recursive=true)
10+
11+
makedocs(;
12+
doctest=true,
13+
doctestfilters = [r"\s*-?(\d+)\.(\d{4})\d*\s*"], # Ignore any digit after the 4th digit after a decimal, throughout the docs
14+
modules=[MRIRealign],
15+
authors="Jakob Asslaender <jakob.asslaender@nyumc.org> and contributors",
16+
repo = Documenter.Remotes.GitHub("MagneticResonanceImaging", "MRIRealign.jl"),
17+
sitename="MRIRealign.jl",
18+
format=Documenter.HTML(;
19+
prettyurls=get(ENV, "CI", "false") == "true",
20+
canonical="https://MagneticResonanceImaging.github.io/MRIRealign.jl",
21+
assets=String[],
22+
),
23+
pages=[
24+
"Home" => "index.md",
25+
],
26+
)
27+
28+
# Set dark theme as default independent of the OS's settings
29+
run(`sed -i'.old' 's/var darkPreference = false/var darkPreference = true/g' docs/build/assets/themeswap.js`)
30+
31+
deploydocs(;
32+
repo="github.com/MagneticResonanceImaging/MRIRealign.jl",
33+
push_preview=true,
34+
)

docs/src/index.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
```@meta
2+
CurrentModule = MRIRealign
3+
```
4+
5+
# MRIRealign.jl
6+
7+
TODO
8+
9+
```@contents
10+
Pages=[
11+
"build_literate/Greens_functions.md",
12+
"build_literate/Simulation_ContinuousWave.md",
13+
"build_literate/Simulation_Pulse.md",
14+
"build_literate/Analyze_NMR_IR_Data.md",
15+
"build_literate/Analyze_NMR_PreSat_Data.md",
16+
"build_literate/Linear_Approximation.md",
17+
]
18+
Depth = 2
19+
```
20+
21+
# API
22+
23+
In the following, you find the documentation of all exported functions of the [MRIRealign.jl](https://github.com/MagneticResonanceImaging/MRIRealign.jl) package:
24+
25+
```@index
26+
```
27+
28+
```@autodocs
29+
Modules = [MRIRealign]
30+
```

src/MRIRealign.jl

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,32 @@ using ImageFiltering
1010
using Statistics
1111
using OhMyThreads
1212

13-
export realign!, create_rotation_matrix
13+
export realign!, create_rotation_matrix, create_affine_matrix
1414

1515

1616
# --- Top-level functions ---
17+
"""
18+
realign!(img; center=size(img)[1:3] .÷ 2, ref_mode=:consensus, mask=trues(size(img)[1:3]), fwhm=nothing, realign=true)
19+
realign!(img, motion_params; center=size(img)[1:3] .÷ 2)
20+
21+
Estimate motion parameters and/or realign the images.
22+
23+
# Required argument
24+
- `img::AbstractArray{T,4}`: Array of images with the dimensions `x, y, z, t`, i.e., 3D images with time in the 4th dimension. The type T can be real or complex valued. If complex-valued, the motion estimation will be performed on the absolute value; otherwise, on img, i.e., allowing for negative values.
25+
26+
# Keyword arguments if motion parameters are unknown
27+
- `center=size(img)[1:3] .÷ 2`: Point around which the images are rotated (relevant only for the estimated motion parameters, not the alignment).
28+
- `ref_mode: `:consensus` (default), `:mean`, or an integer. `:consensus` estimates motion parameters pairwise for all timeframes and computes a consensus, which is helpful if any single reference might have poor image quality. This comes at the cost of a `t`-fold increase in computation time. `:mean` estimates the motion parameters wrt. to the mean of all images. This is fast, but might have inferior precision if the mean is blurred by substantial motion. Providing an integer aligns the images wrt. to the `ref_mode`th time frame, which is fast, but works only reliably if this time frame has good image quality.
29+
- `mask=trues(size(img)[1:3])`: bitmask at which the frames are compared.
30+
- `fwhm=nothing`: 3-Tuple of the full width at half maximum values of an optional Gaussian smoothing kernel along each dimension, in units of voxels. The default setting (`nothing`) is to perform no smoothing.
31+
- `realign=true`: If true, the argument `img` will be overwritten inline with the aligned images. If `false`, this function estimates the motion parameters, but does not align the images.
32+
33+
# Optional arguments if the motion parameters are already known
34+
- `motion_params::AbstractMatrix`: If the motion parameters are known, e.g., by a previous run of this function, they can be provided to skip the estimation step. The dimensions of this matrix are `6 × T`, capturing in the first dimension the motion parameters, in the order `rx, ry, rz, tx, ty, tz`, with the rotations `r` and the translations `t`. T is the number of time frames.
35+
- `center=size(img)[1:3] .÷ 2)`: Point around which `motion_params` are applied.
36+
37+
With the appropriate settings (see above), the aligned timeframes are written inline into `img`. The function always returns the estimated motion parameters, where all rotations are in radians and translations in voxels.
38+
"""
1739
function realign!(img::AbstractArray{Tin,4};
1840
center=size(img)[1:3] 2,
1941
ref_mode=:consensus,
@@ -99,7 +121,7 @@ function realign!(img::AbstractArray{T,4}, motion_params; center=size(img)[1:3]
99121
vol[idx] = img_itp(v[1], v[2], v[3])
100122
end
101123
end
102-
return img
124+
return motion_params
103125
end
104126

105127

@@ -180,6 +202,15 @@ end
180202

181203
_interpolate(x) = extrapolate(interpolate(x, BSpline(Cubic())), Interpolations.Flat())
182204

205+
206+
"""
207+
create_rotation_matrix(rx, ry, rz)
208+
create_rotation_matrix(p) = create_rotation_matrix(p[1], p[2], p[3])
209+
210+
Calculate the rotation matrix for three rotations `rx, ry, rz`, in radians. In this package, we use the convention `R = Rz * Ry * Rx`.
211+
"""
212+
create_rotation_matrix(p) = create_rotation_matrix(p[1], p[2], p[3])
213+
183214
function create_rotation_matrix(rx, ry, rz)
184215
Rx = @SMatrix [1 0 0; 0 cos(rx) -sin(rx); 0 sin(rx) cos(rx)]
185216
Ry = @SMatrix [cos(ry) 0 sin(ry); 0 1 0; -sin(ry) 0 cos(ry)]
@@ -188,6 +219,11 @@ function create_rotation_matrix(rx, ry, rz)
188219
return R
189220
end
190221

222+
"""
223+
create_affine_matrix(p, center)
224+
225+
Calculate the affine matrix from `p = rx, ry, rz, tx, ty, tz`. The rotations `r` are in radians and the translations `t` in voxels. The argument `center` takes a 3-Tuple (or vector of length 3) with the center around which the images are rotated.
226+
"""
191227
function create_affine_matrix(p, center)
192228
rx, ry, rz, tx, ty, tz = p
193229

0 commit comments

Comments
 (0)