From: Francesc A. <fa...@py...> - 2004-04-06 17:41:05
|
Hello Hanneke, A Dimarts 06 Abril 2004 12:25, Hanneke Schuurmans va escriure: > Dear Francesc (and others), > > I need help on the following: > For my research I have to edit radar images. These images are stored in > HDF5 format. However when I want to > > open the file I get the error code as printed below. > The radar image is stored in /image1/image_data and consist of 8-bit data, > stored in a 2-dimensional array > > of 256 rows x 256 columns. I want to save only the image data in a matrix. > > I assume that the image dataset is not yet implemented in pytables. Could > you tell me if this can be done Yes, you are right. The IMAGE dataset is a special dataset that is implemented in the hdf5_hl (HDF5 High Level) library. See http://hdf.ncsa.uiuc.edu/HDF5/hdf5_hl/ and http://hdf.ncsa.uiuc.edu/HDF5/doc/ADGuide/ImageSpec.html for more info on that. Unluckly, PyTables implements all the datasets in hdf5_hl (ARRAYS and TABLES), except the IMAGE ones. Conceptually, it's not difficult to add this support, but it should represent a fair amount of work. If you want to have a try, look at the "Table" class in pytables/src/hdf5Extension.pyx and see how it links with the functions of the pytables/src/H5TB.c (a modified version of the file that comes with hdf5_hl library). I would suggest to add a new extension class (doing it in Pyrex is far more easy that writing it in pure C) called "Image", and provide methods for interacting with the features of the desired functions in hdf5_hl/src/H5IM.c (where the IMAGE code is). Then add a class in Python to wrap the Image extension class (you can follow the pytables/tables/Table.py as an example). You can complete your work by adding some unit tests for the new class (look at pytables/test/test_tables.py for a guide) and you are done (well, almost, because you should document your work and send it to me so as to include this support in the main PyTables distribution so that others users may benefit on that ;-). Other thing is that the IMAGE dataset seems to need support for multidimensional Attributes. Although this is not yet supported officially, however it should be not difficult at all to implement (see pytables/src/hdf5Extension.pyx:AttributeSet._g_getNodeAttr method). Of course, this kind of support is available under a commercial agreement. On another hand, if all you want is to access only to the data as a 2-dimensional array, without the advantages that represents the IMAGE object, you can apply the next patch: --- tables/Group.py.orig 2004-04-06 19:33:57.000000000 +0200 +++ tables/Group.py 2004-04-06 19:34:00.000000000 +0200 @@ -219,6 +219,8 @@ return Table() elif class_ == "ARRAY": return Array() + elif class_ == "IMAGE": + return Array() elif class_ == "EARRAY": return EArray() elif class_ == "VLARRAY": and perhaps it would work (beware, I haven't tested it my self!) Regards, -- Francesc Alted |