viqa.fr_metrics.gsm.GSM

class viqa.fr_metrics.gsm.GSM(data_range=255, normalize=False, **kwargs)[source]

Calculate the gradient similarity (GSM) between two images.

score_val

GSM score value of the last calculation.

Type:

float

parameters

Dictionary containing the parameters for GSM calculation.

Type:

dict

Parameters:
  • data_range ({1, 255, 65535}, default=255) – Data range of the returned data in data loading. Is used for image loading when normalize is True and for the GSM calculation. Passed to viqa.utils.load_data() and viqa.fr_metrics.gsm.gradient_similarity().

  • normalize (bool, default=False) – If True, the input images are normalized to the data_range argument.

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

  • chromatic (bool, default False) – If True, the input images are expected to be RGB images. If False, the input images are converted to grayscale images if necessary.

Raises:

ValueError – If data_range is not set.

Warning

This metric is not yet tested. The metric should be only used for experimental purposes.

Notes

GSM is a full reference IQA metric based on gradient similarity. It combines luminosity information and contrast-structural information. For further details, see [1]. data_range for image loading is also used for the GSM calculation and therefore must be set. The parameter is set through the constructor of the class and is passed to score().

References

score(img_r, img_m, dim=None, im_slice=None, **kwargs)[source]

Calculate the gradient similarity (GSM) between two images.

The metric can be calculated for 2D and 3D images. If the images are 3D, the metric can be calculated for the full volume or for a given slice of the image by setting dim to the desired dimension and im_slice to the desired slice number.

Parameters:
  • img_r (np.ndarray or Tensor or str or os.PathLike) – Reference image to calculate score against.

  • img_m (np.ndarray or Tensor or str or os.PathLike) – Distorted image to calculate score of.

  • dim ({0, 1, 2}, optional) – GSM for 3D images is calculated as mean over all slices of the given dimension.

  • im_slice (int, optional) – If given, GSM is calculated only for the given slice of the 3D image.

  • **kwargs (optional) – Additional parameters for GSM calculation. The keyword arguments are passed to viqa.fr_metrics.gsm.gradient_similarity().

Returns:

score_val – GSM score value.

Return type:

float

Raises:

ValueError – If invalid dimension given in dim. If images are neither 2D nor 3D. If images are 3D, but dim is not given. If im_slice is given, but not an integer.

Warns:

RuntimeWarning – If dim or im_slice is given for 2D images.

If im_slice is not given, but dim is given for 3D images, GSM is calculated for the full volume.

Notes

For 3D images if dim is given, but im_slice is not, the GSM is calculated for the full volume of the 3D image. This is implemented as mean of the GSM values of all slices of the given dimension. If dim is given and im_slice is given, the GSM is calculated for the given slice of the given dimension (represents a 2D metric of the given slice). This implementation is adapted for 3D images if experimental=True. Therefore, 12 kernels are used instead of the original 4. The gradient is calculated by

\[\max_{n=1,2,...,N} \lbrace \pmb{I} * \mathcal{K}_{n} \rbrace \text{ instead of } \max_{n=1,2,...,N} \lbrace \operatorname{mean2} (\lvert \pmb{X} \cdot \mathcal{K}_{n} \rvert) \rbrace\]

with \(\pmb{I}\) denoting the Image, \(\mathcal{K}_{n}\) denoting the Kernel n and \(\pmb{X}\) denoting an image block.

print_score(decimals=2)[source]

Print the GSM score value of the last calculation.

Parameters:

decimals (int, default=2) – Number of decimal places to print the score value.

Warns:

RuntimeWarning – If score_val is not available.

export_results(path, filename)

Export the score to a csv file.

Parameters:
  • path (str) – The path where the csv file should be saved.

  • filename (str) – The name of the csv file.

Notes

The arguments get passed to viqa.utils.export_results().

load_images(img_r, img_m)

Load the images and perform checks.

Parameters:
  • img_r (np.ndarray, viqa.ImageArray, torch.Tensor, str or os.PathLike) – The reference image.

  • img_m (np.ndarray, viqa.ImageArray, torch.Tensor, str or os.PathLike) – The modified image.

Returns: