본문 바로가기

Python

[NYU depth] How to read NYU depth dataset in python

반응형

NYU depth v2 dataset can be downloaded from http://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html


They provide images and corresponding depth-map (aligned and in-painted) for training and testing. 


The data is stored in the format of mat. The following code shows how to read the images and corresponding depth-map in python.


Enjoy.


// CODES ////////////////////////////////////// 


import skimage.io as io
import numpy as np
import h5py

# data path
path_to_depth = './nyu_depth_v2_labeled.mat'

# read mat file
f = h5py.File(path_to_depth)

# read 0-th image. original format is [3 x 640 x 480], uint8
img = f['images'][0]

# reshape
img_ = np.empty([480, 640, 3])
img_[:,:,0] = img[0,:,:].T
img_[:,:,1] = img[1,:,:].T
img_[:,:,2] = img[2,:,:].T

# imshow
img__ = img_.astype('float32')
io.imshow(img__/255.0)
io.show()


# read corresponding depth (aligned to the image, in-painted) of size [640 x 480], float64
depth = f['depths'][0]

# reshape for imshow
depth_ = np.empty([480, 640, 3])
depth_[:,:,0] = depth[:,:].T
depth_[:,:,1] = depth[:,:].T
depth_[:,:,2] = depth[:,:].T

io.imshow(depth_/4.0)
io.show()


These are the results