반응형
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
'Python' 카테고리의 다른 글
How to resize an image : skimage library (0) | 2017.08.01 |
---|---|
How to show an image : skimage library (0) | 2017.07.21 |
How to plot a graph : mathplotlib library (0) | 2017.07.21 |
How to write values in csv files (0) | 2017.07.18 |
How to read values from csv files (0) | 2017.07.18 |