seg_utils

CTSegNet is more than a 2D CNN model - it’s a 3D Segmenter that uses 2D CNNs. The set_utils.py defines the Segmenter class that wraps over a keras U-net-like model (defined by models.py), integrating 3D slicing and 2D patching functions to enable the 3D-2D-3D conversations in the segmentation workflow. To slice a 3D volume, manipulations such as 45 deg rotations, orthogonal slicing, patch extraction and stitching are performed.

ct_segnet.seg_utils.process_data(p, segmenter, preprocess_func=None, max_patches=None, overlap=None, nprocs=None, rot_angle=0.0, slice_axis=0, crops=None, arr_split=1, arr_split_infer=1)[source]

Segment a volume of shape (nz, ny, nx). The 2D keras model passes along either axis (0,1,2), segmenting images with a patch size defined by input to the model in the segmenter class.

Parameters
  • max_patches (tuple) – (my, mx) are # of patches along Y, X in image (ny, nx)

  • overlap (tuple or int) – number of overlapping pixels between patches

  • nprocs (int) – number of CPU processors for multiprocessing Pool

  • arr_split (int) – breakdown chunk into arr_split number of smaller chunks

  • slice_axis (int) – (0,1,2); axis along which to draw slices

cropslist

list of three tuples; each tuple (start, stop) will define a python slice for the respective axis

rot_anglefloat

(degrees) rotate volume around Z axis before slicing along any given axis. Note this is redundant if slice_axis = 0

nprocsint

number of CPU processors for multiprocessing Pool

arr_splitint

breakdown chunk into arr_split number of smaller chunks

preprocess_funfunc

pass a preprocessing function that applies a 2D filter on an image

class ct_segnet.seg_utils.Segmenter(model_filename=None, model=None, model_name='unknown', weight_file_name=None, GPU_mem_limit=16.0)[source]

The Segmenter class wraps over a keras model, integrating 3D slicing and 2D patching functions to enable the 3D-2D-3D conversations in the segmentation workflow.

model: tf.keras.model

keras model with input shape = out shape = (ny, nx, 1)

model_filenamestr

path to keras model file (e.g. “model_1.h5”)

model_namestr

(optional) just a name for the model

GPU_mem_limitfloat

max limit of GPU memory to use

seg_chunk(p, max_patches=None, overlap=None, nprocs=None, arr_split=1, arr_split_infer=1)[source]

Segment a volume of shape (nslices, ny, nx). The 2D keras model passes along nslices, segmenting images (ny, nx) with a patch size defined by input to the model

max_patches: tuple

(my, mx) are # of patches along Y, X in image (ny, nx)

overlaptuple or int

number of overlapping pixels between patches

nprocsint

number of CPU processors for multiprocessing Pool

arr_splitint

breakdown chunk into arr_split number of smaller chunks

seg_image(s, max_patches=None, overlap=None)[source]

Test the segmenter on arbitrary sized 2D image. This method extracts patches of shape same as the input shape of 2D CNN, segments them and stitches them back to form the original image.

max_patchestuple

(my, mx) are # of patches along Y, X in image

snumpy.array

greyscale image slice of shape (ny, nx)

overlaptuple or int

number of overlapping pixels between patches

class ct_segnet.seg_utils.FeatureExtraction2D(max_patches=None, overlap=None, model_filename=None)[source]

This class converts a 2D image into an n-dimensional vector z

Parameters

max_patches (tuple) – (my, mx) are # of patches along Y, X in image

overlaptuple or int

number of overlapping pixels between patches

model: tf.keras.model

keras model with input shape = out shape = (ny, nx, 1)

model_filenamestr

path to keras model file (e.g. “model_1.h5”)

model_namestr

(optional) just a name for the model

extract_code()[source]

not implemented

to do: consider patches are created. How should the code vectors of each patch be converted to singe vector? (mean, median, std?)

extract_measurement(img, measurement, **kwargs)[source]
Returns

measured_features (np.array) – shape (ndims,)

Parameters
  • img (np.array) – A 2D numpy array (ny,nx). Could be a tomo slice or projection.

  • measurement (func) – function to extract a measurement, e.g. radius, particle centroid, etc.

vis_feature(s, measurement, **kwargs)[source]

This method extracts patches of shape same as the input shape of 2D CNN, measures a feature for each patch’s segmentation map and stitches them back to form a checkered image.

snumpy.array

greyscale image slice of shape (ny, nx)