Skip to content

Commit

Permalink
Out of field pixel value is denoted by η
Browse files Browse the repository at this point in the history
  • Loading branch information
emmt committed Jun 11, 2024
1 parent fbc9f25 commit 9bee16c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 35 deletions.
4 changes: 3 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ makedocs(
Dict(:left => raw"\[", :right => raw"\]", display => true),
],
:macros => Dict(raw"\Vh" => raw"\boldsymbol{h}",
raw"\Vt" => raw"\boldsymbol{t}",
raw"\Vt" => raw"\boldsymbol{\delta}",
raw"\Vx" => raw"\boldsymbol{x}",
raw"\Vy" => raw"\boldsymbol{y}",
raw"\Vz" => raw"\boldsymbol{z}",
raw"\Vtheta" => raw"\boldsymbol{\theta}",
raw"\Params" => raw"\boldsymbol{\xi}",
raw"\Dist" => raw"\mathcal{D}",
raw"\Score" => raw"\mathcal{S}",
raw"\RR" => raw"\mathbb{R}",
Expand Down
48 changes: 26 additions & 22 deletions docs/src/general.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,45 @@ Accounting for all these remarks, a possible definition of the distance between
reference image, and ``\Vx``, a reconstructed image, is given by:

```math
\begin{align}
\Dist(\Vx,\Vy) = \min_{α,β,\Vt} \Bigl\{
&\sum_{i \in |\MR_{\boldsymbol{θ}}\cdot\Vx| \cap |\Vy|}
d\!\left(α\,(\MR_{\boldsymbol{θ}}\cdot\Vx)_i + β, y_i\right)
\begin{align*}
\Dist(\Vx,\Vy) = \min_{\Params} \Bigl\{
&\sum_{i \in |\MR_{\Vtheta}\cdot\Vx| \cap |\Vy|}
d\!\left(α\,(\MR_{\Vtheta}\cdot\Vx)_i + β, y_i\right)
\notag\\
&+ \sum_{i \in |\MR_{\boldsymbol{θ}}\cdot\Vx| \backslash
(|\MR_{\boldsymbol{θ}}\cdot\Vx| \cap |\Vy|)}
d\!\left(α\,(\MR_{\boldsymbol{θ}}\cdot\Vx)_i + β, v_{\mathrm{out}}\right)
&+ \sum_{i \in |\MR_{\Vtheta}\cdot\Vx| \backslash
(|\MR_{\Vtheta}\cdot\Vx| \cap |\Vy|)}
d\!\left(α\,(\MR_{\Vtheta}\cdot\Vx)_i + β, \eta\right)
\notag\\
&+ \sum_{i \in |\Vy| \backslash
(|\MR_{\boldsymbol{θ}}\cdot\Vx| \cap |\Vy|)}
d\!\left(v_{\mathrm{out}},y_i\right)
(|\MR_{\Vtheta}\cdot\Vx| \cap |\Vy|)}
d\!\left(\eta,y_i\right)
\Bigr\}
\end{align}
\end{align*}
```

where ``d(x,y)`` is some pixel-wise distance, ``\MR_{\boldsymbol{θ}}`` is a linear
operator which implements resampling with a given magnification, translation, and
blurring, and ``v_{\mathrm{out}}`` is the assumed out-of-field pixel value.
``\boldsymbol{θ}`` accounts for all parameters defining the operator
``\MR_{\boldsymbol{θ}}``, in particular the translation ``\Vt``, and ``|\Vy|`` denotes the
list of pixels of the image ``\Vy``. Here ``\alpha \in \mathbb{R}``, ``\beta \in
\mathbb{R}``, and the translation ``\Vt \in \mathbb{R}^2`` are nuisance parameters to
reduce the mismatch between the images.
where ``d(x,y)`` is some pixel-wise distance, ``\MR_{\Vtheta}`` is a linear operator which
implements resampling with a given magnification, translation, and blurring, and ``\eta``
is the assumed out-of-field pixel value. ``|\Vy|`` denotes the list of pixels of the image
``\Vy`` and ``\Vtheta = \{\rho,\Vt,\omega\}`` accounts for all parameters defining the
operator ``\MR_{\Vtheta}``: the magnification ``\rho``, the translation ``\Vt``, and the
blur width ``\omega``.

The distance is minimized in the set ``\Params`` of parameters which are irrelevant for
judging of the image quality. These parameters depend on the context. For image
reconstruction from interferometric data, ``\beta = 0`` and ``\eta = 0`` are natural
settings while ``\alpha \in \mathbb{R}`` and the translation ``\Vt \in \mathbb{R}^2`` must
be adjusted to reduce the mismatch between the images. Hence, ``\Params = \{\alpha,\Vt\}``
in this context.

The score may be defined by normalizing the distance:

```math
\Score(\Vx)
= \frac{\Dist(\Vx,\Vy)}{\Dist(v_{\mathrm{out}}\,\One,\Vy)}
\Score(\Vx) = \frac{\Dist(\Vx,\Vy)}{\Dist(\eta\,\One,\Vy)}
```

where ``\One`` is an image of the same size as ``\Vy`` but filled with ones, hence
``v_{\mathrm{out}}\,\One`` is an image of the same size as ``\Vy`` but filled with
``v_{\mathrm{out}}`` the assumed out-of-field pixel value.
``\eta\,\One`` is an image of the same size as ``\Vy`` but filled with ``\eta`` the
assumed out-of-field pixel value.

The following properties are assumed for the pixel-wise distance:

Expand Down
28 changes: 16 additions & 12 deletions src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,37 +21,41 @@ as:
dist = Σᵢ Ψ(Γ(α⋅x[i] + β), Γ(y[i]))
where the parameters `α` and `β` and functions `Γ` and `Ψ` are specified by keywords:
for pixels `i` in the common region of `x` and `y` and where the parameters `α` and `β`
and functions `Γ` and `Ψ` are specified by keywords:
| Keyword | Symbol | Default | Description |
|:----------------|:-------|:-----------|:-----------------------|
| `scale` | `α` | `1` | Brightness scale |
| `bias` | `β` | `0` | Brightness bias |
| `enhancement` | `Γ` | `identity` | Brightness enhancement |
| `cost` | `Ψ` | `absdif` | Pixelwise cost |
| Keyword | Symbol | Default | Description |
|:----------------|:-------|:------------------------|:-----------------------------|
| `scale` | `α` | `one(real(eltype(x)))` | Brightness scale |
| `bias` | `β` | `zero(real(eltype(x)))` | Brightness bias |
| `out` | `η` | `zero(real(eltype(y)))` | Value of out-of-field pixels |
| `enhancement` | `Γ` | `identity` | Brightness enhancement |
| `cost` | `Ψ` | `absdif` | Pixelwise cost |
"""
function distance(x::AbstractArray{Tx,N},
y::AbstractArray{Ty,N};
enhancement::Function = identity,
cost::Function = abs,
scale::Real = one(real(Tx)),
bias::Real = zero(real(Tx))) where {Tx,Ty,N}
# Convert floating-point type of α and β whitout changing units if any.
scale::Number = one(real(Tx)),
bias::Number = zero(real(Tx)),
out::Number = zero(real(Ty))) where {Tx,Ty,N}
# Convert floating-point type of α, β, and η whitout changing their units if any.
T = floating_point_type(Tx, Ty) # floating-point type for computations
α = convert_floating_point_type(T, scale)
β = convert_floating_point_type(T, bias)
η = convert_floating_point_type(T, out)
Γ = enhancement
Ψ = cost
dist = zero(Ψ(Γ(zero(β)), Γ(zero(β))))
Γz = Γ(η)
dist = zero(Ψ(Γz, Γz))
if axes(x) == axes(y)
@inbounds @simd for i in eachindex(x, y)
dist += Ψ(Γ*x[i] + β), Γ(y[i]))
end
else
X = CartesianIndices(x)
Y = CartesianIndices(y)
Γz = Γ(β)
# Distance of background w.r.t. `x`.
let dx = zero(dist)
@inbounds @simd for i in X
Expand Down

0 comments on commit 9bee16c

Please sign in to comment.