Peak detection

Peak detection module.

Nuclei detection is done using detection of local signal peaks. Then a local signal quantification can be performed to measure the intensity of nuclei targeted signal.

timagetk.algorithms.peak_detection.detect_nuclei(nuclei_img, threshold=3000.0, radius_range=(0.8, 1.4), step=0.2)[source]

Detect nuclei positions in a (16-bit) nuclei marker SpatialImage.

Parameters:
  • nuclei_img (timagetk.SpatialImage or timagetk.MultiChannelImage) – Intensity image with nuclei targeted signal.

  • threshold (float, optional) – Response to Gaussian filter threshold. # FIXME: use the binary threshold detection instead ?

  • radius_range (tuple, optional) – Range of nuclei size to detect.

  • step (float, optional) – Step of radius range.

  • channel (str) – If a MultiChannelImage is used as input image, select the channel to use with this algorithm.

Returns:

numpy.ndarray – Nuclei 3D positions in physical XYZ coordinates.

Examples

>>> import numpy as np
>>> from scipy.cluster.vq import vq
>>> from timagetk.algorithms.peak_detection import detect_nuclei
>>> from timagetk.synthetic_data.nuclei_image import example_nuclei_image
>>> # Let's start by creating a synthetic nuclei intensity image:
>>> nuclei_img, points = example_nuclei_image(n_points=10, extent=15., nuclei_radius=1.5, nuclei_intensity=10000, return_points=True)
>>> # Now we can detect nuclei positions on this synthetic image:
>>> nuclei_arr = detect_nuclei(nuclei_img, threshold=1500, radius_range=(1.3, 1.7))
>>> n_nuclei = nuclei_arr.shape[0]
>>> # It is now possible to compare detected nuclei positions & known position (ground-truth):
>>> true_points = np.array(list(points.values()))  # convert the dictionary into an XYZ sorted array of points coordinates
>>> matching = vq(true_points, nuclei_arr)
>>> # Let's display the detected nuclei as a 2D top-view projection:
>>> import matplotlib.pyplot as plt
>>> plt.figure(figsize=(10, 10))
>>> plt.scatter(true_points[:, 0], true_points[:, 1], color='red', label='Ground-truth')  # Show X & Y coordinates of ground truth coordinates in red
>>> plt.scatter(nuclei_arr[:, 0], nuclei_arr[:, 1], color='green', marker="x", label='Prediction')  # Show X & Y coordinates of predicted coordinates in green
>>> plt.imshow(nuclei_img.max(axis=0), cmap='gray', extent=(0, nuclei_img.extent[2], nuclei_img.extent[1], 0))  # Add maximum intensity projection of the nuclei signal
>>> plt.title("Example of nuclei detection on synthetic data")
>>> plt.legend()
>>> plt.show()
timagetk.algorithms.peak_detection.detect_peaks_3D_scale_space(scale_space_images, sigmas, threshold=None, voxelsize=[1, 1, 1])[source]

Identify local maxima in a 4D scale-space image.

Parameters:
  • scale_space_images (numpy.ndarray) – Scale-space transform of a 3d image.

  • sigmas (list) – List of scales used to generate the scale-space.

  • threshold (int, optional) – Minimal intensity to be reached by a candidate maximum.

  • voxelsize (list, optional) – The voxel-size of the scale space image.

Returns:

numpy.ndarray – Containing 4D coordinates of local maxima, sorted as S, Z, Y, X.

timagetk.algorithms.peak_detection.detect_segmentation_nuclei(nuclei_img, seg_img, background_label=1, radius_range=(0.8, 1.4), step=0.2)[source]

Detect nuclei positions in a nuclei SpatialImage using a LabelledImage.

The function detects spherical blobs of image intensity in a nuclei marker image, but uses a segmented membrane marker image to provide cell regions in the image. Only one nucleus is detected within each cell region of the segmented image, and its 3D position is associated with the cell label.

Parameters:
  • nuclei_img (timagetk.SpatialImage) – Intensity image with nuclei targeted signal.

  • seg_img (timagetk.LabelledImage) – Segmented image with cells in which to detect nuclei.

  • background_label (int) – Label corresponding to the background region.

  • radius_range (tuple, optional) – Range of nuclei size to detect.

  • step (float, optional) – Step of radius range.

Returns:

dict – Nuclei 3D position for each cell label, in physical XYZ coordinates.

timagetk.algorithms.peak_detection.gaussian_scale_space(image, sigmas)[source]

Apply the Gaussian scale space transform to an intensity image.

Parameters:
  • image (timagetk.SpatialImage) – Intensity image to transform.

  • sigmas (list) – Real unit sigma to use with Gaussian filter.

Returns:

numpy.ndarray – 4D array with scale as first dimension and filtered arrays on the 3 other.

Examples

>>> from timagetk.algorithms.peak_detection import gaussian_scale_space
>>> from timagetk.synthetic_data.nuclei_image import example_nuclei_image
>>> from timagetk.visu.mplt import grayscale_imshow
>>> nuclei_img = example_nuclei_image(n_points=10, extent=15., nuclei_radius=1.5, nuclei_intensity=10000, return_points=False)
>>> gss_img = gaussian_scale_space(nuclei_img, [0.5, 1, 1.5])
>>> # Let's display the detected nuclei as a 2D top-view projection:
>>> import matplotlib.pyplot as plt
>>> fig, axs = plt.subplots(1, 3)
>>> fig.set_size_inches(9, 3)
>>> axs[0].imshow(gss_img[0].max(axis=0), cmap='gray', extent=(0, nuclei_img.extent[2], nuclei_img.extent[1], 0))  # Add maximum intensity projection of the nuclei signal
>>> axs[1].imshow(gss_img[1].max(axis=0), cmap='gray', extent=(0, nuclei_img.extent[2], nuclei_img.extent[1], 0))  # Add maximum intensity projection of the nuclei signal
>>> axs[2].imshow(gss_img[2].max(axis=0), cmap='gray', extent=(0, nuclei_img.extent[2], nuclei_img.extent[1], 0))  # Add maximum intensity projection of the nuclei signal
>>> plt.suptitle("Example of Gaussian scale space transform on synthetic data")
>>> plt.show()
timagetk.algorithms.peak_detection.scale_space_transform(image, sigmas)[source]

Apply the scale space transform to an intensity image.

Parameters:
  • image (timagetk.SpatialImage) – Intensity image to transform.

  • sigmas (list of float) – List of scales used to generate the scale-space

Returns:

numpy.ndarray – 4D array with scale as first dimension and arrays on the 3 other.