Skip to content
Snippets Groups Projects
Select Git revision
  • 3f25c8ff9df13d0f6cce80582180eb3c88c951c4
  • master default protected
  • maufrais
  • amaury
  • v12.5.0
  • v12.4.0
  • v12.3.0
  • v12.2.0
  • v12.1.0
  • v12.0.0
  • v11.10.0
  • v11.9.0
  • v11.8.0
  • v11.7.0
  • v11.6
  • v11.5
  • v11.4.0
  • v11.3.0
  • v11.2.0
  • v11.1.0
  • v11.0.0
  • v10.9.0
  • v10.8.3
  • v10.8.2
24 results

check_dataset.t26_20201124.RData

Blame
  • Forked from Gael MILLOT / cute_little_R_functions
    Source project has a limited visibility.
    seg.py 1.33 KiB
    import matplotlib
    import logging
    from droplet_growth import multiwell
    
    matplotlib.logging.basicConfig(level=logging.INFO)
    logging.basicConfig(level=logging.DEBUG)
    
    logger = logging.getLogger(__name__)
    logger.setLevel(logging.INFO)
    
    
    def crop_center(array):
        shape = array.shape
        crop =  array[
            shape[0] // 4 : shape[0] * 3 // 4, shape[1] // 4 : shape[1] * 3 // 4,
        ]
        return crop
    
    
    def segment_bf(well, thr=0.2, smooth=10, erode=10, fill=True, plot=False):
        '''
        Serments input 2d array using thresholded gradient with filling
        Returns labels
        '''
        grad = multiwell.get_2d_gradient(well)
        sm = multiwell.gaussian_filter(grad, smooth)
    #     sm = multiwell.gaussian_filter(well, smooth)
        
        regions = sm > thr * sm.max()
        
        if fill:
            regions = multiwell.binary_fill_holes(regions)
        
        if erode:
            regions = multiwell.binary_erosion(regions, iterations=erode)
        
        labels, n_labels = multiwell.label(regions)
        print(f'{n_labels} region{" s"[n_labels>1]}')
        if plot:
            fig, ax = multiwell.plt.subplots(1,3)
            ax[0].imshow(well, cmap='gray')
            ax[0].set_title('input')
            ax[1].imshow(sm, cmap='gray')
            ax[1].set_title('grad')
            ax[2].imshow(labels)
            ax[2].set_title(f'{n_labels} labels')
            multiwell.plt.show()
            
        return labels