def nodeToEdgeFeat(nodeFeatures, rag): uv = rag.uvIds() uF = nodeFeatures[uv[:, 0], :] vF = nodeFeatures[uv[:, 1], :] feats = [ numpy.abs(uF - vF), uF + vF, uF * vF, numpy.minimum(uF, vF), numpy.maximum(uF, vF) ] return numpy.concatenate(feats, axis=1)
def computeFeatures(raw, pmap, rag): uv = rag.uvIds() nrag = nifty.graph.rag # list of all edge features we fill feats = [] # helper function to convert # node features to edge features def nodeToEdgeFeat(nodeFeatures): uF = nodeFeatures[uv[:, 0], :] vF = nodeFeatures[uv[:, 1], :] feats = [ numpy.abs(uF - vF), uF + vF, uF * vF, numpy.minimum(uF, vF), numpy.maximum(uF, vF) ] return numpy.concatenate(feats, axis=1) # accumulate features from raw data fRawEdge, fRawNode = nrag.accumulateStandartFeatures(rag=rag, data=raw, minVal=0.0, maxVal=255.0, numberOfThreads=1) feats.append(fRawEdge) feats.append(nodeToEdgeFeat(fRawNode)) # accumulate data from pmap fPmapEdge, fPmapNode = nrag.accumulateStandartFeatures(rag=rag, data=pmap, minVal=0.0, maxVal=1.0, numberOfThreads=1) feats.append(fPmapEdge) feats.append(nodeToEdgeFeat(fPmapNode)) # accumulate node and edge features from # superpixels geometry fGeoEdge = nrag.accumulateGeometricEdgeFeatures(rag=rag, numberOfThreads=1) feats.append(fGeoEdge) fGeoNode = nrag.accumulateGeometricNodeFeatures(rag=rag, numberOfThreads=1) feats.append(nodeToEdgeFeat(fGeoNode)) return numpy.concatenate(feats, axis=1)
def computeFeatures(raw, pmap, rag): uv = rag.uvIds() nrag = nifty.graph.rag # list of all edge features we fill feats = [] # helper function to convert # node features to edge features def nodeToEdgeFeat(nodeFeatures): uF = nodeFeatures[uv[:,0], :] vF = nodeFeatures[uv[:,1], :] feats = [ numpy.abs(uF-vF), uF + vF, uF * vF, numpy.minimum(uF,vF), numpy.maximum(uF,vF)] return numpy.concatenate(feats, axis=1) # accumulate features from raw data fRawEdge, fRawNode = nrag.accumulateStandartFeatures(rag=rag, data=raw, minVal=0.0, maxVal=255.0, numberOfThreads=1) feats.append(fRawEdge) feats.append(nodeToEdgeFeat(fRawNode)) # accumulate data from pmap fPmapEdge, fPmapNode = nrag.accumulateStandartFeatures(rag=rag, data=pmap, minVal=0.0, maxVal=1.0, numberOfThreads=1) feats.append(fPmapEdge) feats.append(nodeToEdgeFeat(fPmapNode)) # accumulate node and edge features from # superpixels geometry fGeoEdge = nrag.accumulateGeometricEdgeFeatures(rag=rag, numberOfThreads=1) feats.append(fGeoEdge) fGeoNode = nrag.accumulateGeometricNodeFeatures(rag=rag, numberOfThreads=1) feats.append(nodeToEdgeFeat(fGeoNode)) return numpy.concatenate(feats, axis=1)
def getTrainingData(rag, sp, pixelGt, features, settings): thresholds = settings['fuztGtThreshold'] t0,t1 = thresholds # compute overlap overlap = nifty.ground_truth.Overlap(rag.numberOfNodes-1, sp, pixelGt ) fuzzyEdgeGt = overlap.differentOverlaps(rag.uvIds()) where0 = numpy.where(fuzzyEdgeGt<t0) where1 = numpy.where(fuzzyEdgeGt>t1) f0 = features[where0] f1 = features[where1] feat = numpy.concatenate([f0,f1],axis=0) labels = numpy.ones(feat.shape[0],dtype='uint32') labels[0:f0.shape[0]] = 0 return feat,labels
seeds = nifty.segmentation.localMaximaSeeds(gtImage) growMap = nifty.filters.gaussianSmoothing(1.0 - gtImage, 1.0) growMap += 0.1 * nifty.filters.gaussianSmoothing(1.0 - gtImage, 6.0) gt = nifty.segmentation.seededWatersheds(growMap, seeds=seeds) # for benchmarking purposes... if (ds == 'test'): data['seeds'] = seeds data['gt'] = gt overlap = nifty.ground_truth.overlap(segmentation=overseg, groundTruth=gt) edgeGt = overlap.differentOverlaps(rag.uvIds()) data['edgeGt'] = edgeGt assert (rag.numberOfEdges == features.shape[0]) assert (edgeGt.shape[0] == features.shape[0]) # plot an image from each set if z % 12 == 0 and plot == 'on': figure = pylab.figure() figure.suptitle('%sing Set Slice %d' % (ds, z), fontsize=16) #fig = matplotlib.pyplot.gcf() figure.set_size_inches(18.5, 10.5) figure.add_subplot(3, 2, 1) pylab.imshow(raw, cmap='gray')
def accumulatedFeatures(raw, pmap, overseg, rag, settings): #print "bincoutn", numpy.bincount(overseg.reshape([-1])).size,"nNodes",rag.numberOfNodes uv = rag.uvIds() u = uv[:, 0] v = uv[:, 1] # geometric edge features geometricFeaturs = nifty.graph.rag.accumulateGeometricEdgeFeatures( rag, blockShape=[75, 75], numberOfThreads=1) allEdgeFeat = [geometricFeaturs] pixelFeats = [ raw[:, :, None], ] if pmap is not None: pixelFeats.append(pmap[:, :, None]) for sigma in (1.0, 2.0, 4.0, 6.0, 8.0): pf = [ vigra.filters.hessianOfGaussianEigenvalues(raw, 1.0 * sigma), vigra.filters.structureTensorEigenvalues(raw, 1.0 * sigma, 2.0 * sigma), vigra.filters.gaussianGradientMagnitude(raw, 1.0 * sigma)[:, :, None], vigra.filters.gaussianSmoothing(raw, 1.0 * sigma)[:, :, None] ] pixelFeats.extend(pf) if pmap is not None: pixelFeats.append( vigra.filters.gaussianSmoothing(pmap, 1.0 * sigma)[:, :, None]) pixelFeats.append( vigra.filters.hessianOfGaussianEigenvalues(pmap, 1.0 * sigma)), pixelFeats.append( vigra.filters.structureTensorEigenvalues( pmap, 1.0 * sigma, 2.0 * sigma)) pixelFeats = numpy.concatenate(pixelFeats, axis=2) for i in range(pixelFeats.shape[2]): pixelFeat = pixelFeats[:, :, i] edgeFeat, nodeFeat = nifty.graph.rag.accumulateStandartFeatures( rag=rag, data=pixelFeat.astype('float32'), minVal=pixelFeat.min(), maxVal=pixelFeat.max(), blockShape=[75, 75], numberOfThreads=10) uFeat = nodeFeat[u, :] vFeat = nodeFeat[v, :] du = numpy.abs(edgeFeat, uFeat) dv = numpy.abs(edgeFeat, vFeat) fList = [ uFeat + vFeat, uFeat * vFeat, numpy.abs(uFeat - vFeat), numpy.minimum(uFeat, vFeat), numpy.maximum(uFeat, vFeat), du + dv, numpy.abs(du - dv), numpy.minimum(du, dv), numpy.maximum(du, dv), edgeFeat ] edgeFeat = numpy.concatenate(fList, axis=1) allEdgeFeat.append(edgeFeat) allEdgeFeat = numpy.concatenate(allEdgeFeat, axis=1) return allEdgeFeat
# local maxima seeds seeds = nifty.segmentation.localMaximaSeeds(gtImage) # growing map growMap = nifty.filters.gaussianSmoothing(1.0 - gtImage, 1.0) growMap += 0.1 * nifty.filters.gaussianSmoothing( 1.0 - gtImage, 6.0) gt = nifty.segmentation.seededWatersheds(growMap, seeds=seeds) # map the gt to the edges overlap = nifty.ground_truth.overlap(segmentation=overseg, groundTruth=gt) # edge gt edgeGt = overlap.differentOverlaps(rag.uvIds()) data['edgeGt'] = edgeGt # plot each 14th if z % 14 == 0: figure = pylab.figure() figure.suptitle('Training Set Slice %d' % z, fontsize=20) #fig = matplotlib.pyplot.gcf() figure.set_size_inches(18.5, 10.5) figure.add_subplot(3, 2, 1) pylab.imshow(raw, cmap='gray') pylab.title("Raw data %s" % (ds)) figure.add_subplot(3, 2, 2)
# local maxima seeds seeds = nifty.segmentation.localMaximaSeeds(gtImage) # growing map growMap = nifty.filters.gaussianSmoothing(1.0-gtImage, 1.0) growMap += 0.1*nifty.filters.gaussianSmoothing(1.0-gtImage, 6.0) gt = nifty.segmentation.seededWatersheds(growMap, seeds=seeds) # map the gt to the edges overlap = nifty.ground_truth.overlap(segmentation=overseg, groundTruth=gt) # edge gt edgeGt = overlap.differentOverlaps(rag.uvIds()) data['edgeGt'] = edgeGt # plot each 14th if z % 14 == 0 : figure = pylab.figure() figure.suptitle('Training Set Slice %d'%z, fontsize=20) #fig = matplotlib.pyplot.gcf() figure.set_size_inches(18.5, 10.5) figure.add_subplot(3, 2, 1) pylab.imshow(raw, cmap='gray') pylab.title("Raw data %s"%(ds))