viqa.nr_metrics.cnr.contrast_to_noise_ratio

viqa.nr_metrics.cnr.contrast_to_noise_ratio(img, background_center, signal_center, radius, region_type='cubic', auto_center=False, iterations=5, **kwargs)[source]

Calculate the contrast-to-noise ratio (CNR) for an image.

Parameters:
  • img (np.ndarray or Tensor or str or os.PathLike) – Image to calculate score of.

  • background_center (Tuple(int)) – Center of the background. Order is (x, y) for 2D images and (x, y, z) for 3D images.

  • signal_center (Tuple(int)) – Center of the signal. Order is (x, y) for 2D images and (x, y, z) for 3D images.

  • radius (int) – Width of the regions.

  • region_type ({'cubic', 'spherical', 'full', 'original'}, optional) – Type of region to calculate the SNR. Default is ‘cubic’. Gets passed to viqa.utils.find_largest_region() if auto_center is True. If auto_center is False, the following options are available: If ‘full’ or ‘original’ the original image is used as signal and background region. If ‘cubic’ a cubic region around the center is used. Alias for ‘cubic’ are ‘cube’ and ‘square’. If ‘spherical’ a spherical region around the center is used. Alias for ‘spherical’ are ‘sphere’ and ‘circle’.

  • auto_center (bool, default False) – Automatically find the center of the image. signal_center, background_center and radius are ignored if True.

  • iterations (int, optional) – Number of iterations for morphological operations if auto_center is True. Default is 5.

  • **kwargs (optional) – Additional parameters for data loading. The keyword arguments are passed to viqa.utils.load_data().

Returns:

score_val – CNR score value.

Return type:

float

Raises:

ValueError – If the input image is not 2D or 3D. If the input center is not a tuple of integers. If the input center is too close to the border. If the input radius is not an integer. If the passed region type is not valid.

Notes

This implementation uses cubic regions to calculate the CNR. The calculation is based on the following formula:

\[CNR = \frac{\mu_{signal} - \mu_{background}}{\sigma_{background}}\]

where \(\mu\) is the mean and \(\sigma\) is the standard deviation.

Important

The background region should be chosen in a homogeneous area, while the signal region should be chosen in an area with a high contrast.

References