Skip to content

Reconstruction metrics ​

Compare images on the same grid, mask and intensity convention. Raw complex NRMSE measures amplitude and phase differences; globally aligned metrics remove one fitted complex scale, and magnitude metrics discard phase. Report which choice you use. A small value against a reconstructed reference is not an independent physical validation of that reference.

A complete CPU example ​

This controlled example changes only a known global scale and phase. The aligned error is near zero by construction; it demonstrates the metric definitions.

julia
using HighOrderMRI

reference = reshape(ComplexF64.(1:256), 16, 16)
reconstruction = (1.2 * cis(0.2)) .* reference
metric_values = (
    raw = raw_complex_nrmse(reconstruction, reference),
    aligned = aligned_complex_nrmse(reconstruction, reference),
    magnitude = magnitude_nrmse(reconstruction, reference),
    ssim = magnitude_ssim(reconstruction, reference),
)
@assert metric_values.raw > 0
@assert metric_values.aligned < 1e-12

The newer functions take (reconstruction, reference). The HO_* compatibility functions below use reference first. They have different validation rules: for example, normalized errors reject a zero reference norm, while unscaled HO_MSE does not need a reference norm. No helper applies a mask internally. SSIM copies magnitudes to CPU storage and uses the dependency's image/window conventions; its default peak normalization uses the same scale for both images.

See Scientific validation strategy for how to separate raw, aligned and magnitude-only results.

complex_alignment_scale ​

julia
complex_alignment_scale(reconstruction::AbstractArray{<:Number}, reference::AbstractArray{<:Number})

Return the least-squares scalar alpha = dot(vec(x), vec(reference)) / dot(vec(x), vec(x)) for x = reconstruction, using the conjugating inner product. Multiplying by this scalar removes one global amplitude and phase difference.

Inputs must have the same nonempty shape and finite scalar products. A zero reconstruction returns a scale of one because the scale is then immaterial. This is an explicitly aligned comparison, not raw reconstruction accuracy.

Source: src/utils/ImageMetrics.jl

raw_complex_nrmse ​

julia
raw_complex_nrmse(reconstruction::AbstractArray{<:Number}, reference::AbstractArray{<:Number})

Return norm(vec(reconstruction) - vec(reference)) / norm(vec(reference)) without intensity scaling or global phase alignment. Inputs must have the same nonempty shape. A zero/nonfinite reference norm or nonfinite error norm raises an error. The output is a dimensionless scalar; no mask is applied internally.

Source: src/utils/ImageMetrics.jl

aligned_complex_nrmse ​

julia
aligned_complex_nrmse(
    reconstruction::AbstractArray{<:Number},
    reference::AbstractArray{<:Number};
    scale = complex_alignment_scale(reconstruction, reference))

Return complex NRMSE after multiplying the reconstruction by scale. By default the scale is fitted by complex_alignment_scale. Reference shape, nonempty size and nonzero finite norm are checked as for raw complex NRMSE. Label this as an aligned result because amplitude and phase errors can be removed.

Source: src/utils/ImageMetrics.jl

magnitude_nrmse ​

julia
magnitude_nrmse(
    reconstruction::AbstractArray{<:Number},
    reference::AbstractArray{<:Number};
    align::Bool = false)

Return norm(abs.(reconstruction) - abs.(reference)) / norm(reference) after vectorization. Phase differences are not measured. With align=true, first fit one global complex scale, then compare magnitudes. Inputs require the same nonempty shape and a nonzero finite reference norm; nonfinite errors are rejected.

Source: src/utils/ImageMetrics.jl

magnitude_ssim ​

julia
magnitude_ssim(
    reconstruction::AbstractArray{<:Number},
    reference::AbstractArray{<:Number};
    align::Bool = false,
    normalize::Bool = true)

Compute SSIM on magnitude images using ImageQualityIndexes.assess_ssim. Both images are converted to floating-point host arrays with Array and abs. If align=true, first fit a global complex scale. If normalize=true, divide both magnitudes by the same peak magnitude of the reference; the reconstruction is not normalized independently or clipped to a unit range.

Inputs must have the same nonempty shape, finite values, and nonzero reference norm. Supported image dimensions and the SSIM window are delegated to the dependency. Report alignment/normalization settings with the value.

Source: src/utils/ImageMetrics.jl

Compatibility API ​

These bindings remain available for existing scripts. HO_img_scale returns an aligned image; complex_alignment_scale returns the scalar itself.

HO_img_scale ​

julia
HO_img_scale(reference::AbstractArray{<:Number}, reconstruction::AbstractArray{<:Number})

Compatibility API with reference-first argument order. Return the reconstruction multiplied by complex_alignment_scale(reconstruction, reference); this returns an aligned image, not the fitted scalar.

Source: src/utils/ImageMetrics.jl

HO_MSE ​

julia
HO_MSE(reference::AbstractArray{<:Number}, reconstruction::AbstractArray{<:Number}; scale::Bool = false)

Compatibility API with reference-first argument order. Return the squared complex Euclidean error divided by the number of reference elements. With scale=true, first apply HO_img_scale. Same nonempty shapes are checked; without scaling this implementation does not separately reject nonfinite values or require a nonzero reference norm.

Source: src/utils/ImageMetrics.jl

HO_RMSE ​

julia
HO_RMSE(reference::AbstractArray{<:Number}, reconstruction::AbstractArray{<:Number}; scale::Bool = false)

Compatibility API with reference-first argument order. Return the square root of HO_MSE(reference, reconstruction; scale), retaining that function's alignment choice and input behavior.

Source: src/utils/ImageMetrics.jl

HO_NRMSE ​

julia
HO_NRMSE(reference::AbstractArray{<:Number}, reconstruction::AbstractArray{<:Number}; scale::Bool = false)

Compatibility API with reference-first argument order. Dispatch to raw_complex_nrmse(reconstruction, reference) when scale=false, or to aligned_complex_nrmse when true. A zero reference norm is rejected.

Source: src/utils/ImageMetrics.jl

HO_SSIM ​

julia
HO_SSIM(reference::AbstractArray{<:Number}, reconstruction::AbstractArray{<:Number}; scale::Bool = false)

Compatibility API with reference-first argument order. Call magnitude_ssim(reconstruction, reference; align=scale) with its default reference-peak normalization. It compares magnitudes and returns a scalar SSIM.

Source: src/utils/ImageMetrics.jl

HighOrderMRI.jl documentation · v0.1.0 · code 425f7df · docs f949b4f