diff --git a/docs/make.jl b/docs/make.jl index 4c9a70f..f7ea849 100644 --- a/docs/make.jl +++ b/docs/make.jl @@ -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}", diff --git a/docs/src/general.md b/docs/src/general.md index 61c435e..46f728f 100644 --- a/docs/src/general.md +++ b/docs/src/general.md @@ -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: diff --git a/src/metrics.jl b/src/metrics.jl index 4c1092f..70bad0e 100644 --- a/src/metrics.jl +++ b/src/metrics.jl @@ -21,29 +21,34 @@ 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])) @@ -51,7 +56,6 @@ function distance(x::AbstractArray{Tx,N}, 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