def testGridGraphSegmentationFelzenszwalbSegmentation(): dataRGB = numpy.random.random([3, 3, 3]).astype(numpy.float32) dataRGB = taggedView(dataRGB, 'xyc') data = numpy.random.random([3, 3]).astype(numpy.float32) edata = numpy.random.random([3 * 2 - 1, 3 * 2 - 1]).astype(numpy.float32) g0 = graphs.gridGraph(data.shape) ew = graphs.edgeFeaturesFromInterpolatedImage(g0, edata) labels = graphs.felzenszwalbSegmentation(graph=g0, edgeWeights=ew, k=1.0, nodeNumStop=5) g1 = graphs.regionAdjacencyGraph(graph=g0, labels=labels) assert g1.nodeNum == 5 data = numpy.random.random([3, 3, 3]).astype(numpy.float32) edata = numpy.random.random([3 * 2 - 1, 3 * 2 - 1, 3 * 2 - 1]).astype(numpy.float32) g0 = graphs.gridGraph(data.shape) ew = graphs.edgeFeaturesFromInterpolatedImage(g0, edata) labels = graphs.felzenszwalbSegmentation(graph=g0, edgeWeights=ew, k=1.0, nodeNumStop=15) g1 = graphs.regionAdjacencyGraph(graph=g0, labels=labels) assert g1.nodeNum == 15
def testGridGraphSegmentationFelzenszwalbSegmentation(): dataRGB = numpy.random.random([3,3,3]).astype(numpy.float32) dataRGB = taggedView(dataRGB,'xyc') data = numpy.random.random([3,3]).astype(numpy.float32) edata = numpy.random.random([3*2-1,3*2-1]).astype(numpy.float32) g0 = graphs.gridGraph(data.shape) ew = graphs.edgeFeaturesFromInterpolatedImage(g0,edata) labels = graphs.felzenszwalbSegmentation(graph=g0,edgeWeights=ew,k=1.0,nodeNumStop=5) g1 = graphs.regionAdjacencyGraph(graph=g0,labels=labels) assert g1.nodeNum == 5 data = numpy.random.random([3,3,3]).astype(numpy.float32) edata = numpy.random.random([3*2-1,3*2-1,3*2-1]).astype(numpy.float32) g0 = graphs.gridGraph(data.shape) ew = graphs.edgeFeaturesFromInterpolatedImage(g0,edata) labels = graphs.felzenszwalbSegmentation(graph=g0,edgeWeights=ew,k=1.0,nodeNumStop=15) g1 = graphs.regionAdjacencyGraph(graph=g0,labels=labels) assert g1.nodeNum == 15
imgLab = vigra.colors.transform_RGB2Lab(img) labels, nseg = vigra.analysis.slicSuperpixels(imgLab, slicWeight, superpixelDiameter) labels = vigra.analysis.labelImage(labels) # compute gradient on interpolated image imgLabBig = vigra.resize(imgLab, [imgLab.shape[0] * 2 - 1, imgLab.shape[1] * 2 - 1]) gradMag = vigra.filters.gaussianGradientMagnitude(imgLabBig, sigmaGradMag) # get 2D grid graph and edgeMap for grid graph # from gradMag of interpolated image gridGraph = graphs.gridGraph(img.shape[0:2]) gridGraphEdgeIndicator = graphs.edgeFeaturesFromInterpolatedImage( gridGraph, gradMag) # get region adjacency graph from super-pixel labels rag = graphs.regionAdjacencyGraph(gridGraph, labels) # accumulate edge weights from gradient magnitude edgeWeights = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator) # do the segmentation with felzenszwalbs method labels = graphs.felzenszwalbSegmentation(rag, edgeWeights, k=50, nodeNumStop=nodeNumStop) rag.show(img, labels) vigra.show()
gradMag) # get 2D grid graph and edgeMap for grid graph # from gradMag of interpolated image gridGraph = graphs.gridGraph(img.shape[0:2]) gridGraphEdgeIndicator = graphs.edgeFeaturesFromInterpolatedImage(gridGraph, gradMag) # get region adjacency graph from super-pixel labels rag = graphs.regionAdjacencyGraph(gridGraph, labels) # accumulate edge weights from gradient magnitude ragEdgeIndicator = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator) # get labels/segmentation for rag ragLabels = graphs.felzenszwalbSegmentation(rag, ragEdgeIndicator, k=10, nodeNumStop=1000) # get more corsair graph from labeled rag rag2 = graphs.regionAdjacencyGraph(graph=rag, labels=ragLabels) # accumulate new edge weights rag2EdgeIndicator = rag2.accumulateEdgeFeatures(ragEdgeIndicator, acc='mean') # get labels/segmentation for rag2 rag2Labels = graphs.felzenszwalbSegmentation(rag2, ragEdgeIndicator, k=20, nodeNumStop=100) # get more corsair graph from labeled rag2 rag3 = graphs.regionAdjacencyGraph(graph=rag2, labels=rag2Labels)
# get super-pixels with slic on LAB image imgLab = vigra.colors.transform_RGB2Lab(img) labels, nseg = vigra.analysis.slicSuperpixels(imgLab, slicWeight, superpixelDiameter) labels = vigra.analysis.labelImage(labels) # compute gradient on interpolated image imgLabBig = vigra.resize(imgLab, [imgLab.shape[0]*2-1, imgLab.shape[1]*2-1]) gradMag = vigra.filters.gaussianGradientMagnitude(imgLabBig, sigmaGradMag) # get 2D grid graph and edgeMap for grid graph # from gradMag of interpolated image gridGraph = graphs.gridGraph(img.shape[0:2]) gridGraphEdgeIndicator = graphs.edgeFeaturesFromInterpolatedImage(gridGraph, gradMag) # get region adjacency graph from super-pixel labels rag = graphs.regionAdjacencyGraph(gridGraph, labels) # accumulate edge weights from gradient magnitude edgeWeights = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator) # do the segmentation with felzenszwalbs method labels = graphs.felzenszwalbSegmentation(rag, edgeWeights, k=50,nodeNumStop=nodeNumStop) rag.show(img, labels) vigra.show()
# get 2D grid graph and edgeMap for grid graph # from gradMag of interpolated image gridGraph = graphs.gridGraph(img.shape[0:2]) gridGraphEdgeIndicator = graphs.edgeFeaturesFromInterpolatedImage( gridGraph, gradMag) # get region adjacency graph from super-pixel labels rag = graphs.regionAdjacencyGraph(gridGraph, labels) # accumulate edge weights from gradient magnitude ragEdgeIndicator = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator) # get labels/segmentation for rag ragLabels = graphs.felzenszwalbSegmentation(rag, ragEdgeIndicator, k=10, nodeNumStop=1000) # get more corsair graph from labeled rag rag2 = graphs.regionAdjacencyGraph(graph=rag, labels=ragLabels) # accumulate new edge weights rag2EdgeIndicator = rag2.accumulateEdgeFeatures(ragEdgeIndicator, acc='mean') # get labels/segmentation for rag2 rag2Labels = graphs.felzenszwalbSegmentation(rag2, ragEdgeIndicator, k=20, nodeNumStop=100) # get more corsair graph from labeled rag2