Images#

thetan.image

Helpers that turn images and volumes into feature rows that the clustering functions accept, and post-process segmentations. Compiled with Cython.

thetan.image.connected_components(image, delta=0.0)#

Perform 3D connected component labeling using 26-connectivity.

Parameters:

image (3D np.ndarray): Input image (binary or grayscale). delta (float): Intensity difference threshold for merging components.

Returns:

labels (3D np.ndarray[intp]): Labeled image with unique components. num_components (int): Total number of connected components.

thetan.image.correct_connectivity(segments, min_size, max_size, start_label=1)#

Helper function to remove small disconnected regions from the labels

Parameters:
segments3D array of int, shape (Z, Y, X)

The label field/superpixels found by SLIC.

min_sizeint

The minimum size of the segment

max_sizeint

The maximum size of the segment. This is done for performance reasons, to pre-allocate a sufficiently large array for the breadth first search

start_labelint

The label indexing start value.

Returns:
connected_segments3D array of int, shape (Z, Y, X)

A label field with connected labels starting at label=1

thetan.image.img2d_to_ijv_color(img2d)#

Turn a colour image into one (i, j, c0, c1, c2) row per pixel.

Parameters:
img2dndarray of float64, shape (I, J, C)

C-contiguous image with at least three channels. Only the first three channels are used.

Returns:
featuresndarray of float64, shape (I * J, 5)

Row index, column index and the three channel values of each pixel, in row-major order.

thetan.image.img2d_to_ijv_features(img2d)#

Turn a grayscale image into one (i, j, value) row per pixel.

Parameters:
img2dndarray of float64, shape (I, J)

C-contiguous grayscale image.

Returns:
featuresndarray of float64, shape (I * J, 3)

Row index, column index and intensity of each pixel, in row-major order.

thetan.image.img3d_integrals(img3d, out, radius=20)#

Sum a volume over a cubic window around each voxel.

For each voxel at least radius voxels away from every border, adds the sum of img3d over the cube of side 2 * radius + 1 centred on it to out. Voxels closer to a border are left untouched.

Parameters:
img3dndarray of float64, shape (I, J, K)

C-contiguous input volume.

outndarray of float64, shape (I, J, K)

C-contiguous output volume, updated in place. The sums are added to its values, so pass an array of zeros to get the sums alone.

radiusint, optional

Half side of the cubic window, in voxels.

Returns:
int

Always 1. The result is written to out.

Notes

The window is summed directly, so the cost is O(I J K radius^3).

thetan.image.img3d_to_ijkv_features(img3d)#

Turn a volume into one (i, j, k, value) row per voxel.

Parameters:
img3dndarray of float64, shape (I, J, K)

C-contiguous volume.

Returns:
featuresndarray of float64, shape (I * J * K, 4)

The three voxel indices and the intensity of each voxel, in row-major order.