# print "Reading pre-built classifier from file::" , classifierFilename , "@" , datetime.datetime.now() # classifier = loadClassifier(classifierFilename) # # predictImage = pomio.msrc_loadImages(msrcData)[0] plt.interactive(1) plt.figure() pomio.showClassColours() plt.figure() for img in msrcImages: print "\nRead in image %s from the MSRC dataset::" % img.m_imgFn imageFeatures = FeatureGenerator.generatePixelFeaturesForImage(img.m_img) predLabs = classifier.predict(imageFeatures) print "\nGenerating prediction of shape ", predLabs.shape, "::" , predLabs predImg = np.reshape( predLabs, img.m_img[:,:,0].shape ) #print "\nGenerating the probability dist. for each pixel over class labels @" , datetime.datetime.now() #imageClassDist = generateImagePredictionClassDist(img.m_img, classifier,False) # Display print "Unique labels from clfr = ", np.unique(predLabs) plt.subplot(1,2,1) plt.imshow(img.m_img) plt.subplot(1,2,2) pomio.showLabels( predImg ) plt.waitforbuttonpress() print "\tCompleted @ " + str(datetime.datetime.now()) plt.interactive(0) plt.show()
plt.figure() pomio.showClassColours() plt.figure() print 'Classifying file ', args.infile image = skimage.io.imread(args.infile) [spClassPreds, spGraph ] = SuperPixelClassifier.predictSuperPixelLabels(clfr, image, numberSuperPixels, superPixelCompactness) spClassPredsImage = spGraph.imageFromSuperPixelData( spClassPreds.reshape((len(spClassPreds), 1))) if args.verbose: plt.subplot(1, 2, 1) plt.imshow(image) plt.title(args.infile) plt.subplot(1, 2, 2) pomio.showLabels(spClassPredsImage) plt.waitforbuttonpress() if args.outfile and len(args.outfile) > 0: print 'Writing output label file %s' % args.outfile outimg = pomio.msrc_convertLabelsToRGB(spClassPredsImage) skimage.io.imsave(args.outfile, outimg) print ' done.' if args.verbose: plt.interactive(0) plt.show()
plt.figure() plt.imshow(imgRGB) plt.title('original image') # show superpixels plt.figure() spix.draw() plt.title('Super Pixels') # show class labels per pixel classLabs = np.argmax( classProbs, 1 ) # these are labs per region. turn into an image of labels. plt.figure() # +1 adds void class # todo: tidy this shemozzle up! pomio.showLabels( spix.imageFromSuperPixelData( classLabs + 1 ) ) plt.title('Raw Classifier Labelling') plt.figure() pomio.showClassColours() plt.draw() if dointeract: print 'Click plot to continue...' plt.waitforbuttonpress() # # Do the inference # print 'Performing CRF inference...'
# # predictImage = pomio.msrc_loadImages(msrcData)[0] plt.interactive(1) plt.figure() pomio.showClassColours() plt.figure() for img in msrcImages: print "\nRead in image %s from the MSRC dataset::" % img.m_imgFn # todo: replace with features.computePixelFeatures JRS imageFeatures = FeatureGenerator.generatePixelFeaturesForImage( img.m_img) predLabs = classifier.predict(imageFeatures) print "\nGenerating prediction of shape ", predLabs.shape, "::", predLabs predImg = np.reshape(predLabs, img.m_img[:, :, 0].shape) #print "\nGenerating the probability dist. for each pixel over class labels @" , datetime.datetime.now() #imageClassDist = generateImagePredictionClassDist(img.m_img, classifier,False) # Display print "Unique labels from clfr = ", np.unique(predLabs) plt.subplot(1, 2, 1) plt.imshow(img.m_img) plt.subplot(1, 2, 2) pomio.showLabels(predImg) plt.waitforbuttonpress() print "\tCompleted @ " + str(datetime.datetime.now()) plt.interactive(0) plt.show()
print ' classes = ', clfr.classes_ # Transform class probs to the correct sized matrix. nbRows = imgRGB.shape[0] nbCols = imgRGB.shape[1] nbClasses = pomio.getNumClasses() cpnew = np.zeros( (nbRows, nbCols, nbClasses) ) for i in range( classProbs.shape[2] ): # stuff this set of probs to new label cpnew[:,:,clfr.classes_[i]] = classProbs[:,:,i] classProbs = cpnew del cpnew maxLabel = np.argmax( classProbs, 2 ) pomio.showLabels(maxLabel, colourMap) if args.verbose: plt.title('raw clfr labels') plt.figure() pomio.showClassColours( classNames, colourMap ) plt.draw() if 0 and args.interactive: plt.waitforbuttonpress() #print classProbs if dbgMode and args.verbose: for i in range( classProbs.shape[2] ): plt.imshow( classProbs[:,:,i] ) plt.title( 'class %d: %s' % (i,classNames[i]) )
print ' classes = ', clfr.classes_ # Transform class probs to the correct sized matrix. nbRows = imgRGB.shape[0] nbCols = imgRGB.shape[1] nbClasses = pomio.getNumClasses() cpnew = np.zeros((nbRows, nbCols, nbClasses)) for i in range(classProbs.shape[2]): # stuff this set of probs to new label cpnew[:, :, clfr.classes_[i]] = classProbs[:, :, i] classProbs = cpnew del cpnew maxLabel = np.argmax(classProbs, 2) pomio.showLabels(maxLabel) plt.title('raw clfr labels') plt.figure() pomio.showClassColours() plt.draw() if dointeract: plt.waitforbuttonpress() print classProbs if dbgMode: for i in range(classProbs.shape[2]): plt.imshow(classProbs[:, :, i]) plt.title('class %d: %s' % (i, pomio.msrc_classLabels[i]))
plt.waitforbuttonpress() plt.figure() plt.imshow(imgRGB) plt.title('original image') # show superpixels plt.figure() spix.draw() plt.title('Super Pixels') # show class labels per pixel classLabs = np.argmax(classProbs, 1) # these are labs per region. turn into an image of labels. plt.figure() pomio.showLabels(spix.imageFromSuperPixelData(classLabs)) plt.title('Raw Classifier Labelling') plt.figure() pomio.showClassColours() plt.draw() if dointeract: print 'Click plot to continue...' plt.waitforbuttonpress() # # Do the inference # # Get adjacency probs if args.adjFn != None:
plt.figure() plt.imshow(imgRGB) plt.title('original image') # show superpixels plt.figure() spix.draw() plt.title('Super Pixels') # show class labels per pixel classLabs = np.argmax(classProbs, 1) # these are labs per region. turn into an image of labels. plt.figure() # +1 adds void class # todo: tidy this shemozzle up! pomio.showLabels(spix.imageFromSuperPixelData(classLabs + 1)) plt.title('Raw Classifier Labelling') plt.figure() pomio.showClassColours() plt.draw() if dointeract: print 'Click plot to continue...' plt.waitforbuttonpress() # # Do the inference # print 'Performing CRF inference...' if args.verbose:
plt.waitforbuttonpress() plt.figure() plt.imshow(imgRGB) plt.title('original image') # show superpixels plt.figure() spix.draw() plt.title('Super Pixels') # show class labels per pixel classLabs = np.argmax( classProbs, 1 ) # these are labs per region. turn into an image of labels. plt.figure() pomio.showLabels( spix.imageFromSuperPixelData( classLabs ) ) plt.title('Raw Classifier Labelling') plt.figure() pomio.showClassColours() plt.draw() if dointeract: print 'Click plot to continue...' plt.waitforbuttonpress() # # Do the inference # # Get adjacency probs if args.adjFn != None:
# Load all data print 'Loading all data...' # first arg should be msrc data path data = pomio.msrc_loadImages( sys.argv[1], ['Images/7_3_s.bmp']) # get particular image we like ex = data[0] plt.figure() plt.imshow(ex.m_img) plt.title('original image') plt.figure() clrs = [[z/255.0 for z in c[1]] for c in pomio.msrc_classToRGB] pomio.showLabels( ex.m_gt ) plt.title('ground truth labels' ) print 'unique class labels: ', np.unique(ex.m_gt) # generate features imagePixelFeatures = FeatureGenerator.generatePixelFeaturesForImage(ex.m_img) # For each feature, how many distinct values? for i in range(imagePixelFeatures.shape[1]): print "Feature %d has %d distinct values" \ % (i, len(np.unique( imagePixelFeatures[:,i])) ) # Plot a selection of features sel = np.arange(26,30) # sel = range(80,86)
superPixelCompactness = args.superPixelCompactness if args.verbose: plt.interactive(1) plt.figure() pomio.showClassColours() plt.figure() print 'Classifying file ', args.infile image = skimage.io.imread(args.infile) [spClassPreds, spGraph] = SuperPixelClassifier.predictSuperPixelLabels(clfr, image,numberSuperPixels, superPixelCompactness) spClassPredsImage = spGraph.imageFromSuperPixelData( spClassPreds.reshape( (len(spClassPreds),1) ) ) if args.verbose: plt.subplot(1,2,1) plt.imshow(image) plt.title(args.infile) plt.subplot(1,2,2) pomio.showLabels(spClassPredsImage) plt.waitforbuttonpress() if args.outfile and len(args.outfile)>0: print 'Writing output label file %s' % args.outfile outimg = pomio.msrc_convertLabelsToRGB( spClassPredsImage ) skimage.io.imsave(args.outfile, outimg) print ' done.' if args.verbose: plt.interactive(0) plt.show()
print ' classes = ', clfr.classes_ # Transform class probs to the correct sized matrix. nbRows = imgRGB.shape[0] nbCols = imgRGB.shape[1] nbClasses = pomio.getNumClasses() cpnew = np.zeros( (nbRows, nbCols, nbClasses) ) for i in range( classProbs.shape[2] ): # stuff this set of probs to new label cpnew[:,:,clfr.classes_[i]] = classProbs[:,:,i] classProbs = cpnew del cpnew maxLabel = np.argmax( classProbs, 2 ) pomio.showLabels(maxLabel) plt.title('raw clfr labels') plt.figure() pomio.showClassColours() plt.draw() if dointeract: plt.waitforbuttonpress() print classProbs if dbgMode: for i in range( classProbs.shape[2] ): plt.imshow( classProbs[:,:,i] ) plt.title( 'class %d: %s' % (i,pomio.msrc_classLabels[i]) )
import matplotlib # Load all data print 'Loading all data...' data = pomio.msrc_loadImages('/home/jamie/data/MSRC_ObjCategImageDatabase_v2', \ ['Images/7_3_s.bmp']) # get particular image we like ex = data[0] plt.figure() plt.imshow(ex.m_img) plt.title('original image') plt.figure() clrs = [[z / 255.0 for z in c[1]] for c in pomio.msrc_classToRGB] pomio.showLabels(ex.m_gt) plt.title('ground truth labels') print 'unique class labels: ', np.unique(ex.m_gt) # generate features imagePixelFeatures = FeatureGenerator.generatePixelFeaturesForImage(ex.m_img) # For each feature, how many distinct values? for i in range(imagePixelFeatures.shape[1]): print "Feature %d has %d distinct values" \ % (i, len(np.unique( imagePixelFeatures[:,i])) ) # Plot a selection of features sel = np.arange(12, 29, 2) # sel = range(80,86)