示例#1
0
    def test_tile_resizer(self):
        from flowdec import data as fd_data
        image = fd_data.bars_25pct().data.astype(np.uint16)
        tile = image[np.newaxis, :, np.newaxis, ...]
        self.assertTrue(tile.ndim == 5,
                        'Expecting 5D shape but got {}'.format(tile.shape))
        config = cytokit_simulation.get_example_config(example_name='ex1')

        # Equate resolution to do fair comparison between anisotropic skimage resize
        # and tensorflow isotropic resize
        config._conf['acquisition']['axial_resolution'] = 1.
        config._conf['acquisition']['lateral_resolution'] = 1.

        # Set resizing factors and implementation to ensure the operation will run
        config._conf['processor']['tile_resize']['factors'] = [.75, .75, .75]
        config._conf['processor']['tile_resize']['implementation'] = 'skimage'
        resizer = tile_resize.CytokitTileResize(config).initialize()
        sk_res = resizer.run(tile)[0, :, 0]
        self.assertTrue(sk_res.ndim == 3,
                        'Expecting 3D shape but got {}'.format(sk_res.shape))

        # Run again using tensorflow implementation
        config._conf['processor']['tile_resize'][
            'implementation'] = 'tensorflow'
        resizer = tile_resize.CytokitTileResize(config).initialize()
        tf_res = resizer.run(tile)[0, :, 0]
        self.assertTrue(tf_res.ndim == 3,
                        'Expecting 3D shape but got {}'.format(tf_res.shape))

        # Ensure that differences are both minor and present to such a degree that
        # the same implementation was not used for comparison
        ssim = compare_ssim(sk_res, tf_res)
        self.assertTrue(.99 <= ssim < 1,
                        'Expecting SSIM in [.99, 1) but got {}'.format(ssim))
示例#2
0
    def test_observer(self):
        acq = fd_data.bars_25pct()
        imgs = []

        def observer(img, *_):
            imgs.append(img)
            self.assertEqual(acq.data.shape, img.shape, msg='Observer image and original shapes not equal')
        algo = fd_restoration.RichardsonLucyDeconvolver(n_dims=3, observer_fn=observer).initialize()
        algo.run(acq, niter=5)
        self.assertEqual(len(imgs), 5)
示例#3
0
def run_deconvolution(device):
    import os
    import tensorflow as tf
    config = tf.ConfigProto()
    config.gpu_options.allow_growth = True
    config.gpu_options.visible_device_list = device
    #acq = fd_data.load_celegans_channel('CY3')

    for i in range(10):
        acq = fd_data.bars_25pct()
        algo = fd_restoration.RichardsonLucyDeconvolver(3).initialize()
        res = algo.run(acq, niter=50, session_config=config).data
        time.sleep(5)
    return res
示例#4
0
    def test_bars(self):
        """Test reconstruction of blurred "Hollow Bars" volume"""
        n_iter = 10
        thresholds = {
            # Results should always improve on the original
            'original': 1.,

            # Results should also be better than DL2 and scikit-image most of the time
            'sk': .75,
            'dl2': .75 if dl2_enabled() else None
        }

        acq = fd_data.bars_25pct()

        # Initialize list of acquisitions to deconvolve
        acqs = [acq]

        # Add translations to images and kernels to ensure that there aren't
        # any issues supporting non-symmetric inputs
        acqs += [
            tfv.reblur(tfv.shift(acq, data_shift=(0, 10, 10))),
            tfv.reblur(tfv.shift(acq, data_shift=(0, -10, -10))),
            tfv.reblur(tfv.shift(acq, kern_shift=(0, 10, 10))),
            tfv.reblur(tfv.shift(acq, kern_shift=(0, -10, -10))),
            tfv.reblur(
                tfv.shift(acq, data_shift=(-3, 5, -5), kern_shift=(-3, 5, -5)))
        ]

        # Subset image and kernel to make sure that padding of inputs for fft is added
        # and then cropped out correctly (tests asymmetries and non-power-of-2 dimensions)
        acqs += [
            tfv.reblur(
                tfv.subset(acq,
                           kern_slice=[
                               slice(None, 24),
                               slice(None, 48),
                               slice(None, 48)
                           ])),
        ]

        # Validate that downsampling the original volume also causes no issues
        acqs += [
            tfv.reblur(tfv.downsample(acq, data_factor=.8, kern_factor=.4)),
            tfv.reblur(tfv.downsample(acq, data_factor=.5, kern_factor=.5))
        ]

        self._validate_restoration(acqs, n_iter, thresholds=thresholds)
示例#5
0
    def test_bars(self):
        """Test reconstruction of blurred "Hollow Bars" volume"""
        n_iter = 10
        thresholds = {
            # Results should always improve on the original
            'original': 1.0,
            'dl2': .75 if dl2_enabled() else None
        }

        acq = fd_data.bars_25pct()
        self.assertTrue(acq.data.shape == acq.kernel.shape == (32, 64, 64))
        # shape: {'actual': (32, 64, 64), 'kernel': (32, 64, 64), 'data': (32, 64, 64)}

        # Initialize list of acquisitions to deconvolve
        acqs = [acq]

        # Slice to give shape with odd dimensions as this is a better test of padding features
        acq_slice = [slice(2, 29), slice(None, 57), slice(None, 57)]
        acq = tfv.subset(acq, data_slice=acq_slice, kern_slice=acq_slice)
        # shape: {'data': (27, 57, 57), 'actual': (27, 57, 57), 'kernel': (27, 57, 57)}
        acqs += [acq]

        # Add translations to images and kernels to ensure that there aren't
        # any issues supporting non-symmetric inputs
        acqs += [
            tfv.reblur(tfv.shift(acq, data_shift=(0, 4, 4))),
            tfv.reblur(tfv.shift(acq, data_shift=(0, -4, -4))),
            tfv.reblur(tfv.shift(acq, kern_shift=(0, 4, 4))),
            tfv.reblur(tfv.shift(acq, kern_shift=(0, -4, -4))),
            tfv.reblur(
                tfv.shift(acq, data_shift=(-3, 5, -5), kern_shift=(-3, 5, -5)))
        ]

        # Validate that downsampling the original volume also causes no issues
        acqs += [
            tfv.reblur(tfv.downsample(acq, data_factor=.8, kern_factor=.4)),
            tfv.reblur(tfv.downsample(acq, data_factor=.5, kern_factor=.5))
        ]

        self._validate_restoration(acqs,
                                   n_iter,
                                   thresholds=thresholds,
                                   dtype=np.uint16)
示例#6
0
def load_simulated_bars_experiment(blur=False):
    ref_img = fd_data.bars_25pct().data if blur else fd_data.bars_25pct().actual
    # Subset image to not be equal in x and y
    ref_img = ref_img[:, :48, :]
    return experiment_from_img(ref_img)