ct_segnet.seg_utils

Created on Sat Nov 16 17:13:22 2019

@author: atekawade

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, we manipulations such as 45 deg rotations, orthogonal slicing, patch extraction and stitching.

Functions:

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

Bases: object

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.

seg_chunk(p, max_patches=None, overlap=None, nprocs=None, arr_split=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) overlap : tuple or int, number of overlapping pixels between patches nprocs : number of CPU processors for multiprocessing Pool arr_split : breakdown chunk into arr_split number of smaller chunks

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

function to test the segmenter on arbitrary sized 2D image; extracts patches shape = input shape of 2D CNN max_patches : tuple, (my, mx) are # of patches along Y, X in image p : greyscale image of shape (ny, nx) overlap : tuple or int, number of overlapping pixels between patches

ct_segnet.seg_utils.get_repadding(crops, d_shape)[source]

Returns padding values to restore 3D np array after it was cropped. crops : 3 tuples in a list [(nz1,nz2), (ny1,ny2), (nx1,nx2)] d_shape : original shape of 3D array

ct_segnet.seg_utils.message(_str)[source]
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)[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. max_patches : tuple, (?,?) number of patches along each axis of 2D image overlap : tuple or int, number of overlapping pixels between patches slice_axis : int (0,1,2); axis along which to draw slices crops : list of three tuples; each tuple (start, stop) will

define a python slice for the respective axis
rot_angle : rotate volume around Z axis before slicing along any given axis.
Note this is redundant if slice_axis = 0

nprocs : number of CPU processors for multiprocessing Pool arr_split : breakdown chunk into arr_split number of smaller chunks preprocess_func : pass a preprocessing function that applies a 2D filter on an image