ct.metric

Functions for computing image metrics.

ct.metric.image_psnr(im_pd, im_gt, im_mask=None)[source]

Computes PSNR given images in numpy arrays.

Parameters:
  • im_pd (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_gt (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_mask (Float[ndarray, 'h w'] | None) – numpy array, (h, w), float32, range [0, 1], enforced. Value > 0.5 means foreground. None means all foreground.

Returns:

PSNR value in float.

Return type:

float

ct.metric.image_ssim(im_pd, im_gt, im_mask=None)[source]

Computes SSIM given images in numpy arrays.

Parameters:
  • im_pd (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_gt (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_mask (Float[ndarray, 'h w'] | None) – numpy array, (h, w), float32, range [0, 1], enforced. Value > 0.5 means foreground. None means all foreground.

Returns:

SSIM value in float.

Return type:

float

ct.metric.image_lpips(im_pd, im_gt, im_mask=None)[source]

Computes LPIPS given images in numpy arrays.

Parameters:
  • im_pd (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_gt (Float[ndarray, 'h w 3']) – numpy array, (h, w, 3), float32, range [0, 1], enforced.

  • im_mask (Float[ndarray, 'h w'] | None) – numpy array, (h, w), float32, range [0, 1], enforced. Value > 0.5 means foreground. None means all foreground.

Returns:

LPIPS value in float.

Return type:

float

ct.metric.image_psnr_with_paths(im_pd_path, im_gt_path, im_mask_path=None)[source]
Parameters:
  • im_pd_path (str | Path) – Path to the rendered RGB image. The image will be resized to the same (h, w) as im_gt.

  • im_gt_path (str | Path) – Path to the ground truth RGB image.

  • im_mask_path (str | Path | None) – Path to the mask image. The mask will be resized to the same (h, w) as im_gt.

Returns:

PSNR value in float.

Return type:

float

ct.metric.image_ssim_with_paths(im_pd_path, im_gt_path, im_mask_path=None)[source]
Parameters:
  • im_pd_path (str | Path) – Path to the rendered RGB image. The image will be resized to the same (h, w) as im_gt.

  • im_gt_path (str | Path) – Path to the ground truth RGB image.

  • im_mask_path (str | Path | None) – Path to the mask image. The mask will be resized to the same (h, w) as im_gt.

Returns:

SSIM value in float.

Return type:

float

ct.metric.image_lpips_with_paths(im_pd_path, im_gt_path, im_mask_path=None)[source]
Parameters:
  • im_pd_path (str | Path) – Path to the rendered RGB image. The image will be resized to the same (h, w) as im_gt.

  • im_gt_path (str | Path) – Path to the ground truth RGB image.

  • im_mask_path (str | Path | None) – Path to the mask image. The mask will be resized to the same (h, w) as im_gt.

ct.metric.load_im_pd_im_gt_im_mask_for_eval(im_pd_path, im_gt_path, im_mask_path=None, alpha_mode='white')[source]

Load prediction, ground truth, and mask images for image metric evaluation.

Parameters:
  • im_pd_path (str | Path) – Path to the rendered image.

  • im_gt_path (str | Path) – Path to the ground truth RGB or RGBA image.

  • im_mask_path (str | Path | None) – Path to the mask image. The mask will be resized to the same (h, w) as im_gt.

  • alpha_mode (Literal['white', 'keep']) – The mode on how to handle the alpha channel. Currently only “white” is supported.

The alpha_mode parameter can be:
  • “white”: If im_gt contains alpha channel, im_gt will be converted

    to RGB, the background will be rendered as white, the alpha channel will be then ignored.

  • “keep”: If im_gt contains alpha channel, the alpha channel will

    be used as mask. This mask can be overwritten by im_mask_path if im_mask_path is not None. (This option is not implemented yet.)

Returns:

  • im_pd: (h, w, 3), float32, value in [0, 1].

  • im_gt: (h, w, 3), float32, value in [0, 1].

  • im_mask: (h, w), float32, value only 0 or 1. Even if im_mask_path is None, im_mask will be returned as all 1s.

Return type:

[Float[np.ndarray, “h w 3”], Float[np.ndarray, “h w 3”], Float[np.ndarray, “h w”]]