def watersheds(raw, sigma): edgeIndicator = ffilt.hessianOfGaussianEigenvalues(raw, sigma)[:,:,0] seg, nseg = vigra.analysis.watersheds(edgeIndicator) #seg -= 1 #vigra.segShow(raw, seg) #vigra.show() return seg,nseg
def watersheds(raw, sigma): edgeIndicator = ffilt.hessianOfGaussianEigenvalues(raw, sigma)[:, :, 0] seg, nseg = vigra.analysis.watersheds(edgeIndicator) #seg -= 1 #vigra.segShow(raw, seg) #vigra.show() return seg, nseg
def em_hmap(raw, sigma, sigma2=None, invert=True): """ This heightmap works well for 2d boundaries in EM. """ hmap = normalize_input(ff.gaussianGradientMagnitude(raw, sigma)) sigma2 = sigma if sigma2 is None else sigma2 hmap = ff.hessianOfGaussianEigenvalues(hmap, sigma2)[..., 0] hmap = update_hmap(raw, hmap, invert=invert) return hmap
def __call__(self, raw): f = fastfilters.hessianOfGaussianEigenvalues(raw, self.sigma) for c in range(3): fc = f[:, :, :, c] fc -= self.mi[c] fc /= (self.ma[c] - self.mi[c]) return f
def __init__(self, raw, sigma): self.sigma = sigma f = fastfilters.hessianOfGaussianEigenvalues(raw, self.sigma) self.mi = [numpy.min(f[:, :, :, c]) for c in range(3)] self.ma = [numpy.max(f[:, :, :, c]) for c in range(3)] self.range = [(ma - mi) / tolFactor for ma, mi in zip(self.ma, self.mi)] for c in range(3): self.mi[c] -= self.range[c] self.ma[c] += self.range[c]
def test_vigra_compare(): a = np.random.randn(1000000).reshape(1000,1000).astype(np.float32)[:,:900] a = np.ascontiguousarray(a) sigmas = [1.0, 5.0, 10.0] for order in [0,1,2]: for sigma in sigmas: res_ff = ff.gaussianDerivative(a, sigma, order, window_size=3.5) res_vigra = vigra.filters.gaussianDerivative(a, sigma, [order,order], window_size=3.5) print("gaussian ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.hessianOfGaussianEigenvalues(a, sigma, window_size=3.5) res_vigra = vigra.filters.hessianOfGaussianEigenvalues(a, sigma, window_size=3.5) print("HOG", sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6) or np.any(np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: HOG", sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.gaussianGradientMagnitude(a, sigma, window_size=3.5) res_vigra = vigra.filters.gaussianGradientMagnitude(a, sigma, window_size=3.5) print("gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.laplacianOfGaussian(a, sigma, window_size=3.5) res_vigra = vigra.filters.laplacianOfGaussian(a, sigma, window_size=3.5) print("laplacian2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: laplacian2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: for sigma2 in sigmas: res_ff = ff.structureTensorEigenvalues(a, sigma2, sigma, window_size=3.5) res_vigra = vigra.filters.structureTensorEigenvalues(a, sigma, sigma2, window_size=3.5) print("ST", sigma, sigma2, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6) or np.any(np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: ST", sigma, sigma2, np.max(np.abs(res_ff - res_vigra)))
def test_parallel_filter_channel(self): from ilastik.workflows.carving.carvingTools import parallel_filter name = 'hessianOfGaussianEigenvalues' shape = 3 * (128,) x = numpy.random.rand(*shape).astype('float32') sigma = 1.6 exp = fastfilters.hessianOfGaussianEigenvalues(x, sigma) for channel in range(3): res = parallel_filter(name, x, sigma, max_workers=4, return_channel=channel) assert numpy.allclose(res, exp[..., channel])
def test_vigra_compare3d(): a = np.random.randn(1000000).reshape(100,100,100).astype(np.float32)[:,:90,:80] a = np.ascontiguousarray(a) sigmas = [1.0, 5.0, 10.0] for order in [0,1,2]: for sigma in sigmas: res_ff = ff.gaussianDerivative(a, sigma, order) res_vigra = vigra.filters.gaussianDerivative(a, sigma, [order,order,order]) print("gaussian ", order, sigma, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.gaussianGradientMagnitude(a, sigma) res_vigra = vigra.filters.gaussianGradientMagnitude(a, sigma) print("gradmag3d ", order, sigma, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: gradmag3d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.laplacianOfGaussian(a, sigma) res_vigra = vigra.filters.laplacianOfGaussian(a, sigma) print("laplacian3d ", order, sigma, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: laplacian3d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.hessianOfGaussianEigenvalues(a, sigma) res_vigra = vigra.filters.hessianOfGaussianEigenvalues(a, sigma) print("HOG", sigma, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) if np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra) > 1e-6 or np.any(np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: HOG", sigma, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) for sigma in sigmas: for sigma2 in sigmas: res_ff = ff.structureTensorEigenvalues(a, sigma2, sigma) res_vigra = vigra.filters.structureTensorEigenvalues(a, sigma, sigma2) print("ST", sigma, sigma2, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra)) if np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra) > 1e-5 or np.any(np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: ST", sigma, sigma2, np.max(np.abs(res_ff - res_vigra)), np.sum(np.abs(res_ff-res_vigra))/np.size(res_vigra))
def __call__(self, dataIn, slicing, featureArray): fIndex = 0 dataIn = numpy.require(dataIn,'float32').squeeze() dataWithChannel = extractChannels(dataIn, self.usedChannels) slicingEv = slicing + [slice(0,2)] for c in range(dataWithChannel.shape[2]): data = dataWithChannel[:,:,c] # pre-smoothed sigmaPre = self.sigmas[0]/2.0 preS = fastfilters.gaussianSmoothing(data, sigmaPre) for sigma in self.sigmas: neededScale = getScale(target=sigma, presmoothed=sigmaPre) preS = fastfilters.gaussianSmoothing(preS, neededScale) sigmaPre = sigma featureArray[:,:,fIndex] = preS[slicing] fIndex += 1 featureArray[:,:,fIndex] = fastfilters.laplacianOfGaussian(preS, neededScale)[slicing] fIndex += 1 featureArray[:,:,fIndex] = fastfilters.gaussianGradientMagnitude(preS, neededScale)[slicing] fIndex += 1 featureArray[:,:,fIndex:fIndex+2] = fastfilters.hessianOfGaussianEigenvalues(preS, neededScale)[slicingEv] fIndex += 2 #print("array shape",featureArray[:,:,:,fIndex:fIndex+3].shape) feat = fastfilters.structureTensorEigenvalues(preS, float(sigma)*0.3, float(sigma)*0.7)[slicingEv] #print("feat shape",feat.shape) featureArray[:,:,fIndex:fIndex+2] = feat fIndex += 2 assert fIndex == self.n_features
sigmas = [1.0, 5.0, 10.0] for order in [0,1,2]: for sigma in sigmas: res_ff = ff.gaussian2d(a, order, sigma) res_vigra = vigra.filters.gaussianDerivative(a, sigma, [order,order]) print("gaussian ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.hessianOfGaussianEigenvalues(a, sigma) res_vigra = vigra.filters.hessianOfGaussianEigenvalues(a, sigma) print("HOG", sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6) or np.any(np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: HOG", sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.gaussianGradientMagnitude(a, sigma) res_vigra = vigra.filters.gaussianGradientMagnitude(a, sigma) print("gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra)))
def filter_fn(self, source_raw: numpy.ndarray) -> numpy.ndarray: return fastfilters.hessianOfGaussianEigenvalues( source_raw, scale=self.scale, window_size=self.window_size)
def filter_fn( self, source_raw: "ndarray[Any, dtype[float32]]" ) -> "ndarray[Any, dtype[float32]]": return fastfilters.hessianOfGaussianEigenvalues( source_raw, scale=self.scale, window_size=self.window_size)
sigmas = [1.0, 5.0, 10.0] for order in [0, 1, 2]: for sigma in sigmas: res_ff = ff.gaussian2d(a, order, sigma) res_vigra = vigra.filters.gaussianDerivative(a, sigma, [order, order]) print("gaussian ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: ", order, sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.hessianOfGaussianEigenvalues(a, sigma) res_vigra = vigra.filters.hessianOfGaussianEigenvalues(a, sigma) print("HOG", sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6) or np.any( np.isnan(np.abs(res_ff - res_vigra))): raise Exception("FAIL: HOG", sigma, np.max(np.abs(res_ff - res_vigra))) for sigma in sigmas: res_ff = ff.gaussianGradientMagnitude(a, sigma) res_vigra = vigra.filters.gaussianGradientMagnitude(a, sigma) print("gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra))) if not np.allclose(res_ff, res_vigra, atol=1e-6): raise Exception("FAIL: gradmag2d ", order, sigma, np.max(np.abs(res_ff - res_vigra)))