Metrics
Functions to compare image pairs.
All functions expect float-encoded images, with values in [0, 1], with NHWC shapes. Each image metric function returns a scalar for each image pair.
- cloudcasting.metrics.mae(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number, ignore_nans: bool = False) Array | ndarray | bool | number | float | int
Returns the Mean Absolute Error between a and b.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
ignore_nans (bool) – Defaults to False
- Returns:
MAE between a and b
- Return type:
chex.Numeric
- cloudcasting.metrics.mse(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number, ignore_nans: bool = False) Array | ndarray | bool | number | float | int
Returns the Mean Squared Error between a and b.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
ignore_nans (bool) – Defaults to False
- Returns:
MSE between a and b
- Return type:
chex.Numeric
- cloudcasting.metrics.psnr(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number) Array | ndarray | bool | number | float | int
Returns the Peak Signal-to-Noise Ratio between a and b.
Assumes that the dynamic range of the images (the difference between the maximum and the minimum allowed values) is 1.0.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
- Returns:
PSNR in decibels between a and b
- Return type:
chex.Numeric
- cloudcasting.metrics.rmse(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number) Array | ndarray | bool | number | float | int
Returns the Root Mean Squared Error between a and b.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
- Returns:
RMSE between a and b
- Return type:
chex.Numeric
- cloudcasting.metrics.simse(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number) Array | ndarray | bool | number | float | int
Returns the Scale-Invariant Mean Squared Error between a and b.
For each image pair, a scaling factor for b is computed as the solution to the following problem:
min_alpha || vec(a) - alpha * vec(b) ||_2^2
where a and b are flattened, i.e., vec(x) = np.flatten(x). The MSE between the optimally scaled b and a is returned: mse(a, alpha*b).
This is a scale-invariant metric, so for example: simse(x, y) == sims(x, y*5).
This metric was used in “Shape, Illumination, and Reflectance from Shading” by Barron and Malik, TPAMI, ‘15.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
- Returns:
SIMSE between a and b
- Return type:
chex.Numeric
- cloudcasting.metrics.ssim(a: Array | ndarray | bool | number, b: Array | ndarray | bool | number, *, max_val: float = 1.0, filter_size: int = 11, filter_sigma: float = 1.5, k1: float = 0.01, k2: float = 0.03, return_map: bool = False, precision=Precision.HIGHEST, filter_fn: Callable[[Array | ndarray | bool | number], Array | ndarray | bool | number] | None = None, ignore_nans: bool = False) Array | ndarray | bool | number | float | int
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.
- Parameters:
a (chex.Array) – First image (or set of images)
b (chex.Array) – Second image (or set of images)
max_val (float) – The maximum magnitude that a or b can have. Defaults to 1.
filter_size (int) – Window size (>= 1). Image dims must be at least this small. Defaults to 11
filter_sigma (float) – The bandwidth of the Gaussian used for filtering (> 0.). Defaults to 1.5
k1 (float) – One of the SSIM dampening parameters (> 0.). Defaults to 0.01.
k2 (float) – One of the SSIM dampening parameters (> 0.). Defaults to 0.03.
return_map (bool) – If True, will cause the per-pixel SSIM “map” to be returned. Defaults to False.
precision – The numerical precision to use when performing convolution
filter_fn (Callable[[chex.Array], chex.Array] | None) – An optional argument for overriding the filter function used by SSIM, which would otherwise be a 2D Gaussian blur specified by filter_size and filter_sigma
ignore_nans (bool) – Defaults to False
- Returns:
Each image’s mean SSIM, or a tensor of individual values if return_map is True
- Return type:
chex.Numeric