Example #1
0
 def test_mahalanobis_class_mean(self):
     '''Test that a class's mean spectrum is classified as that class.
     Note this assumes that class priors are equal.
     '''
     mdc = spy.MahalanobisDistanceClassifier(self.ts)
     cl = mdc.classes[0]
     assert (mdc.classify(cl.stats.mean) == cl.index)
Example #2
0
 def test_mahalanobis_classify_transformedimage_runs(self):
     '''Mahalanobis classifier works with a TransformedImage object.'''
     pc = spy.principal_components(self.data).reduce(num=3)
     ximg = pc.transform(self.image)
     ts = spy.create_training_classes(pc.transform(self.data),
                                      self.gt,
                                      calc_stats=True)
     gmlc = spy.MahalanobisDistanceClassifier(ts)
     ret = gmlc.classify_image(ximg)
Example #3
0
 def test_mahalanobis_spectrum_image_equal(self):
     '''Tests that classification of spectrum is same as from image.'''
     mdc = spy.MahalanobisDistanceClassifier(self.ts)
     data = self.data[20:30, 30:40, :]
     assert(mdc.classify_spectrum(data[2, 2]) == \
            mdc.classify_image(data)[2, 2])
Example #4
0
cm2 = 'classar = np.concatenate((' + allstr + '))'
exec cm1
exec cm2

#Adjust (either zero-pad or cut) classification array to work with source raster
(cx, cy) = maskar.shape
if src_raster_num_bands > classification_images_num_bands:
    zerar = np.zeros((cx, cy))
    diff = src_raster_num_bands - classification_images_num_bands
    for i in range(diff):
        classar = np.dstack((classar, zerar))

#Create training class and model
trcls = sp.create_training_classes(classar, maskar)
gmlc = sp.GaussianClassifier(trcls)
mldc = sp.MahalanobisDistanceClassifier(trcls)

#Classify image and display results
(kclmap, c) = sp.kmeans(barall, 12, 30)  #unsupervised
gclmap = gmlc.classify_image(barall)  #supervised
mclmap = mldc.classify_image(barall)  #supervised


#Define classification colors for array conversion
def num2colR(arg):
    switcher = {
        1: 255,
        2: 0,
        3: 255,
        4: 255,
        5: 255,
Example #5
0
 def test_mahalanobis_classify_spyfile_runs(self):
     '''Mahalanobis classifier works with a SpyFile object.'''
     mdc = spy.MahalanobisDistanceClassifier(self.ts)
     ret = mdc.classify_image(self.image)