def largeSeedWatershed(raw, pmap, seeds, membraneWidth = 7.0, visu=False): blockShape = (100, )*3 cOpts = vbw.convOpts pmap = numpy.require(pmap, dtype='float32') with vigra.Timer("add noise"): mx = pmap.max() sshape = pmap.squeeze().shape noise = numpy.random.rand(*sshape)*(0.05*mx) noise = vigra.taggedView(noise.astype('float32'),'xyz') opts = vbw.convOpts(blockShape=blockShape, sigma=4.0) noise = vbw.gaussianSmooth(noise, options=opts) pmap += noise with vigra.Timer("smoothed tie breaker"): # compute a smoothed map as tie breaker opts = vbw.convOpts(blockShape=blockShape, sigma=membraneWidth/2.0) gaussianSmoothedPmap = vbw.gaussianSmooth(pmap, options=opts) addEps = 0.3 growingMap = gaussianSmoothedPmap growingMap *= addEps # opts = vbw.convOpts(blockShape=blockShape, sigma=membraneWidth/7.50) notSoMuch = vbw.gaussianSmooth(pmap, options=opts) # get the actual growing mapz growingMap += notSoMuch growingMap /= 1.0 + addEps with vigra.Timer("watershedsNew"): # do the actual watershed growingMap = vigra.taggedView(growingMap, 'xyz') seeds = numpy.require(seeds, dtype='uint32') seeds = vigra.taggedView(seeds, 'xyz') seg,nSeg = vigra.analysis.watershedsNew(image=growingMap, seeds=seeds) if visu: grayData = [ (raw, "raw"), (pmap,"pmap"), (growingMap,"growingMap") ] segData = [ (seeds, "seeds"), (seg, "seg") ] skneuro.addHocViewer(grayData, segData) return seg,nSeg
def largeSeedWatershed(raw, pmap, seeds, membraneWidth=7.0, visu=False): blockShape = (100, ) * 3 cOpts = vbw.convOpts pmap = numpy.require(pmap, dtype='float32') with vigra.Timer("add noise"): mx = pmap.max() sshape = pmap.squeeze().shape noise = numpy.random.rand(*sshape) * (0.05 * mx) noise = vigra.taggedView(noise.astype('float32'), 'xyz') opts = vbw.convOpts(blockShape=blockShape, sigma=4.0) noise = vbw.gaussianSmooth(noise, options=opts) pmap += noise with vigra.Timer("smoothed tie breaker"): # compute a smoothed map as tie breaker opts = vbw.convOpts(blockShape=blockShape, sigma=membraneWidth / 2.0) gaussianSmoothedPmap = vbw.gaussianSmooth(pmap, options=opts) addEps = 0.3 growingMap = gaussianSmoothedPmap growingMap *= addEps # opts = vbw.convOpts(blockShape=blockShape, sigma=membraneWidth / 7.50) notSoMuch = vbw.gaussianSmooth(pmap, options=opts) # get the actual growing mapz growingMap += notSoMuch growingMap /= 1.0 + addEps with vigra.Timer("watershedsNew"): # do the actual watershed growingMap = vigra.taggedView(growingMap, 'xyz') seeds = numpy.require(seeds, dtype='uint32') seeds = vigra.taggedView(seeds, 'xyz') seg, nSeg = vigra.analysis.watershedsNew(image=growingMap, seeds=seeds) if visu: grayData = [(raw, "raw"), (pmap, "pmap"), (growingMap, "growingMap")] segData = [(seeds, "seeds"), (seg, "seg")] skneuro.addHocViewer(grayData, segData) return seg, nSeg
from vigra import blockwise as bw numpy.random.seed(42) # input shape = (500, 500, 500) data = numpy.random.rand(*shape).astype('float32') print "make options object" options = bw.BlockwiseConvolutionOptions3D() print type(options) sigma = 1.0 options.stdDev = (sigma, )*3 options.blockShape = (128, )*3 print "stddev",options.stdDev print "call blockwise filter" with vigra.Timer("AllThread"): res = bw.gaussianSmooth(data, options) with vigra.Timer("1thread"): resRef = vigra.gaussianSmoothing(data, sigma) print numpy.sum(numpy.abs(res-resRef))
def onClickedComputeFeaturesImpl(self, param): lCtrl = self.layerCtrl extractor = self.featureExtractor rawData = self.dataDict['raw'] print "compute features" print param options = bw.BlockwiseConvolutionOptions3D() options.blockShape = (128, )*3 fSize = [0] def fRange(feat): old = long(fSize[0]) fSize[0] += feat.shape[1] return (old, fSize[0]) geoFeat,geoFeatNames = extractor.geometricFeatures() lCtrl.addFeature("GeometricFeature",fRange(geoFeat),subNames=geoFeatNames) topoFeat, topoFeatNames = extractor.topologicalFeatures() lCtrl.addFeature("TopologicalFeatures",fRange(topoFeat),subNames=topoFeatNames) features = [geoFeat, topoFeat] for order in range(3): orderName = '%d-Order Filter'%order doFilter = param[('RawData',orderName,'computeFilter')] if(doFilter): sigmas = param[('RawData',orderName,'sigma')] sigmas = list(eval(sigmas)) doUcm = param[('RawData',orderName,'UCM','ucmFilters')] ucmMeanSign = float(param[('RawData',orderName,'UCM','meanSign')]) print "ucmMeanSign",ucmMeanSign print "doUcm",doUcm wardness = param[('RawData',orderName,'UCM','wardness')] wardness = list(eval(wardness)) wardness = numpy.array(wardness, dtype='float32') wnames =[] for w in wardness : wnames.append(" w"+str(w)) wnames.append(" r"+str(w)) print "sigma",sigmas, "w",wardness for sigma in sigmas: print sigma orderSigmaName = orderName + str(sigma) options.stdDev = (float(sigma), )*3 if order == 0: if sigma < 0.01: res = rawData else: res = bw.gaussianSmooth(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature(orderSigmaName,fRange(accFeat),subNames=accFeatNames) features.append(accFeat) if doUcm : mean = accFeat[:,0] mean *= ucmMeanSign ucmName = orderSigmaName+"MeanUcm" ucm = extractor.ucmTransformFeatures(mean[:,None], wardness) lCtrl.addFeature(ucmName,fRange(ucm),subNames=wnames) features.append(ucm) if order == 1 : if sigma < 0.5: continue else: res = bw.gaussianGradientMagnitude(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature(orderSigmaName,fRange(accFeat),subNames=accFeatNames) features.append(accFeat) if doUcm : mean = accFeat[:,0] print "ucmMeanSign",ucmMeanSign mean *= ucmMeanSign ucmName = orderSigmaName+"MeanUcm" ucm = extractor.ucmTransformFeatures(mean[:,None], wardness) lCtrl.addFeature(ucmName,fRange(ucm),subNames=wnames) features.append(ucm) if order == 2 : if sigma < 0.5: continue else: res = bw.hessianOfGaussianFirstEigenvalue(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature(orderSigmaName,fRange(accFeat),subNames=accFeatNames) features.append(accFeat) if doUcm : mean = accFeat[:,0] mean *= ucmMeanSign ucmName = orderSigmaName+"MeanUcm" ucm = extractor.ucmTransformFeatures(mean[:,None], wardness) lCtrl.addFeature(ucmName,fRange(ucm),subNames=wnames) features.append(ucm) if False: for s in [2.0]: options.stdDev = (s, )*3 res = bw.gaussianSmooth(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature("RawGaussianSmooth",fRange(accFeat),subNames=accFeatNames) features.append(accFeat) # 6 wardness = numpy.array([0.0, 0.1, 0.15, 0.25, 0.5, 1.0], dtype='float32') wnames =[] for w in wardness : wnames.append(" w"+str(w)) wnames.append(" r"+str(w)) for s in [2.0]: options.stdDev = (s, )*3 res = bw.hessianOfGaussianFirstEigenvalue(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature("hessianOfGaussianFirstEigenvalue",fRange(accFeat),subNames=accFeatNames) features.append(accFeat) print "ucm" mean = accFeat[:,0] ucm = extractor.ucmTransformFeatures(mean[:,None], wardness) print "ucm done" lCtrl.addFeature("hessianMeanUcm",fRange(ucm),subNames=wnames) features.append(ucm) #for s in [1.0, 3.0, 4.0]: # img = hessianEv2(rawData, s, 2.0) # #vigra.imshow(img) # #vigra.show() # accFeat = extractor.accumulatedFeatures(img) # features.append(accFeat) # mean = accFeat[:,0] # ucm = extractor.ucmTransformFeatures(mean[:,None],wardness) # features.extend([accFeat,ucm]) features = numpy.concatenate(features,axis=1) self.currentFeatures = features print "compute done" fMin = numpy.min(features, axis=0) fMax = numpy.max(features, axis=0) self.featureMinMax = (fMin, fMax) self.ctrlWidget.setFeatures(self.currentFeatures.shape[1]) self.ctrlWidget.modeSelectorComboBox.setCurrentIndex(2)
if True: if True: options = bw.BlockwiseConvolutionOptions3D() sigma = 2.7 options.stdDev = (sigma, )*3 options.blockShape = (64, )*3 print "hessianEv" ev = bw.hessianOfGaussianFirstEigenvalue(volume, options) print ev.shape, ev.dtype options.stdDev = (4.5, )*3 print "smooth" ev = bw.gaussianSmooth(ev, options) vigra.impex.writeHDF5(ev,"growmap.h5",'data') else: ev = vigra.impex.readHDF5("growmap.h5",'data') with vigra.Timer("watershedsNew"): labels, nseg = vigra.analysis.unionFindWatershed3D(ev,(100,100,100)) print "gridGraph" gridGraph = graphs.gridGraph(labels.shape) rag = graphs.regionAdjacencyGraph(gridGraph, labels) rag.writeHDF5("rag.h5",'data') else:
import vigra from vigra import graphs from vigra import numpy from vigra import Timer from vigra import blockwise as bw numpy.random.seed(42) # input shape = (500, 500, 500) data = numpy.random.rand(*shape).astype('float32') print "make options object" options = bw.BlockwiseConvolutionOptions3D() print type(options) sigma = 1.0 options.stdDev = (sigma, ) * 3 options.blockShape = (128, ) * 3 print "stddev", options.stdDev print "call blockwise filter" with vigra.Timer("AllThread"): res = bw.gaussianSmooth(data, options) with vigra.Timer("1thread"): resRef = vigra.gaussianSmoothing(data, sigma) print numpy.sum(numpy.abs(res - resRef))
def onClickedComputeFeaturesImpl(self, param): lCtrl = self.layerCtrl extractor = self.featureExtractor rawData = self.dataDict['raw'] print "compute features" print param options = bw.BlockwiseConvolutionOptions3D() options.blockShape = (128, ) * 3 fSize = [0] def fRange(feat): old = long(fSize[0]) fSize[0] += feat.shape[1] return (old, fSize[0]) geoFeat, geoFeatNames = extractor.geometricFeatures() lCtrl.addFeature("GeometricFeature", fRange(geoFeat), subNames=geoFeatNames) topoFeat, topoFeatNames = extractor.topologicalFeatures() lCtrl.addFeature("TopologicalFeatures", fRange(topoFeat), subNames=topoFeatNames) features = [geoFeat, topoFeat] for order in range(3): orderName = '%d-Order Filter' % order doFilter = param[('RawData', orderName, 'computeFilter')] if (doFilter): sigmas = param[('RawData', orderName, 'sigma')] sigmas = list(eval(sigmas)) doUcm = param[('RawData', orderName, 'UCM', 'ucmFilters')] ucmMeanSign = float(param[('RawData', orderName, 'UCM', 'meanSign')]) print "ucmMeanSign", ucmMeanSign print "doUcm", doUcm wardness = param[('RawData', orderName, 'UCM', 'wardness')] wardness = list(eval(wardness)) wardness = numpy.array(wardness, dtype='float32') wnames = [] for w in wardness: wnames.append(" w" + str(w)) wnames.append(" r" + str(w)) print "sigma", sigmas, "w", wardness for sigma in sigmas: print sigma orderSigmaName = orderName + str(sigma) options.stdDev = (float(sigma), ) * 3 if order == 0: if sigma < 0.01: res = rawData else: res = bw.gaussianSmooth(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures( res) lCtrl.addFeature(orderSigmaName, fRange(accFeat), subNames=accFeatNames) features.append(accFeat) if doUcm: mean = accFeat[:, 0] mean *= ucmMeanSign ucmName = orderSigmaName + "MeanUcm" ucm = extractor.ucmTransformFeatures( mean[:, None], wardness) lCtrl.addFeature(ucmName, fRange(ucm), subNames=wnames) features.append(ucm) if order == 1: if sigma < 0.5: continue else: res = bw.gaussianGradientMagnitude( rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures( res) lCtrl.addFeature(orderSigmaName, fRange(accFeat), subNames=accFeatNames) features.append(accFeat) if doUcm: mean = accFeat[:, 0] print "ucmMeanSign", ucmMeanSign mean *= ucmMeanSign ucmName = orderSigmaName + "MeanUcm" ucm = extractor.ucmTransformFeatures( mean[:, None], wardness) lCtrl.addFeature(ucmName, fRange(ucm), subNames=wnames) features.append(ucm) if order == 2: if sigma < 0.5: continue else: res = bw.hessianOfGaussianFirstEigenvalue( rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures( res) lCtrl.addFeature(orderSigmaName, fRange(accFeat), subNames=accFeatNames) features.append(accFeat) if doUcm: mean = accFeat[:, 0] mean *= ucmMeanSign ucmName = orderSigmaName + "MeanUcm" ucm = extractor.ucmTransformFeatures( mean[:, None], wardness) lCtrl.addFeature(ucmName, fRange(ucm), subNames=wnames) features.append(ucm) if False: for s in [2.0]: options.stdDev = (s, ) * 3 res = bw.gaussianSmooth(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature("RawGaussianSmooth", fRange(accFeat), subNames=accFeatNames) features.append(accFeat) # 6 wardness = numpy.array([0.0, 0.1, 0.15, 0.25, 0.5, 1.0], dtype='float32') wnames = [] for w in wardness: wnames.append(" w" + str(w)) wnames.append(" r" + str(w)) for s in [2.0]: options.stdDev = (s, ) * 3 res = bw.hessianOfGaussianFirstEigenvalue(rawData, options) accFeat, accFeatNames = extractor.accumulatedFeatures(res) lCtrl.addFeature("hessianOfGaussianFirstEigenvalue", fRange(accFeat), subNames=accFeatNames) features.append(accFeat) print "ucm" mean = accFeat[:, 0] ucm = extractor.ucmTransformFeatures(mean[:, None], wardness) print "ucm done" lCtrl.addFeature("hessianMeanUcm", fRange(ucm), subNames=wnames) features.append(ucm) #for s in [1.0, 3.0, 4.0]: # img = hessianEv2(rawData, s, 2.0) # #vigra.imshow(img) # #vigra.show() # accFeat = extractor.accumulatedFeatures(img) # features.append(accFeat) # mean = accFeat[:,0] # ucm = extractor.ucmTransformFeatures(mean[:,None],wardness) # features.extend([accFeat,ucm]) features = numpy.concatenate(features, axis=1) self.currentFeatures = features print "compute done" fMin = numpy.min(features, axis=0) fMax = numpy.max(features, axis=0) self.featureMinMax = (fMin, fMax) self.ctrlWidget.setFeatures(self.currentFeatures.shape[1]) self.ctrlWidget.modeSelectorComboBox.setCurrentIndex(2)
if True: if True: options = bw.BlockwiseConvolutionOptions3D() sigma = 2.7 options.stdDev = (sigma, ) * 3 options.blockShape = (64, ) * 3 print "hessianEv" ev = bw.hessianOfGaussianFirstEigenvalue(volume, options) print ev.shape, ev.dtype options.stdDev = (4.5, ) * 3 print "smooth" ev = bw.gaussianSmooth(ev, options) vigra.impex.writeHDF5(ev, "growmap.h5", 'data') else: ev = vigra.impex.readHDF5("growmap.h5", 'data') with vigra.Timer("watershedsNew"): labels, nseg = vigra.analysis.unionFindWatershed3D(ev, (100, 100, 100)) print "gridGraph" gridGraph = graphs.gridGraph(labels.shape) rag = graphs.regionAdjacencyGraph(gridGraph, labels) rag.writeHDF5("rag.h5", 'data') else: rag = vigra.graphs.loadGridRagHDF5("rag.h5", 'data')