ct_segnet/seg_utils.py
def seg_image(self, p, max_patches = None, overlap = None):

        """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
        """
        # Handle patching parameter inputs
        patch_size = self.model.output_shape[1:-1]    
        if type(max_patches) is not tuple:
            max_patches = (max_patches, max_patches)
            
        if type(overlap) is not tuple:
            overlap = (overlap, overlap)
        overlap = (0 if max_patches[0] == 1 else overlap[0],\
                   0 if max_patches[1] == 1 else overlap[1])
    
        # Resize images
        orig_shape = p.shape
        p = cv2.resize(p, (max_patches[1]*patch_size[1] - overlap[1],\
                           max_patches[0]*patch_size[0] - overlap[0]))
        
        # Make patches
        downres_shape = p.shape
        steps = PM.get_stepsize(downres_shape, patch_size)
        p = PM.get_patches(p, patch_size = patch_size, steps = steps)
        
        # The dataset now has shape: (ny, nx, py, px). ny, nx are # of patches, and py, px is patch_shape.
        # Reshape this dataset into (n, py, px) where n = ny*nx. Trust numpy to preserve order. lol.
        dataset_shape = p.shape
        p = p.reshape((-1,) + patch_size)
        
        # Predict using the model.
        p = self.model.predict(p[...,np.newaxis])
        p = p[...,0]
        
        # Now, reshape the data back...
        p = p.reshape(dataset_shape)
        
        
        # Reconstruct from patches...
        p = PM.recon_patches(p, img_shape = downres_shape, steps = steps)
        
        # Finally, resize the images to the original shape of slices... This will result in some loss of resolution...
        p = cv2.resize(p, (orig_shape[1], orig_shape[0]))

        # outputs: segmented image of same shape as input image p
        return np.asarray(np.round(p)).astype(np.uint8)
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
        
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
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
def seg_image(self, p, max_patches = None, overlap = None):
        patch_size = self.model.output_shape[1:-1]    
        if type(max_patches) is not tuple:
            max_patches = (max_patches, max_patches)
        if type(overlap) is not tuple:
            overlap = (overlap, overlap)
        overlap = (0 if max_patches[0] == 1 else overlap[0],\
                   0 if max_patches[1] == 1 else overlap[1])
        orig_shape = p.shape
        p = cv2.resize(p, (max_patches[1]*patch_size[1] - overlap[1],\
                           max_patches[0]*patch_size[0] - overlap[0]))
        downres_shape = p.shape
        steps = PM.get_stepsize(downres_shape, patch_size)
        p = PM.get_patches(p, patch_size = patch_size, steps = steps)
        dataset_shape = p.shape
        p = p.reshape((-1,) + patch_size)
        p = self.model.predict(p[...,np.newaxis])
        p = p[...,0]
        p = p.reshape(dataset_shape)
        p = PM.recon_patches(p, img_shape = downres_shape, steps = steps)
        p = cv2.resize(p, (orig_shape[1], orig_shape[0]))
        return np.asarray(np.round(p)).astype(np.uint8)
def seg_image ( self , p , max_patches = None , overlap = None ) : patch_size = self . model . output_shape [ 1 : - 1 ] if type ( max_patches ) is not tuple : max_patches = ( max_patches , max_patches ) if type ( overlap ) is not tuple : overlap = ( overlap , overlap ) overlap = ( 0 if max_patches [ 0 ] == 1 else overlap [ 0 ] , 0 if max_patches [ 1 ] == 1 else overlap [ 1 ] ) orig_shape = p . shape p = cv2 . resize ( p , ( max_patches [ 1 ] * patch_size [ 1 ] - overlap [ 1 ] , max_patches [ 0 ] * patch_size [ 0 ] - overlap [ 0 ] ) ) downres_shape = p . shape steps = PM . get_stepsize ( downres_shape , patch_size ) p = PM . get_patches ( p , patch_size = patch_size , steps = steps ) dataset_shape = p . shape p = p . reshape ( ( - 1 , ) + patch_size ) p = self . model . predict ( p [ ... , np . newaxis ] ) p = p [ ... , 0 ] p = p . reshape ( dataset_shape ) p = PM . recon_patches ( p , img_shape = downres_shape , steps = steps ) p = cv2 . resize ( p , ( orig_shape [ 1 ] , orig_shape [ 0 ] ) ) return np . asarray ( np . round ( p ) ) . astype ( np . uint8 )
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
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
"""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
        """ # Handle patching parameter inputs # Resize images # Make patches # The dataset now has shape: (ny, nx, py, px). ny, nx are # of patches, and py, px is patch_shape. # Reshape this dataset into (n, py, px) where n = ny*nx. Trust numpy to preserve order. lol. # Predict using the model. # Now, reshape the data back... # Reconstruct from patches... # Finally, resize the images to the original shape of slices... This will result in some loss of resolution... # outputs: segmented image of same shape as input image p
self
p
max_patches
overlap