viqa.multiple.BatchMetrics

class viqa.multiple.BatchMetrics(file_dir, pairs_file, metrics, metrics_parameters)[source]

Class to calculate metrics in batch mode.

results

Dictionary containing the results of the metrics.

Type:

dict

file_dir

Directory where the images are stored.

Type:

str

metrics

List of metric instances.

Type:

list

metrics_parameters

List of dictionaries containing the parameters for the metrics.

Type:

list

pairs_file

Path to the file containing the image pairs.

Type:

str

pairs

List of dictionaries containing the image pairs.

Type:

list

Parameters:
  • file_dir (str) – Directory where the images are stored.

  • pairs_file (str) –

    Path to the file containing the image pairs. Accepted delimiter characters are ‘,’, ‘;’, and ‘ ‘.

    CSV/TSV file layout

    reference_image

    modified_image

    image_path

    image_path

  • 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 If the pairs file does not contain the columns ‘reference_image’ and ‘modified_image’.

Notes

Make sure to use a well-structured CSV/TSV file as performance is better with e.g. the same reference image in multiple consecutive rows.

Attention

In image pairs with unequal shapes, the modified image will be resized to the shape of the reference image in the calculate() method.

Examples

>>> from viqa import BatchMetrics, PSNR, QMeasure
>>> metrics = [PSNR(data_range=1), QMeasure(data_range=1)]
>>> metrics_parameters = [{}, {'hist_bins': 16, 'num_peaks': 2}]
>>> batch = BatchMetrics(
...     file_dir='path/to/images',
...     pairs_file='path/to/pairs.csv',
...     metrics=metrics,
...     metrics_parameters=metrics_parameters
... )
>>> batch.calculate()
>>> batch.export_results(file_path='path/to/results', file_name='results.csv')
calculate(**kwargs)[source]

Calculate the metrics in batch mode.

Parameters:
Returns:

results – Dictionary containing the results of the metrics.

Return type:

dict

Warns:

UserWarning – If the images are the same as in the previous pair.

report(csv=True, metadata=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.

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

  • 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 viqa.utils.export_image().

  • 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.

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.