scico.flax.examples.data_generation

Functionality to generate training data for Flax example scripts.

Computation is distributed via ray to reduce processing time.

Functions

batched_f(f_, vr)

Distribute application of operator over a batch of vectors

distributed_data_generation(imgenf, size, nimg)

Data generation distributed among processes using ray.

generate_blur_data(nimg, size, blur_kernel, ...)

Generate batch of blurred data.

generate_ct_data(nimg, size, nproj[, ...])

Generate batch of computed tomography (CT) data.

generate_foam1_images(seed, size, ndata)

Generate batch of xdesign foam-like structures.

generate_foam2_images(seed, size, ndata)

Generate batch of foam2 structures.

vector_f(f_, v)

Vectorize application of operator.

Classes

Foam2([size_range, gap, porosity, attn1, attn2])

Foam-like material with two attenuations.

UnitCircle()

class scico.flax.examples.data_generation.Foam2(size_range=[0.05, 0.01], gap=0, porosity=1, attn1=1.0, attn2=10.0)[source]

Bases: UnitCircle

Foam-like material with two attenuations.

Inheritance diagram of Foam2

Define functionality to generate phantom with structure similar to foam with two different attenuation properties.

Foam-like structure with two different attenuations. Circles for material 1 are more sparse than for material 2 by design.

Parameters:
  • size_range (Union[float, List[float]]) – The radius, or range of radius, of the circles to be added. Default: [0.05, 0.01].

  • gap (float) – Minimum distance between circle boundaries. Default: 0.

  • porosity (float) – Target porosity. Must be a value between [0, 1]. Default: 1.

  • attn1 (float) – Mass attenuation parameter for material 1. Default: 1.

  • attn2 (float) – Mass attenuation parameter for material 2. Default: 10.

scico.flax.examples.data_generation.generate_foam1_images(seed, size, ndata)[source]

Generate batch of xdesign foam-like structures.

Generate batch of images with xdesign foam-like structure, which uses one attenuation.

Parameters:
  • seed (float) – Seed for data generation.

  • size (int) – Size of image to generate.

  • ndata (int) – Number of images to generate.

Return type:

ndarray

Returns:

Array of generated data.

scico.flax.examples.data_generation.generate_foam2_images(seed, size, ndata)[source]

Generate batch of foam2 structures.

Generate batch of images with Foam2 structure (foam-like material with two different attenuations).

Parameters:
  • seed (float) – Seed for data generation.

  • size (int) – Size of image to generate.

  • ndata (int) – Number of images to generate.

Return type:

ndarray

Returns:

Array of generated data.

scico.flax.examples.data_generation.vector_f(f_, v)[source]

Vectorize application of operator.

Parameters:
  • f – Operator to apply.

  • v (Array) – Array to evaluate.

Return type:

Array

Returns:

Result of evaluating operator over given arrays.

scico.flax.examples.data_generation.batched_f(f_, vr)[source]
Distribute application of operator over a batch of vectors

among available processes.

Parameters:
  • f – Operator to apply.

  • vr (Array) – Batch of arrays to evaluate.

Return type:

Array

Returns:

Result of evaluating operator over given batch of arrays. This evaluation preserves the batch axis.

scico.flax.examples.data_generation.generate_ct_data(nimg, size, nproj, imgfunc=<function generate_foam2_images>, seed=1234, verbose=False)[source]

Generate batch of computed tomography (CT) data.

Generate batch of CT data for training of machine learning network models.

Parameters:
  • nimg (int) – Number of images to generate.

  • size (int) – Size of reconstruction images.

  • nproj (int) – Number of CT views.

  • imgfunc (Callable) – Function for generating input images (e.g. foams).

  • seed (int) – Seed for data generation.

  • verbose (bool) – Flag indicating whether to print status messages.

Return type:

Tuple[Array, Array, Array]

Returns:

tuple

A tuple (img, sino, fbp) containing:

  • img : (jax.Array): Generated foam images.

  • sino : (jax.Array): Corresponding sinograms.

  • fbp : (jax.Array) Corresponding filtered back projections.

scico.flax.examples.data_generation.generate_blur_data(nimg, size, blur_kernel, noise_sigma, imgfunc=<function generate_foam1_images>, seed=4321, verbose=False)[source]

Generate batch of blurred data.

Generate batch of blurred data for training of machine learning network models.

Parameters:
  • nimg (int) – Number of images to generate.

  • size (int) – Size of reconstruction images.

  • blur_kernel (Array) – Kernel for blurring the generated images.

  • noise_sigma (float) – Level of additive Gaussian noise to apply.

  • imgfunc (Callable) – Function to generate foams.

  • seed (int) – Seed for data generation.

  • verbose (bool) – Flag indicating whether to print status messages.

Return type:

Tuple[Array, Array]

Returns:

tuple

A tuple (img, blurn) containing:

  • img : Generated foam images.

  • blurn : Corresponding blurred and noisy images.

scico.flax.examples.data_generation.distributed_data_generation(imgenf, size, nimg, seedg=123)[source]

Data generation distributed among processes using ray.

Warning: callable imgenf should not make use of any jax functions to avoid the risk of errors when running with GPU devices, in which case jax is initialized to expect the availability of GPUs, which are then not available within the ray.remote function due to the absence of any declared GPUs as a num_gpus parameter of @ray.remote.

Parameters:
  • imagenf – Function for batch-data generation.

  • size (int) – Size of image to generate.

  • ndata – Number of images to generate.

  • seedg (float) – Base seed for data generation.

Return type:

ndarray

Returns:

Array of generated data.