Synthetic data

Nuclei image

timagetk.synthetic_data.nuclei_image.example_nuclei_image(n_points=100, extent=50.0, voxelsize=(0.5, 0.25, 0.25), nuclei_radius=1.5, nuclei_intensity=10000.0, **kwargs)[source]

Generate a synthetic 3D nuclei image.

The function creates a 3D image over a cubic volume of a given extent and populates it with randomly scattered nuclei. Nuclei are represented by a spherical blobs of intensity of a same radius.

Parameters:
  • n_points (int, optional) – Number of nuclei in the image. Defaults to 100.

  • extent (float, optional) – The extent of the output image (in µm). Defaults to 50..

  • voxelsize (list(float), optional) – Length-3 list of image Z,Y,X voxelsize (in µm). Defaults to (0.5, 0.25, 0.25).

  • nuclei_radius (float, optional) – Radius of the spherical blobs representing nuclei (in µm). Defaults to 1.5.

  • nuclei_intensity (float, optional) – The intensity value of the spherical blobs. Defaults to 10000.

  • dtype ({"uint8", "uint16"}) – The bit-depth of the intensity image. Defaults to 'uint16'.

Returns:

  • timagetk.SpatialImage – The generated nuclei image.

  • dict – The XYZ-ordered 3D point positions used to generate the nuclei image.

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from timagetk.synthetic_data.nuclei_image import example_nuclei_image
>>> from timagetk.visu.mplt import image_plot
>>> nuclei_img, points = example_nuclei_image(n_points=10, extent=15., nuclei_radius=1.5, nuclei_intensity=10000)
>>> points = np.array(list(points.values()))
>>> plt.figure(figsize=(5, 5))
>>> plt.scatter(points[:,0], points[:,1], color='r')  # Show X & Y coordinates
>>> image_plot(nuclei_img.max(axis=0),plt.gca(),val_range='auto')
>>> plt.show()
timagetk.synthetic_data.nuclei_image.example_nuclei_signal_images(n_points=100, extent=50.0, voxelsize=(0.5, 0.25, 0.25), nuclei_radius=1.5, signal_type='random', signal_intensity=10000.0, **kwargs)[source]

Generate a synthetic 3D nuclei image with a second signal channel.

The function creates a 3D image over a cubic volume of a given extent and populates it with randomly scattered nuclei. Nuclei are represented by a spherical blobs of intensity of a same radius.

In the second channel, a signal value is associated with each nucleus and multiplied with the intensity of the corresponding spherical blob. The signal distribution can either be random or radially decreasing.

Parameters:
  • n_points (int, optional) – Number of nuclei in the image. Defaults to 100.

  • extent (float, optional) – The extent of the output image (in µm). Defaults to 50..

  • voxelsize (list(float), optional) – Len-3 list of image Z,Y,X voxelsize (in µm). Defaults to (0.5, 0.25, 0.25).

  • nuclei_radius (float, optional) – Radius of the spherical blobs representing nuclei (in µm). Defaults to 1.5.

  • signal_type ({'random', 'center'}) – Whether to use a radially decreasing (‘center’) or a random signal (‘random’). Defaults to 'random'.

  • signal_intensity (float, optional) – The intensity value of the spherical blobs. Defaults to 10000.

  • dtype ({"uint8", "uint16"}) – The bit-depth of the intensity image. Defaults to 'uint16'.

Returns:

  • timagetk.SpatialImage – The generated nuclei reference image

  • timagetk.SpatialImage – The generated signal intensity image

  • dict – The random X,Y,Z 3D point positions used to generate the nuclei

  • dict – The signal values associated with each nucleus

Examples

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from timagetk.synthetic_data.nuclei_image import example_nuclei_signal_images
>>> from timagetk.visu.mplt import image_plot
>>> nuclei_img, signal_img, points, point_signals = example_nuclei_signal_images(n_points=10, extent=15., nuclei_radius=1.5, signal_intensity=10000)
>>> points = np.array(list(points.values()))
>>> point_signals = np.array(list(point_signals.values()))
>>> fig, axes = plt.subplots(2, 2)
>>> fig.set_size_inches(w=4*5., h=5.)
>>> axes[0, 0].scatter(points[:,0], points[:,1], color='r')  # Show X & Y coordinates
>>> axes[0, 1].scatter(points[:,0], points[:,1], c=point_signals, cmap='viridis')  # Show X & Y coordinates
>>> image_plot(nuclei_img.max(axis=0),axes[1, 0],'gray',val_range='auto')
>>> image_plot(signal_img.max(axis=0),axes[1, 1],'gray',val_range='auto')
>>> plt.show()
timagetk.synthetic_data.nuclei_image.nuclei_image_from_point_positions(points, extent=50.0, voxelsize=(0.5, 0.25, 0.25), nuclei_radius=1.5, nuclei_intensity=10000.0, point_signals=None, **kwargs)[source]

