Ejemplo n.º 1
0
#
# Super Pixel inference
#

# Construct test data: a 2x2 checkerboard with 4 superpixels.  Want top 2
# to come out class 0, and bottom to be class 1.
splabels = np.array(
    [[0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1], [0, 0, 0, 1, 1, 1],
     [2, 2, 2, 3, 3, 3], [2, 2, 2, 3, 3, 3], [2, 2, 2, 3, 3, 3]],
    dtype=np.int32)
spnodes = np.arange(4)
spedges = [[0, 1], [2, 3], [0, 2], [1, 3]]
lblWts = -np.log(
    np.array([[0.01, 0.02, 0.90], [0.80, 0.02, 0.05], [0.01, 0.02, 0.87],
              [0.01, 0.82, 0.03]]))

spgraph = sp.SuperPixelGraph(splabels, spnodes, spedges)

x = np.reshape([np.arange(4) * 10], (4, 1))
y = spgraph.imageFromSuperPixelData(x)
print y

res = uflow.inferenceSuperPixel(spgraph, lblWts, 'abswap', 'degreeSensitive')
print "Inference result = \n", res

expectedResult = np.array([[2, 2, 2, 0, 0, 0], [2, 2, 2, 0, 0, 0],
                           [2, 2, 2, 0, 0, 0], [2, 2, 2, 1, 1, 1],
                           [2, 2, 2, 1, 1, 1], [2, 2, 2, 1, 1, 1]])
assert (np.all(expectedResult == res))
        print 'Click plot to continue...'
        plt.waitforbuttonpress()

#
# Do the inference
#


print 'Performing CRF inference...'
if args.verbose:
    plt.figure()

segResult = uflow.inferenceSuperPixel( \
    spix,\
    -np.log( np.maximum(1E-10, np.ascontiguousarray(classProbs) ) ), \
    adjProbs, \
    'abswap',\
    args.nbrPotentialMethod,\
    K )#, np.ascontiguousarray(nbrPotentialParams) )

# turn from label classes to msrc labels
segResult += 1
print '   done.'

if args.outfile and len(args.outfile)>0:
    print 'Writing output label file %s' % args.outfile
    outimg = pomio.msrc_convertLabelsToRGB( segResult )
    skimage.io.imsave(args.outfile, outimg)
    print '   done.'

# Show the result.
    if dointeract:
        print 'Click plot to continue...'
        plt.waitforbuttonpress()

#
# Do the inference
#

print 'Performing CRF inference...'
if args.verbose:
    plt.figure()

segResult = uflow.inferenceSuperPixel( \
    spix,\
    -np.log( np.maximum(1E-10, np.ascontiguousarray(classProbs) ) ), \
    adjProbs, \
    'abswap',\
    args.nbrPotentialMethod,\
    K )#, np.ascontiguousarray(nbrPotentialParams) )

# turn from label classes to msrc labels
segResult += 1
print '   done.'

if args.outfile and len(args.outfile) > 0:
    print 'Writing output label file %s' % args.outfile
    outimg = pomio.msrc_convertLabelsToRGB(segResult)
    skimage.io.imsave(args.outfile, outimg)
    print '   done.'

# Show the result.
Ejemplo n.º 4
0
        [2, 2, 2, 3, 3, 3],
        [2, 2, 2, 3, 3, 3],
        [2, 2, 2, 3, 3, 3],
    ],
    dtype=np.int32,
)
spnodes = np.arange(4)
spedges = [[0, 1], [2, 3], [0, 2], [1, 3]]
lblWts = -np.log(np.array([[0.01, 0.02, 0.90], [0.80, 0.02, 0.05], [0.01, 0.02, 0.87], [0.01, 0.82, 0.03]]))

spgraph = sp.SuperPixelGraph(splabels, spnodes, spedges)

x = np.reshape([np.arange(4) * 10], (4, 1))
y = spgraph.imageFromSuperPixelData(x)
print y

res = uflow.inferenceSuperPixel(spgraph, lblWts, "abswap", "degreeSensitive")
print "Inference result = \n", res

expectedResult = np.array(
    [
        [2, 2, 2, 0, 0, 0],
        [2, 2, 2, 0, 0, 0],
        [2, 2, 2, 0, 0, 0],
        [2, 2, 2, 1, 1, 1],
        [2, 2, 2, 1, 1, 1],
        [2, 2, 2, 1, 1, 1],
    ]
)
assert np.all(expectedResult == res)
Ejemplo n.º 5
0
        [0,0,0, 1,1,1],
        [0,0,0, 1,1,1],
        [0,0,0, 1,1,1],
        [2,2,2, 3,3,3],
        [2,2,2, 3,3,3],
        [2,2,2, 3,3,3] ], dtype=np.int32 )
spnodes = np.arange(4)
spedges = [ [0,1], [2,3], [0,2], [1,3] ];
lblWts = -np.log( np.array( [ [ 0.01, 0.02, 0.90], 
                   [ 0.80, 0.02, 0.05], 
                   [ 0.01, 0.02, 0.87], 
                   [ 0.01, 0.82, 0.03] ] ) )

spgraph = sp.SuperPixelGraph(splabels,spnodes,spedges)

x = np.reshape( [np.arange(4)*10], (4,1) )
y = spgraph.imageFromSuperPixelData( x )
print y

res = uflow.inferenceSuperPixel( spgraph, lblWts, 'abswap', 'degreeSensitive' )
print "Inference result = \n", res

expectedResult = np.array( [
        [2,2,2, 0,0,0],
        [2,2,2, 0,0,0],
        [2,2,2, 0,0,0],
        [2,2,2, 1,1,1],
        [2,2,2, 1,1,1],
        [2,2,2, 1,1,1] ] )
assert( np.all( expectedResult == res ) )