ct_segnet/seg_utils.py
def 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):
    """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
    """
    if nprocs is None:
        nprocs = 4
    if p.ndim != 3:
        raise ValueError("Invalid dimensions for 3D data.")

    message("Orienting, rotating and padding as requested...")
    # Rotate the volume along axis 0, if requested
    if rot_angle > 0.0:
        p = _rotate(p, rot_angle)
    
    if crops is not None:
        pads = get_repadding(crops, p.shape)
        p = p[slice(*crops[0]), slice(*crops[1]), slice(*crops[2])]

    # Orient the volume such that the first axis is the direction in which to slice through...
    p = np.moveaxis(p, slice_axis, 0)
    message("\tDone")

    # Preprocess function
    if preprocess_func is not None:
        print("\tPreprocessing on XY mapping...")
        p = preprocess_func(p)

    # Run the segmenter algorithm
    p = segmenter.seg_chunk(p, max_patches = max_patches, overlap = overlap, nprocs = nprocs, arr_split = arr_split)


    message("Re-orienting, rotating and padding back original size...")
    # Re-orient the volume such that the first axis is the vertical axis...
    p = np.moveaxis(p, 0, slice_axis)
    

    # Pad the volume to bring it back to original dimensions
    if crops is not None:
        p = np.pad(p, pads, 'constant', constant_values = 0)
    
    # Rotate the volume along axis 0, back to its original state
    if rot_angle > 0.0:
        p = _rotate(p, -rot_angle)
    message("\tDone")
    
    return p.astype(np.uint8)
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
    
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.

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
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 . 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
def 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):
    if nprocs is None:
        nprocs = 4
    if p.ndim != 3:
        raise ValueError("Invalid dimensions for 3D data.")
    message("Orienting, rotating and padding as requested...")
    if rot_angle > 0.0:
        p = _rotate(p, rot_angle)
    if crops is not None:
        pads = get_repadding(crops, p.shape)
        p = p[slice(*crops[0]), slice(*crops[1]), slice(*crops[2])]
    p = np.moveaxis(p, slice_axis, 0)
    message("\tDone")
    if preprocess_func is not None:
        print("\tPreprocessing on XY mapping...")
        p = preprocess_func(p)
    p = segmenter.seg_chunk(p, max_patches = max_patches, overlap = overlap, nprocs = nprocs, arr_split = arr_split)
    message("Re-orienting, rotating and padding back original size...")
    p = np.moveaxis(p, 0, slice_axis)
    if crops is not None:
        p = np.pad(p, pads, 'constant', constant_values = 0)
    if rot_angle > 0.0:
        p = _rotate(p, -rot_angle)
    message("\tDone")
    return p.astype(np.uint8)
def 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 ) : if nprocs is None : nprocs = 4 if p . ndim != 3 : raise ValueError ( "Invalid dimensions for 3D data." ) message ( "Orienting, rotating and padding as requested..." ) if rot_angle > 0.0 : p = _rotate ( p , rot_angle ) if crops is not None : pads = get_repadding ( crops , p . shape ) p = p [ slice ( * crops [ 0 ] ) , slice ( * crops [ 1 ] ) , slice ( * crops [ 2 ] ) ] p = np . moveaxis ( p , slice_axis , 0 ) message ( "\tDone" ) if preprocess_func is not None : print ( "\tPreprocessing on XY mapping..." ) p = preprocess_func ( p ) p = segmenter . seg_chunk ( p , max_patches = max_patches , overlap = overlap , nprocs = nprocs , arr_split = arr_split ) message ( "Re-orienting, rotating and padding back original size..." ) p = np . moveaxis ( p , 0 , slice_axis ) if crops is not None : p = np . pad ( p , pads , 'constant' , constant_values = 0 ) if rot_angle > 0.0 : p = _rotate ( p , - rot_angle ) message ( "\tDone" ) return p . astype ( np . uint8 )
Segment a volume of shape (nz, ny, nx).
Segment a volume of shape ( nz ny nx ) .
"""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
    """ # Rotate the volume along axis 0, if requested # Orient the volume such that the first axis is the direction in which to slice through... # Preprocess function # Run the segmenter algorithm # Re-orient the volume such that the first axis is the vertical axis... # Pad the volume to bring it back to original dimensions # Rotate the volume along axis 0, back to its original state
p
segmenter
preprocess_func
max_patches
overlap
nprocs
rot_angle
slice_axis
crops
arr_split