Create a 3D nuclei image from a dictionary of 3D points.

Parameters:
  • points (dict) – Dictionary with X,Y,Z 3D positions as values

  • extent (float, optional) – The extent of the output image (in µm)

  • voxelsize (list(float), optional) – Length-3 list of image Z,Y,X voxel-size (in µm)

  • nuclei_radius (float, optional) – Radius of the spherical blobs representing nuclei (in µm)

  • nuclei_intensity (float, optional) – The intensity value of the spherical blobs

  • point_signals (dict, optional) – Dictionary with [0,1] intensity factors for each point

  • dtype ({"uint8", "uint16"}) – The bit-depth of the intensity image.

Returns:

timagetk.SpatialImage – The generated nuclei image

Wall image

timagetk.synthetic_data.wall_image.example_layered_sphere_wall_image(extent=60.0, voxelsize=(0.6, 0.6, 0.6), n_points=12, n_layers=1, wall_sigma=None, wall_intensity=None, return_points=False, **kwargs)[source]

Generate a synthetic 3D image representing the walls of a spherical tissue.

The function creates a 3D image over a cubic volume of a given extent. It consists of successive spherical cell layers of equal height around a central spherical cell. The number of cells in each layer is set so that cells in every layer have similar volumes.

Parameters:
  • extent (float, optional) – The extent of the output image (in µm). Defaults to 60..

  • voxelsize (list(float), optional) – Length-3 list of image voxelsize (in µm), ZYX sorted. Defaults to (0.6, 0.6, 0.6).

  • n_points (int, optional) – The number of cells on innermost spherical layer. Defaults to 12.

  • n_layers (int, optional) – The number of layer around the central cell. Defaults to 1.

  • wall_sigma (float, optional) – Sigma value determining the wall width, in real units. Defaults to the image voxelsize seg_img.voxelsize.

  • intensity (float, optional) – Signal intensity of the wall interfaces. Defaults to 2/3 of the maximum value based on dtype.

  • return_points (bool, optional) – Whether to return the points representing the cell centers.

  • dtype ({"uint8", "uint16"}) – The bit-depth of the intensity image. Defaults to 'uint8'.

  • count (bool) – Whether to have higher signal at wall junctions. Defaults to True.

Returns:

  • timagetk.SpatialImage – The generated cell wall reference image.

  • dict, optional – The 3D point positions, XYZ sorted, used to generate the cells.

Examples

>>> from timagetk.synthetic_data.wall_image import example_layered_sphere_wall_image
>>> from timagetk.visu.stack import orthogonal_view
>>> wall_img = example_layered_sphere_wall_image()
>>> v = orthogonal_view(wall_img, suptitle="Synthetic 3D wall intensity image", cmap='gray', val_range='auto')
timagetk.synthetic_data.wall_image.wall_image_from_labelled_image(labelled_image, wall_sigma=None, wall_intensity=None, **kwargs)[source]

Generate a 3D image representing the walls of a labelled image.

Parameters:
  • labelled_image (timagetk.LabelledImage) – The cell image on which to compute the wall signal.

  • wall_sigma (float, optional) – Sigma value determining the wall width, in real units. Defaults to the image voxelsize seg_img.voxelsize.

  • intensity (float, optional) – Signal intensity of the wall interfaces. Defaults to 2/3 of the maximum value based on dtype.

  • dtype ({"uint8", "uint16"}) – The bit-depth of the intensity image. Defaults to 'uint8'.

  • count (bool, optional) – Whether to have higher signal at wall junctions. Defaults to True.

Returns:

timagetk.SpatialImage – The generated cell wall intensity image.

Examples

>>> from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
>>> from timagetk.synthetic_data.wall_image import wall_image_from_labelled_image
>>> from timagetk.visu.mplt import image_plot
>>> seg_img = example_layered_sphere_labelled_image()
>>> wall_img = wall_image_from_labelled_image(seg_img)
>>> z_sl = seg_img.get_shape("z") // 2
>>> from timagetk.visu.mplt import grayscale_imshow
>>> v = grayscale_imshow([seg_img, wall_img], slice_id=z_sl, cmap=['glasbey', 'gray'], val_range='auto')

Labelled image

timagetk.synthetic_data.labelled_image.example_layered_sphere_labelled_image(extent=60.0, voxelsize=(0.6, 0.6, 0.6), n_points=12, n_layers=1, return_points=False, **kwargs)[source]

Generate a synthetic 3D labelled image representing a spherical tissue.

The function creates a 3D labelled image over a cubic volume of a given extent. It consists of successive spherical cell layers of equal height around a central spherical cell. The number of cells in each layer is set so that cells in every layer have similar volumes.

