Skip to content

GaussianClassifier fails with TransformedImage object #49

@tboggs

Description

@tboggs

When a GaussianClassifier is created and the classify_image method is called on a TransformedImage object, and AttributeError is raised because the object does not have a reshape method (classify_image is expecting a numpy.ndarray object). The exception can be reproduced as follows:

>>> from spectral import *
>>> img = open_image('92AV3C.lan')
>>> gt = open_image('92AV3GT.GIS').read_band(0)
>>> data = img.load()
>>> pc = principal_components(data)
>>> pc_0999 = pc.reduce(fraction=0.999)
>>> img_pc = pc_0999.transform(img)
>>> classes = create_training_classes(img_pc, gt)
>>> gmlc = GaussianClassifier(classes)
>>> clmap = gmlc.classify_image(img_pc)
AttributeError                            Traceback (most recent call last)
<ipython-input-11-6488a72f9e73> in <module>()
----> 1 clmap = gmlc.classify_image(img_pc)
/home/thomas/src/spectral/spectral/algorithms/classifiers.pyc in classify_image(self, image)
    200         status.display_percentage('Processing...')
    201         shape = image.shape
--> 202         image = image.reshape(-1, shape[-1])
    203         scores = np.empty((image.shape[0], len(self.classes)), np.float64)
    204         delta = np.empty_like(image, dtype=np.float64)

AttributeError: 'TransformedImage' object has no attribute 'reshape'

This will also occur with the MahalanobisDistanceClassifier. The bug can be avoided by using the load method of the TransformedImage object (img_pc in the example above) to load the data into an ndarray (if sufficient memory is available). This bug will be fixed by using the parent class method Classifier.classify_image when the argument is not an ndarray.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions