adjProbs = None

precomputedMode = args.infile.endswith('.pkl') or args.infile.endswith('.mat')

if precomputedMode == True:
    # If the input file is a pkl (not image) assume we've run necessary superpixel classifier, and input is class label probabilities
    # Input is assumed to be a tuple [superpixels, classProbs]

    print "Using pre-computed superpixels and class label probabilities"
    if args.infile.endswith('.pkl'):
        superPixelInput = pomio.unpickleObject(args.infile)
        spix = superPixelInput[0]
        classProbs = superPixelInput[1]
        colourMap = pomio.msrc_classToRGB
    else:
        spix, classProbs = isprs.loadISPRSResultFromMatlab(args.infile)
        colourMap = isprs.colourMap

else:
    # Assume input image needs processing and classifying
    print "Superpixel generation mode"

    numberSuperPixels = args.nbSuperPixels
    superPixelCompactness = args.superPixelCompactness

    imgRGB = amntools.readImage(args.infile)

    # Turn image into superpixels.
    spix = superPixels.computeSuperPixelGraph(
        imgRGB, 'slic', [numberSuperPixels, superPixelCompactness])
Ejemplo n.º 2
0
  plt.imshow(imgRGB)
  plt.title('original image')
  #plt.waitforbuttonpress()
  plt.figure()

if precomputedMode == True:
  x = scipy.io.loadmat( args.matFn )
  if x.has_key('singlepix_conf'):
    # these are the per-pixel probs
    classLabs = x['singlepix_label']
    classProbs = x['singlepix_conf'].astype(float)
    # the labels are out of order for probabilities.  Paul has: impervious, bldg, car, low veg, tree, clutter
    #classProbs = classProbs[:,:, np.array([1,2,5,3,4])-1]
  else:
    # super-pixel probs
    spix, classProbsLUT = isprs.loadISPRSResultFromMatlab( args.matFn )
    classLabs = spix.m_labels
    # map the labels to HxWxC class probabilities matrix
    classProbs = np.zeros( classLabs.shape + (classProbsLUT.shape[1],) )
    for c in range( classProbsLUT.shape[1] ):
      # Get a mask of matching pixels
      classProbs[ :,:, c ] = classProbsLUT[ classLabs, c ]
  classNames = isprs.classLabels
  colourMap = isprs.colourMap
else:
  print 'Computing class probabilities...'
  print 'Loading classifier...'
  clfr = pomio.unpickleObject(clfrFn)
  ftype = 'classic'
  classLabs, classProbs = classification.classifyImagePixels(imgRGB, clfr, \
                                                               ftype, True)
Ejemplo n.º 3
0
from matplotlib import cm
import pomio
import slic
import superPixels
import skimage
import isprs
import amntools

imgRGB = amntools.readImage(args.imagefile)

if len(args.spfile) == 0:
    numberSuperPixels = args.nbSuperPixels
    superPixelCompactness = args.superPixelCompactness
    # Turn image into superpixels.
    spix = superPixels.computeSuperPixelGraph(imgRGB, "slic", [numberSuperPixels, superPixelCompactness])
elif args.spfile.endswith(".pkl"):
    superPixelInput = pomio.unpickleObject(args.spfile)
    spix = superPixelInput[0]
    classProbs = superPixelInput[1]
    colourMap = pomio.msrc_classToRGB
elif args.spfile.endswith(".mat"):
    spix, classProbs = isprs.loadISPRSResultFromMatlab(args.spfile)
    colourMap = isprs.colourMap
else:
    assert False


# Display superpixel boundaries on image.
plt.imshow(superPixels.generateImageWithSuperPixelBoundaries(imgRGB, spix.m_labels))
plt.show()