Parameters:
  • extent (float, optional) – The extent of the output image (in µm). Defaults to 60..

  • voxelsize (list(float), optional) – Length-3 list of image Z,Y,X voxelsize (in µm). Defaults to (0.6, 0.6, 0.6).

  • n_points (int, optional) – The number of cells on innermost spherical layer. Defaults to 12.

  • n_layers (int, optional) – The number of layer around the central cell. Defaults to 1.

  • return_points (bool, optional) – Whether to return the points representing the cell centers. Defaults to False.

Returns:

  • timagetk.LabelledImage – The generated labelled cell image

  • dict, optional – The 3D X,Y,Z point positions used to generate the cells

Examples

>>> from timagetk.synthetic_data.labelled_image import example_layered_sphere_labelled_image
>>> seg_img = example_layered_sphere_labelled_image()
>>> print(seg_img)
LabelledImage object with following metadata:
   - shape: (100, 100, 100)
   - ndim: 3
   - dtype: uint16
   - axes_order: ZYX
   - voxelsize: [0.6, 0.6, 0.6]
   - unit: 1e-06
   - origin: [0, 0, 0]
   - extent: [59.4, 59.4, 59.4]
   - acquisition_date: None
   - not_a_label: 0
>>> from timagetk.visu.stack import orthogonal_view
>>> v = orthogonal_view(seg_img, cmap='glasbey', val_range='auto')

Miscellaneous

timagetk.synthetic_data.util.point_position_optimization(points, omega_attraction=1.0, omega_repulsion=1.0, target_distance=1, sigma_deformation=0.1, n_iterations=100, force_centering=True, center=array([0., 0., 0.]), constraint_radius=False, radius=50.0)[source]

Optimize the positions of a dictionary of 3D points.

The function performs an optimization of an initial dictionary of 3D points by an attraction-repulsion energy minimization process. The result is a new dictionary in which the 3D points tend to be evenly distributed in space.

Parameters:
  • points (dict) – Dictionary with 3D positions as values.

  • omega_attraction (float) – Coefficient of the attraction term of the energy.

  • omega_repulsion (float) – Coefficient of the repulsion term of the energy.

  • target_distance (float) – Optimal distance between points for the energy definition.

  • sigma_deformation (float) – Maximal displacement of the points at each iteration.

  • n_iterations (int) – Number of iterations in the optimization process.

  • force_centering (bool) – Whether to constraint the positions to remain centered.

  • center (numpy.ndarray) – Length-3 array representing the 3D position of the center to use.

  • constraint_radius (bool) – Whether to constraint the positions at a fixed distance from the center.

  • radius (float) – The fixed distance between the points and the center.

Returns:

dict – The dictionary of optimized 3D positions.

timagetk.synthetic_data.util.pseudo_gradient_norm(seg_img, dtype='uint8', wall_sigma=None, intensity=None, count=True)[source]

Create an image with signal at wall interfaces of a labelled image.

The method starts by counting the number of different label values around each voxel,

and assigns an intensity value where this number is greater than 2.

The signal is then smoothed by a Gaussian kernel to simulate a wall-marker intensity image.

Parameters:
  • seg_img (timagetk.LabelledImage) – The cell image on which to compute the wall signal.

  • dtype (str or numpy.dtype, optional) – Set the dtype of the returned image. Defaults to 'uint8'.

  • wall_sigma (float, optional) – Sigma value determining the wall width, in real units. Defaults to the image voxelsize seg_img.voxelsize.

  • intensity (float, optional) – Signal intensity of the wall interfaces. Defaults to 2/3 of the maximum value based on dtype.

  • count (bool, optional) – Whether to have higher signal at wall junctions. Defaults to True.

Returns:

timagetk.SpatialImage – The wall signal intensity image.

Examples

>>> from timagetk.synthetic_data.util import pseudo_gradient_norm
>>> from timagetk import LabelledImage
>>> from timagetk.io import imread
>>> from timagetk.io.util import shared_dataset
>>> from timagetk.visu.stack import orthogonal_view
>>> img_path = shared_dataset("p58", "segmented")[0]
>>> seg_image = imread(img_path, LabelledImage, not_a_label=0)
>>> v = orthogonal_view(seg_image, cmap='glasbey', val_range='auto')
>>> # Example 1 - Automatic creation of the wall signal intensity image:
>>> int_image = pseudo_gradient_norm(seg_image)
>>> v = orthogonal_view(int_image, cmap='gray', val_range='dtype')
>>> # Example 2 - Automatic creation of the wall signal intensity image, without gaussian smoothing:
>>> int_image = pseudo_gradient_norm(seg_image, wall_sigma=0)
>>> v = orthogonal_view(int_image, cmap='gray', val_range='dtype')