dival.measure module

Provides the abstract Measure base class and some popular measures.

Measure instances are identified by a unique short_name, which is used by the evaluation module.

dival.measure.gen_unique_name(name_orig)[source]
class dival.measure.Measure(short_name=None)[source]

Bases: ABC

Abstract base class for measures used for evaluation.

In subclasses, either __init__() should be inherited or it should call super().__init__() in order to register the short_name and to ensure it is unique.

measure_type

The measure type. Measures with type 'distance' should attain small values if the reconstruction is good. Measures with type 'quality' should attain large values if the reconstruction is good.

Type:

{'distance', 'quality'}

short_name

Short name of the measure, used as identifier (key in measure_dict).

Type:

str

name

Name of the measure.

Type:

str

description

Description of the measure.

Type:

str

measure_type = None

Class attribute, default value for measure_type.

name = ''

Class attribute, default value for name.

description = ''

Class attribute, default value for description.

measure_dict = {'l2': <dival.measure.L2Measure object>, 'mse': <dival.measure.MSEMeasure object>, 'psnr': <dival.measure.PSNRMeasure object>, 'ssim': <dival.measure.SSIMMeasure object>}

Class attribute, registry of all measures with their short_name as key.

__init__(short_name=None)[source]
Parameters:

short_name (str, optional) – The short name of this measure, used as identifier in measure_dict. If None is passed and short_name was not set by the subclass, the __name__ of the subclass is used. If short_name is already taken by another instance, a unique short name is generated by appending a suffix of format '_%d'.

short_name = ''

Class attribute, default value for short_name.

abstract apply(reconstruction, ground_truth)[source]

Calculate the value of this measure.

Parameters:
  • reconstruction (odl element) – The reconstruction.

  • ground_truth (odl element) – The ground truth to compare with.

Returns:

value – The value of this measure for the given reconstruction and ground_truth.

Return type:

float

classmethod get_by_short_name(short_name)[source]

Return Measure instance with given short name by registry lookup.

Parameters:

short_name (str) – Short name, identifier in measure_dict.

Returns:

measure – The instance.

Return type:

Measure

as_operator_for_fixed_ground_truth(ground_truth)[source]

Return an odl operator that can be applied to different reconstructions for fixed ground truth.

Returns:

op – odl operator.

Return type:

odl operator

class dival.measure.L2Measure(short_name=None)[source]

Bases: Measure

The euclidean (l2) distance measure.

measure_type = 'distance'

Class attribute, default value for measure_type.

short_name = 'l2'

Class attribute, default value for short_name.

name = 'euclidean distance'

Class attribute, default value for name.

description = 'distance given by sqrt(sum((reconstruction-ground_truth)**2))'

Class attribute, default value for description.

apply(reconstruction, ground_truth)[source]

Calculate the value of this measure.

Parameters:
  • reconstruction (odl element) – The reconstruction.

  • ground_truth (odl element) – The ground truth to compare with.

Returns:

value – The value of this measure for the given reconstruction and ground_truth.

Return type:

float

class dival.measure.MSEMeasure(short_name=None)[source]

Bases: Measure

The mean squared error distance measure.

measure_type = 'distance'

Class attribute, default value for measure_type.

short_name = 'mse'

Class attribute, default value for short_name.

name = 'mean squared error'

Class attribute, default value for name.

description = 'distance given by 1/n * sum((reconstruction-ground_truth)**2)'

Class attribute, default value for description.

apply(reconstruction, ground_truth)[source]

Calculate the value of this measure.

Parameters:
  • reconstruction (odl element) – The reconstruction.

  • ground_truth (odl element) – The ground truth to compare with.

Returns:

value – The value of this measure for the given reconstruction and ground_truth.

Return type:

float

dival.measure.MSE = <dival.measure.MSEMeasure object>

Instance of MSEMeasure, with short_name='mse'.

class dival.measure.PSNRMeasure(data_range=None, short_name=None)[source]

Bases: Measure

The peak signal-to-noise ratio (PSNR) measure.

The data range is automatically determined from the ground truth if not given to the constructor.

data_range

The data range (max-min possible value). If data_range is None, np.max(ground_truth) - np.min(ground_truth) is used in apply().

Type:

float or None

measure_type = 'quality'

Class attribute, default value for measure_type.

short_name = 'psnr'

Class attribute, default value for short_name.

name = 'peak signal-to-noise ratio'

Class attribute, default value for name.

description = 'quality given by 10*log10(MAX**2/MSE)'

Class attribute, default value for description.

__init__(data_range=None, short_name=None)[source]
Parameters:
  • data_range (float, optional) – The data range (max-min possible value). If data_range is None, np.max(ground_truth) - np.min(ground_truth) is used in apply().

  • short_name (str, optional) – Short name.

apply(reconstruction, ground_truth)[source]

Calculate the value of this measure.

Parameters:
  • reconstruction (odl element) – The reconstruction.

  • ground_truth (odl element) – The ground truth to compare with.

Returns:

value – The value of this measure for the given reconstruction and ground_truth.

Return type:

float

dival.measure.PSNR = <dival.measure.PSNRMeasure object>

Instance of PSNRMeasure, with data_range=None and short_name='psnr'.

class dival.measure.SSIMMeasure(short_name=None, **kwargs)[source]

Bases: Measure

The structural similarity index measure.

measure_type = 'quality'

Class attribute, default value for measure_type.

short_name = 'ssim'

Class attribute, default value for short_name.

name = 'structural similarity index'

Class attribute, default value for name.

description = 'The (M)SSIM like described in `Wang et al. 2014 <https://doi.org/10.1109/TIP.2003.819861>`_.'

Class attribute, default value for description.

__init__(short_name=None, **kwargs)[source]

This is a wrapper for skimage.metrics.structural_similarity(). The data range is automatically determined from the ground truth if not given to the constructor.

Parameters:
  • short_name (str, optional) – Short name.

  • kwargs (dict, optional) – Keyword arguments that will be passed to structural_similarity() in apply(). If data_range is not specified, np.max(ground_truth) - np.min(ground_truth) is used.

apply(reconstruction, ground_truth)[source]

Calculate the value of this measure.

Parameters:
  • reconstruction (odl element) – The reconstruction.

  • ground_truth (odl element) – The ground truth to compare with.

Returns:

value – The value of this measure for the given reconstruction and ground_truth.

Return type:

float

dival.measure.SSIM = <dival.measure.SSIMMeasure object>

Instance of SSIMMeasure, with data_range=None and short_name='ssim'.