dival.datasets.fbp_dataset module

dival.datasets.fbp_dataset.generate_fbp_cache_files(dataset, ray_trafo, cache_files, size=None, filter_type='Hann', frequency_scaling=1.0)[source]

Generate cache files for a CT dataset, whereby FBPs are precomputed from the observations.

The cache files can be accessed by a CachedDataset, which can be obtained by get_cached_fbp_dataset().

Parameters
  • dataset (Dataset) – CT dataset with observation and ground truth pairs. The FBPs are computed from the observations.

  • ray_trafo (odl.tomo.RayTransform) – Ray transform from which the FBP operator is constructed.

  • cache_files (dict of 2-tuple of (str or None)) –

    See cached_dataset.generate_cache_files().

    As an example, to cache the FBPs (but not the ground truths) for parts 'train' and 'validation':

    {'train':      ('cache_train_fbp.npy',      None),
     'validation': ('cache_validation_fbp.npy', None)}
    

  • size (dict of int, optional) – Numbers of samples to cache for each dataset part. If a field is omitted or has value None, all samples are cached. Default: {}.

  • filter_type (str, optional) – Filter type accepted by odl.tomo.fbp_op(). Default: 'Hann'.

  • frequency_scaling (float, optional) – Relative cutoff frequency passed to odl.tomo.fbp_op(). Default: 1.0.

dival.datasets.fbp_dataset.get_cached_fbp_dataset(dataset, ray_trafo, cache_files, size=None, filter_type='Hann', frequency_scaling=1.0)[source]

Return CachedDataset with FBP and ground truth pairs corresponding to the passed CT dataset.

See generate_fbp_cache_files() for generating the cache files.

If for a dataset part no FBP cache is specified, these FBPs are computed from the observations on the fly.

Parameters
  • dataset (Dataset) – CT dataset with observation and ground truth pairs. For all parts and components, for which caches are specified, the samples of this dataset are ignored.

  • ray_trafo (odl.tomo.RayTransform) – Ray transform from which the FBP operator is constructed that is called if an FBP cache is missing.

  • cache_files (dict of 2-tuple of (str or None)) –

    See cached_dataset.CachedDataset().

    As an example, to use caches for the FBPs (but not the ground truths) for parts 'train' and 'validation':

    {'train':      ('cache_train_fbp.npy',      None),
     'validation': ('cache_validation_fbp.npy', None)}
    

  • size (dict of int, optional) – Numbers of samples for each part. If a field is omitted or has value None, all available samples are used, which may be less than the number of samples in the original dataset if the cache contains fewer samples. Default: {}.

  • filter_type (str, optional) – Filter type accepted by odl.tomo.fbp_op(). Default: 'Hann'.

  • frequency_scaling (float, optional) – Relative cutoff frequency passed to odl.tomo.fbp_op(). Default: 1.0.

Returns

cached_fbp_dataset – Dataset with FBP and ground truth pairs that uses the specified cache files.

Return type

CachedDataset

class dival.datasets.fbp_dataset.FBPDataset(dataset, ray_trafo, filter_type='Hann', frequency_scaling=1.0)[source]

Bases: dival.datasets.dataset.Dataset

Dataset computing filtered back-projections for a CT dataset on the fly.

Each sample is a pair of a FBP and a ground truth image.

__init__(dataset, ray_trafo, filter_type='Hann', frequency_scaling=1.0)[source]
Parameters
  • dataset (Dataset) – CT dataset. FBPs are computed from the observations, the ground truth is taken directly from the dataset.

  • ray_trafo (odl.tomo.RayTransform) – Ray transform from which the FBP operator is constructed.

  • filter_type (str, optional) – Filter type accepted by odl.tomo.fbp_op(). Default: 'Hann'.

  • frequency_scaling (float, optional) – Relative cutoff frequency passed to odl.tomo.fbp_op(). Default: 1.0.

generator(part='train')[source]

Yield data.

The default implementation calls get_sample() if the dataset implements it (i.e., supports random access).

Parameters

part ({'train', 'validation', 'test'}, optional) – Whether to yield train, validation or test data. Default is 'train'.

Yields

data (odl element or tuple of odl elements) – Sample of the dataset.

get_sample(index, part='train', out=None)[source]

Get single sample by index.

Parameters
  • index (int) – Index of the sample.

  • part ({'train', 'validation', 'test'}, optional) – The data part. Default is 'train'.

  • out (array-like or tuple of (array-like or bool) or None) –

    Array(s) (or e.g. odl element(s)) to which the sample is written. A tuple should be passed, if the dataset returns two or more arrays per sample (i.e. pairs, …). If a tuple element is a bool, it has the following meaning:

    True

    Create a new array and return it.

    False

    Do not return this array, i.e. None is returned.

Returns

sample – E.g. for a pair dataset: (array, None) if out=(True, False).

Return type

[tuple of ] (array-like or None)

get_samples(key, part='train', out=None)[source]

Get samples by slice or range.

The default implementation calls get_sample() if the dataset implements it.

Parameters
  • key (slice or range) – Indexes of the samples.

  • part ({'train', 'validation', 'test'}, optional) – The data part. Default is 'train'.

  • out (array-like or tuple of (array-like or bool) or None) –

    Array(s) (or e.g. odl element(s)) to which the sample is written. The first dimension must match the number of samples requested. A tuple should be passed, if the dataset returns two or more arrays per sample (i.e. pairs, …). If a tuple element is a bool, it has the following meaning:

    True

    Create a new array and return it.

    False

    Do not return this array, i.e. None is returned.

Returns

samples – If the dataset has multiple arrays per sample, a tuple holding arrays is returned. E.g. for a pair dataset: (array, None) if out=(True, False). The samples are stacked in the first (additional) dimension of each array.

Return type

[tuple of ] (array-like or None)