loss

Pairwise Loss

class airlab.loss.pairwise.LCC(fixed_image, moving_image, fixed_mask=None, moving_mask=None, sigma=3, kernel_type='box', size_average=True, reduce=True)[source]
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class airlab.loss.pairwise.MI(fixed_image, moving_image, fixed_mask=None, moving_mask=None, bins=64, sigma=3, spatial_samples=0.1, background=None, size_average=True, reduce=True)[source]

Implementation of the Mutual Information image loss.

\[\mathcal{S}_{\text{MI}} := H(F, M) - H(F|M) - H(M|F)\]
Parameters:
  • fixed_image (Image) – Fixed image for the registration
  • moving_image (Image) – Moving image for the registration
  • bins (int) – Number of bins for the intensity distribution
  • sigma (float) – Kernel sigma for the intensity distribution approximation
  • spatial_samples (float) – Percentage of pixels used for the intensity distribution approximation
  • background – Method to handle background pixels. None: Set background to the min value of image “mean”: Set the background to the mean value of the image float: Set the background value to the input value
  • size_average (bool) – Average loss function
  • reduce (bool) – Reduce loss function to a single value
bins
bins_fixed_image
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

sigma
class airlab.loss.pairwise.MSE(fixed_image, moving_image, fixed_mask=None, moving_mask=None, size_average=True, reduce=True)[source]

The mean square error loss is a simple and fast to compute point-wise measure which is well suited for monomodal image registration.

\[\mathcal{S}_{\text{MSE}} := \frac{1}{\vert \mathcal{X} \vert}\sum_{x\in\mathcal{X}} \Big(I_M\big(x+f(x)\big) - I_F\big(x\big)\Big)^2\]
Parameters:
  • fixed_image (Image) – Fixed image for the registration
  • moving_image (Image) – Moving image for the registration
  • size_average (bool) – Average loss function
  • reduce (bool) – Reduce loss function to a single value
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class airlab.loss.pairwise.NCC(fixed_image, moving_image, fixed_mask=None, moving_mask=None)[source]
The normalized cross correlation loss is a measure for image pairs with a linear
intensity relation.
\[\mathcal{S}_{\text{NCC}} := \frac{\sum I_F\cdot (I_M\circ f) - \sum\text{E}(I_F)\text{E}(I_M\circ f)} {\vert\mathcal{X}\vert\cdot\sum\text{Var}(I_F)\text{Var}(I_M\circ f)}\]
Parameters:
  • fixed_image (Image) – Fixed image for the registration
  • moving_image (Image) – Moving image for the registration
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class airlab.loss.pairwise.NGF(fixed_image, moving_image, fixed_mask=None, moving_mask=None, epsilon=1e-05, size_average=True, reduce=True)[source]

Implementation of the Normalized Gradient Fields image loss.

Parameters:
  • fixed_image (Image) – Fixed image for the registration
  • moving_image (Image) – Moving image for the registration
  • fixed_mask (Tensor) – Mask for the fixed image
  • moving_mask (Tensor) – Mask for the moving image
  • epsilon (float) – Regulariser for the gradient amplitude
  • size_average (bool) – Average loss function
  • reduce (bool) – Reduce loss function to a single value
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class airlab.loss.pairwise.SSIM(fixed_image, moving_image, fixed_mask=None, moving_mask=None, sigma=[3], dim=2, kernel_type='box', alpha=1, beta=1, gamma=1, c1=1e-05, c2=1e-05, c3=1e-05, size_average=True, reduce=True)[source]

Implementation of the Structual Similarity Image Measure loss.

Parameters:
  • fixed_image (Image) – Fixed image for the registration
  • moving_image (Image) – Moving image for the registration
  • fixed_mask (Tensor) – Mask for the fixed image
  • moving_mask (Tensor) – Mask for the moving image
  • sigma (float) – Sigma for the kernel
  • kernel_type (string) – Type of kernel i.e. gaussian, box
  • alpha (float) – Controls the influence of the luminance value
  • beta (float) – Controls the influence of the contrast value
  • gamma (float) – Controls the influence of the structure value
  • c1 (float) – Numerical constant for the luminance value
  • c2 (float) – Numerical constant for the contrast value
  • c3 (float) – Numerical constant for the structure value
  • size_average (bool) – Average loss function
  • reduce (bool) – Reduce loss function to a single value
forward(displacement)[source]

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.