mr2.operators.functionals.NCC

class mr2.operators.functionals.NCC[source]

Bases: Operator[Tensor, tuple[Tensor]]

(masked) global or local normalized cross-correlation functional.

__init__(target: Tensor, weight: Tensor | None = None, *, window_size: int | None = None, reduction: Literal['full', 'volume', 'none'] = 'full', eps: float = 1e-12) None[source]

Initialize NCC.

Parameters:
  • target (Tensor) – Target volume. At least 3D in the trailing dimensions.

  • weight (Tensor | None, default: None) – Optional positive weight (or boolean mask), broadcastable with target. If window_size is not None, the weight is masked to only include windows that are fully inside the mask.

  • window_size (int | None, default: None) – If None, compute global NCC over the last three dimensions. If integer, compute local NCC with rectangular sliding windows.

  • reduction (Literal['full', 'volume', 'none'], default: 'full') – If full, return scalar mean over volumes. If volume, return one value per volume. If none, return local NCC map for local mode or per-volume values for global mode.

  • eps (float, default: 1e-12) – Small positive constant for numerical stability.

__call__(x: Tensor) tuple[Tensor][source]

Calculate NCC between input and target.

forward(x: Tensor) tuple[Tensor][source]

Apply forward of NCC.

Note

Prefer calling the instance as operator(x) over directly calling this method.

__add__(other: Operator[Unpack[Tin], Tout]) Operator[Unpack[Tin], Tout][source]
__add__(other: Tensor | complex) Operator[Unpack[Tin], tuple[Unpack[Tin]]]

Operator addition.

Returns lambda x: self(x) + other(x) if other is a operator, lambda x: self(x) + other*x if other is a tensor

__matmul__(other: Operator[Unpack[Tin2], tuple[Unpack[Tin]]] | Operator[Unpack[Tin2], tuple[Tensor, ...]]) Operator[Unpack[Tin2], Tout][source]

Operator composition.

Returns lambda x: self(other(x))

__mul__(other: Tensor | complex) Operator[Unpack[Tin], Tout][source]

Operator multiplication with tensor.

Returns lambda x: self(x*other)

__radd__(other: Tensor | complex) Operator[Unpack[Tin], tuple[Unpack[Tin]]][source]

Operator right addition.

Returns lambda x: other*x + self(x)

__rmul__(other: Tensor | complex) Operator[Unpack[Tin], Tout][source]

Operator multiplication with tensor.

Returns lambda x: other*self(x)