viqa.multiple.MultipleMetrics

class viqa.multiple.MultipleMetrics(metrics, metrics_parameters)[source]

Class to calculate metrics in batch mode.

results

Dictionary containing the results of the metrics.

Type:

dict

metrics

List of metric instances.

Type:

list

metrics_parameters

List of dictionaries containing the parameters for the metrics.

Type:

list

Parameters:
  • metrics (list) – List of metric instances.

  • metrics_parameters (list) – List of dictionaries containing the parameters for the metrics.

Raises:

ValueError – If the number of metrics and metric parameters is not equal. If the metric list contains non-metric objects. If the parameters list contains non-dictionary objects

Notes

Attention

In image pairs with unequal shapes, the modified image will be resized to the shape of the reference image.

Examples

>>> from viqa import MultipleMetrics, PSNR, QMeasure
>>> metrics = [PSNR(data_range=1), QMeasure(data_range=1)]
>>> metrics_parameters = [{}, {'hist_bins': 16, 'num_peaks': 2}]
>>> multiple = MultipleMetrics(
...     metrics=metrics,
...     metrics_parameters=metrics_parameters
... )
>>> img_r = 'path/to/reference_image'
>>> img_m = 'path/to/modified_image'
>>> multiple.calculate(img_r, img_m)
>>> multiple.report(
...     csv=True,
...     metadata=True,
...     text=False,
...     image=False,
...     file_path='path/to/results'
... )
calculate(img_r, img_m, **kwargs)[source]

Calculate multiple metrics for an image pair.

Parameters:
  • img_r (str or np.ndarray) – Path to the reference image or the image itself.

  • img_m (str or np.ndarray) – Path to the modified image or the image itself.

  • kwargs (dict) – Additional parameters. Passed to viqa.utils.load_data().

  • scaling_order (int, default=1) – Order of the spline interpolation used for image resizing. Default is 1. Passed to skimage.transform.resize().

Returns:

results – Dictionary containing the results of the metrics.

Return type:

dict

report(csv=True, metadata=True, text=True, image=False, file_path='.', project_name=None, **kwargs)[source]

Report the results and metadata.

Parameters:
  • csv (bool, default=True) – If True, the results will be exported to a csv file. export_results() will be called.

  • metadata (bool, default=True) – If True, the metadata will be exported to a txt file. export_metadata() will be called.

  • text (bool, default=True) – If True, the metric values will be printed to the console. print_values() will be called.

  • image (bool, default=False) – If True, the reference and modified image will be plotted side by side. viqa.utils.export_image() will be called.

  • file_path (str, optional) – Path to the directory where the files should be saved. If None, the files will be saved in the current working directory.

  • project_name (str, optional) – Name of the project. Used for the image file name.

  • kwargs (dict) – Additional parameters. Passed to print_image().

  • decimals (int, default=2) – Number of decimal places for the printed metric values in the console.

  • export_image (bool, default=False) – If True, the image will be saved as a file. Default is False.

  • img_r (str or np.ndarray) – Path to the reference image or the image itself.

  • img_m (str or np.ndarray) – Path to the modified image or the image itself.

  • x (int, optional) – The index of the slice to be plotted. Only one axis can be specified.

  • y (int, optional) – The index of the slice to be plotted. Only one axis can be specified.

  • z (int, optional) – The index of the slice to be plotted. Only one axis can be specified.

Raises:

ValueError – If the reference and modified image are not provided

print_values(decimals=2)[source]

Print the metric values to the console.

Parameters:

decimals (int, default=2) – Number of decimal places for the printed metric values.

export_results(file_path, file_name='results.csv')[source]

Export the results to a csv file.

Parameters:
  • file_path (str) – Path to the directory where the csv file should be saved.

  • file_name (str, default='results.csv') – Name of the csv file. Default is ‘results.csv’.

Notes

Attention

The csv file will be overwritten if it already exists.

export_metadata(file_path='.', file_name='metadata.txt')

Export the metadata (custom parameters and package version) to a txt file.

Parameters:
  • file_path (str) – Path to the directory where the txt file should be saved.

  • file_name (str, default='metadata.txt') – Name of the txt file. Default is ‘metadata.txt’.

Notes

Attention

The txt file will be overwritten if it already exists.