Example #1
0
def testGridGraphWatersheds():

    data = numpy.random.random([10, 10, 10]).astype(numpy.float32)
    edata = numpy.random.random([10 * 2 - 1, 10 * 2 - 1,
                                 10 * 2 - 1]).astype(numpy.float32)
    g0 = graphs.gridGraph(data.shape)

    ew = graphs.edgeFeaturesFromInterpolatedImage(graph=g0, image=edata)

    # generate seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0, nodeWeights=data)
    # node weighted watershed seeds
    labelsNodeWeightedA = graphs.nodeWeightedWatersheds(graph=g0,
                                                        nodeWeights=data,
                                                        seeds=seeds)
    # node weighted watershed seeds
    labelsNodeWeightedB = graphs.nodeWeightedWatersheds(graph=g0,
                                                        nodeWeights=data)
    # edge weighted watershed seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0, nodeWeights=data)
    labelsEdgeWeighted = graphs.edgeWeightedWatersheds(graph=g0,
                                                       edgeWeights=ew,
                                                       seeds=seeds)

    assert numpy.array_equal(labelsNodeWeightedA, labelsNodeWeightedB)

    data = numpy.random.random([10, 10]).astype(numpy.float32)
    edata = numpy.random.random([10 * 2 - 1, 10 * 2 - 1]).astype(numpy.float32)
    g0 = graphs.gridGraph(data.shape)

    ew = graphs.edgeFeaturesFromInterpolatedImage(graph=g0, image=edata)

    # generate seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0, nodeWeights=data)
    # node weighted watershed seeds
    labelsNodeWeightedA = graphs.nodeWeightedWatersheds(graph=g0,
                                                        nodeWeights=data,
                                                        seeds=seeds)
    # node weighted watershed seeds
    labelsNodeWeightedB = graphs.nodeWeightedWatersheds(graph=g0,
                                                        nodeWeights=data)
    # edge weighted watershed seeds
    labelsEdgeWeighted = graphs.edgeWeightedWatersheds(graph=g0,
                                                       edgeWeights=ew,
                                                       seeds=seeds)

    assert numpy.array_equal(labelsNodeWeightedA, labelsNodeWeightedB)
Example #2
0
def testGridGraphWatersheds():

    data  = numpy.random.random([10,10,10]).astype(numpy.float32)
    edata = numpy.random.random([10*2-1,10*2-1,10*2-1]).astype(numpy.float32)
    g0 = graphs.gridGraph(data.shape)


    ew = graphs.edgeFeaturesFromInterpolatedImage(graph=g0,image=edata)

    # generate seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0,nodeWeights=data)
    # node weighted watershed seeds
    labelsNodeWeightedA  = graphs.nodeWeightedWatersheds(graph=g0,nodeWeights=data,seeds=seeds)
    # node weighted watershed seeds
    labelsNodeWeightedB  = graphs.nodeWeightedWatersheds(graph=g0,nodeWeights=data)
    # edge weighted watershed seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0,nodeWeights=data)
    labelsEdgeWeighted  = graphs.edgeWeightedWatersheds(graph=g0,edgeWeights=ew,seeds=seeds)

    assert numpy.array_equal(labelsNodeWeightedA,labelsNodeWeightedB)

    data  = numpy.random.random([10,10]).astype(numpy.float32)
    edata = numpy.random.random([10*2-1,10*2-1]).astype(numpy.float32)
    g0 = graphs.gridGraph(data.shape)


    ew = graphs.edgeFeaturesFromInterpolatedImage(graph=g0,image=edata)

    # generate seeds
    seeds = graphs.nodeWeightedWatershedsSeeds(graph=g0,nodeWeights=data)
    # node weighted watershed seeds
    labelsNodeWeightedA  = graphs.nodeWeightedWatersheds(graph=g0,nodeWeights=data,seeds=seeds)
    # node weighted watershed seeds
    labelsNodeWeightedB  = graphs.nodeWeightedWatersheds(graph=g0,nodeWeights=data)
    # edge weighted watershed seeds
    labelsEdgeWeighted  = graphs.edgeWeightedWatersheds(graph=g0,edgeWeights=ew,seeds=seeds)

    assert numpy.array_equal(labelsNodeWeightedA,labelsNodeWeightedB)
Example #3
0
# 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,
                                                                  gradMagBig)

# get region adjacency graph from super-pixel labels
rag = graphs.regionAdjacencyGraph(gridGraph, labels)


# accumulate edge  and ndie weights from gradient magnitude
ragEdgeWeights = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator)
ragNodeWeights = rag.accumulateNodeFeatures(gradMag)

# generate seeds
seeds = graphs.nodeWeightedWatershedsSeeds(rag, ragNodeWeights)

# node weighted watersheds
labelsNodeWeighted  = graphs.nodeWeightedWatersheds(rag, ragNodeWeights, seeds)

# edge weighted watersheds
labelsEdgeWeighted  = graphs.edgeWeightedWatersheds(rag, ragEdgeWeights, seeds)


f = pylab.figure()
ax0 = f.add_subplot(1, 2, 0)
rag.showNested(img, labelsNodeWeighted)
ax0.set_title("node weighted")

ax1 = f.add_subplot(1, 2, 1)
rag.showNested(img, labelsEdgeWeighted)
Example #4
0
# 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,
                                                                  gradMagBig)

# get region adjacency graph from super-pixel labels
rag = graphs.regionAdjacencyGraph(gridGraph, labels)


# accumulate edge  and ndie weights from gradient magnitude
ragEdgeWeights = rag.accumulateEdgeFeatures(gridGraphEdgeIndicator)
ragNodeWeights = rag.accumulateNodeFeatures(gradMag)

# generate seeds
seeds = graphs.nodeWeightedWatershedsSeeds(rag, ragNodeWeights)

# node weighted watersheds
labelsNodeWeighted  = graphs.nodeWeightedWatersheds(rag, ragNodeWeights, seeds)

# edge weighted watersheds
labelsEdgeWeighted  = graphs.edgeWeightedWatersheds(rag, ragEdgeWeights, seeds)


f = pylab.figure()
ax0 = f.add_subplot(1, 2, 0)
rag.showNested(img, labelsNodeWeighted)
ax0.set_title("node weighted")

ax1 = f.add_subplot(1, 2, 1)
rag.showNested(img, labelsEdgeWeighted)