def __call__(self, raw): f = fastfilters.laplacianOfGaussian(raw, self.sigma) f -= self.mi f /= (self.ma - self.mi) return f[:, :, :, None]
def __init__(self, raw, sigma): self.sigma = sigma f = fastfilters.laplacianOfGaussian(raw, self.sigma) self.mi = numpy.min(f) self.ma = numpy.max(f) self.range = (self.ma - self.mi) / tolFactor self.mi -= self.range self.ma += self.range
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_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
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))) for sigma in sigmas: res_ff = ff.laplacianOfGaussian(a, sigma) res_vigra = vigra.filters.laplacianOfGaussian(a, sigma) 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) res_vigra = vigra.filters.structureTensorEigenvalues(a, sigma, sigma2) 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 filter_fn(self, source_raw: numpy.ndarray) -> numpy.ndarray: return fastfilters.laplacianOfGaussian(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.laplacianOfGaussian(source_raw, scale=self.scale, window_size=self.window_size)
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))) for sigma in sigmas: res_ff = ff.laplacianOfGaussian(a, sigma) res_vigra = vigra.filters.laplacianOfGaussian(a, sigma) 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) res_vigra = vigra.filters.structureTensorEigenvalues(a, sigma, sigma2) 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))):