spectralpython / spectral

Python module for hyperspectral image processing
MIT License
573 stars 139 forks source link

Image array indexing #33

Closed donm closed 9 years ago

donm commented 9 years ago

This fixes #32, and also fixes some SpyFile behavior and adds additional enhancements to ImageArray.

In particular, one change to ImageArray in this patch is that methods and numpy ufuncs always return a numpy ndarray instead of another ImageArray. This is because many times (always?) these results lost their association with the original image that gave the quality of being ImageArrays. For example, things like image_array.diagonal(), image_array.mean(axis=2), or image_array[0, 0, :] would previously return other ImageArrays. This doesn't make semantic sense, plus some attributes were wrong or were not set (nrows, bands, etc.). Returning an ndarray gets around these issues, and also makes the return type consistent with indexing and read_* methods in SpyFile.

tboggs commented 9 years ago

Looks like a great fix. One question... You define two local functions:

It appears that since these functions act as closures, they will be recompiled each time the corresponding __getitem__ method is called. Would it be more efficient instead to add them as pseudo-private methods to the corresponding classes? That is,

donm commented 9 years ago

Yeah, absolutely. Those functions will potentially be called repeatedly, so I'm glad you caught that. Also, the parent_getitem function could be simplified quite a bit due to other changes after it was written.

I added the changes doing a rebase, so if you refresh hopefully github will show you the new commits.