nerfbaselines.metrics¶
- nerfbaselines.metrics.dmpix_ssim(a: ndarray, b: ndarray, *, max_val: float = 1.0, kernel_size: int = 11, sigma: float = 1.5, k1: float = 0.01, k2: float = 0.03, return_map: bool = False, filter_fn: Callable[[ndarray], ndarray] | None = None) ndarray [source]¶
Computes the structural similarity index (SSIM) between image pairs.
This function is based on the standard SSIM implementation from: Z. Wang, A. C. Bovik, H. R. Sheikh and E. P. Simoncelli, “Image quality assessment: from error visibility to structural similarity”, in IEEE Transactions on Image Processing, vol. 13, no. 4, pp. 600-612, 2004.
This function was modeled after tf.image.ssim, and should produce comparable output.
Note: the true SSIM is only defined on grayscale. This function does not perform any colorspace transform. If the input is in a color space, then it will compute the average SSIM.
Note
This function exactly matches dm_pix.ssim
- Parameters:
a – First image (or set of images).
b – Second image (or set of images).
max_val – The maximum magnitude that a or b can have.
kernel_size – Window size (>= 1). Image dims must be at least this small.
sigma – The bandwidth of the Gaussian used for filtering (> 0.).
k1 – One of the SSIM dampening parameters (> 0.).
k2 – One of the SSIM dampening parameters (> 0.).
return_map – If True, will cause the per-pixel SSIM “map” to be returned.
precision – The numerical precision to use when performing convolution.
- Returns:
Each image’s mean SSIM, or a tensor of individual values if return_map.
- nerfbaselines.metrics.lpips(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Learned Perceptual Image Patch Similarity (the lower the better). :param a: Tensor of prediction images [B…, H, W, C]. :param b: Tensor of target images [B…, H, W, C].
- Returns:
Tensor of LPIPS values for each image [B…].
- nerfbaselines.metrics.lpips_alex(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Learned Perceptual Image Patch Similarity (the lower the better). :param a: Tensor of prediction images [B…, H, W, C]. :param b: Tensor of target images [B…, H, W, C].
- Returns:
Tensor of LPIPS values for each image [B…].
- nerfbaselines.metrics.lpips_vgg(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Learned Perceptual Image Patch Similarity (the lower the better). :param a: Tensor of prediction images [B…, H, W, C]. :param b: Tensor of target images [B…, H, W, C].
- Returns:
Tensor of LPIPS values for each image [B…].
- nerfbaselines.metrics.mae(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Mean Absolute Error (the lower the better). :param a: Tensor of prediction images [B, H, W, C]. :param b: Tensor of target images [B, H, W, C].
- Returns:
Tensor of mean absolute error values for each image [B].
- nerfbaselines.metrics.mse(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Mean Squared Error (the lower the better). :param a: Tensor of prediction images [B, H, W, C]. :param b: Tensor of target images [B, H, W, C].
- Returns:
Tensor of mean squared error values for each image [B].
- nerfbaselines.metrics.psnr(a: ndarray | float32 | float64, b: ndarray | None = None) ndarray | float32 | float64 [source]¶
Compute Peak Signal to Noise Ratio (the higher the better). It can reuse computed MSE values if b is None. :param a: Tensor of prediction images [B, H, W, C] or a tensor of MSE values [B] (b must be None in that case). :param b: Tensor of target images [B, H, W, C] or None (if a are MSE values).
- Returns:
Tensor of PSNR values for each image [B].
- nerfbaselines.metrics.ssim(a: ndarray, b: ndarray) ndarray | float32 [source]¶
Compute Structural Similarity Index Measure (the higher the better). :param a: Tensor of prediction images [B, H, W, C]. :param b: Tensor of target images [B, H, W, C].
- Returns:
Tensor of mean SSIM values for each image [B].
- nerfbaselines.metrics.torchmetrics_ssim(a: ndarray, b: ndarray, *, gaussian_kernel: bool = True, sigma: float | Sequence[float] = 1.5, kernel_size: int | Sequence[int] = 11, data_range: float | Tuple[float, float] | None = None, k1: float = 0.01, k2: float = 0.03) ndarray | Tuple[ndarray, ndarray] [source]¶
Compute Structural Similarity Index Measure.
Note
This metric exactly matches torchmetrics.ssim
- Parameters:
preds – estimated image
target – ground truth image
gaussian_kernel – If true (default), a gaussian kernel is used, if false a uniform kernel is used
sigma – Standard deviation of the gaussian kernel, anisotropic kernels are possible. Ignored if a uniform kernel is used
kernel_size – the size of the uniform kernel, anisotropic kernels are possible. Ignored if a Gaussian kernel is used
data_range – Range of the image. If
None
, it is determined from the image (max - min)k1 – Parameter of SSIM.
k2 – Parameter of SSIM.