Ejemplo n.º 1
0
    def run(self, ips, imgs, para=None):
        from cellpose import models, utils
        from cellpose.plot import mask_overlay

        use_GPU = models.use_gpu()

        if not para['slice']: imgs = [ips.img]
        imgs = [i.reshape((i.shape + (-1, ))[:3]) for i in imgs]

        model = models.Cellpose(gpu=use_GPU, model_type=para['model'])
        channels = [para['cytoplasm'], para['nucleus']]
        self.setValue = lambda x: self.progress(x, 100)
        masks, flows, styles, diams = model.eval(imgs,
                                                 diameter=para['diameter'],
                                                 rescale=None,
                                                 channels=channels,
                                                 progress=self)
        self.app.show_img(masks, ips.title + '-cp_mask')
        if para['flow']:
            self.app.show_img([i[0] for i in flows], ips.title + '-cp_flow')
        if para['overlay']:
            for i in range(len(imgs)):
                maski = masks[i].copy().astype(np.uint8)
                imgi = imgs[i].copy()
                overlayi = mask_overlay(imgi, maski)
                self.app.show_img([overlayi], ips.title + '-overlay')
        if para['diams']:
            self.app.show_table(pd.DataFrame({'diams': diams}),
                                ips.title + '-cp_diams')
 def do_check_gpu(self):
     import importlib.util
     torch_installed = importlib.util.find_spec('torch') is not None
     if models.use_gpu(istorch=torch_installed):
         message = "GPU appears to be working correctly!"
     else:
         message = "GPU test failed. There may be something wrong with your configuration."
     import wx
     wx.MessageBox(message, caption="GPU Test")
Ejemplo n.º 3
0
    mask = lut[lab].ravel()[rst].reshape(shp)
    return hist, lut[lab], mask

if __name__ == '__main__':
    from skimage.io import imread, imsave
    from skimage.data import coins, gravel
    from skimage.segmentation import find_boundaries
    
    import matplotlib.pyplot as plt
    from time import time

    import cellpose
    from cellpose import models, utils

    img = gravel()
    use_GPU = models.use_gpu()
    model = models.Cellpose(gpu=use_GPU, model_type='cyto')
    channels = [0, 0]
    mask, flow, style, diam = model.eval(
        img, diameter=30, rescale=None, channels=[0,0])
    start = time()
    water, core, msk = flow2msk(flow[1].transpose(1,2,0), None, 1.0, 20, 100)
    print('flow to mask cost:', time()-start)
    ax1, ax2, ax3, ax4, ax5, ax6 =\
        [plt.subplot(230+i) for i in (1,2,3,4,5,6)]
    ax1.imshow(img)
    ax2.imshow(flow[0])
    ax3.imshow(np.log(water+1))
    ax4.imshow(core)
    ax5.imshow(msk)
    ax6.imshow(~find_boundaries(msk)*img)
Ejemplo n.º 4
0
def test_gpu_check():
    from cellpose import models
    models.use_gpu()