0

I'm trying to extract the images (and its label and such) from an RGB-D dataset called NYUV2 dataset. (I downloaded the labelled dataset)

It's a matlab file so I tried using hdf5 to read it but I don't know how to proceed from here. How do I save the images and its corresponding labels and depths into a different folder??

Here's the script that I used and its corresponding output.

import numpy as np
import h5py

f = h5py.File('nyu_depth_v2_labeled.mat','r')

k = list(f.keys())
print(k)

Output is

['#refs#', '#subsystem#', 'accelData', 'depths', 'images', 'instances', 'labels', 'names', 'namesToIds', 'rawDepthFilenames', 'rawDepths', 'rawRgbFilenames', 'sceneTypes', 'scenes']
sabrinazuraimi
  • 705
  • 1
  • 13
  • 28

1 Answers1

1

I hope this helps.

I suppose you are using the PIL package The function fromarray expects the "mode of the image" see https://pillow.readthedocs.io/en/3.1.x/handbook/concepts.html#concept-modes

I suppose your image is in RGB. I believe the image souhld be under group 'images' and dataset image_name

Therefore

import h5py
import numpy as np
from PIL import Image

hdf = h5py.File('nyu_depth_v2_labeled.mat','r')
array = np.array(list(hdf.get("images/image_name")))
img = Image.fromarray(array.astype('uint8'), 'RGB')
img.show()

You can also look at another answer I gave to know how to save images

Images saved as HDF5 arent colored

To view the content of the h5 file, download HDFview, it will help navigate through it.

PilouPili
  • 2,601
  • 2
  • 17
  • 31
  • Thank you for the answer! I think this would have worked if there was a dataset called image_name under the group 'images'.. I managed to solve it thanks to this site http://ddokkddokk.tistory.com/21 – sabrinazuraimi Sep 21 '18 at 05:41