def _decon_shape(self, data, kernel): # Apply blur to original shape and run restoration on blurred image acq = fd_data.Acquisition(data=data, kernel=kernel, actual=data) acq = tfv.reblur(acq, scale=.001) # Add low amount of noise res = tfv.decon_tf(acq, 10, real_domain_fft=False) # Binarize resulting image and validate that pixels match original exactly bin_res = (res > res.mean()).astype(np.int64) bin_tru = acq.actual.astype(np.int64) return bin_res, bin_tru
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)
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)