NYUD V2資料集的簡介與提取

jiao_mrswang發表於2018-08-13

宣告:基於python3.6提取NYUD V2資料集

NYUD V2資料集下載網址如下:

https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html(文中在Toolbox中提供了常用的預處理影象函式)

下載好的資料集的檔名是nyu_depth_v2_labeled.mat,可以用matlab開啟。

NYUD V2資料集由1449張640*480的影象組成。

提取原圖:

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import h5py
import os
f=h5py.File("/home/yuyangyg/DataSet/NYUDataV2/nyu_depth_v2_labeled.mat")
images=f["images"]
images=np.array(images)
 
path_converted='./nyu_images'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)
 
from PIL import Image
images_number=[]
for i in range(len(images)):
    print(i)
    images_number.append(images[i])
    a=np.array(images_number[i])
#    print len(img)
    #img=img.reshape(3,480,640)
 #   print img.shape
    r = Image.fromarray(a[0]).convert('L')
    g = Image.fromarray(a[1]).convert('L')
    b = Image.fromarray(a[2]).convert('L')
    img = Image.merge("RGB", (r, g, b))
    img = img.transpose(Image.ROTATE_270)
   # plt.imshow(img)
   # plt.axis('off')
   # plt.show()
    iconpath='./nyu_images/'+str(i)+'.jpg'
    img.save(iconpath,optimize=True)
 

提取補洞後的深度圖:

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import h5py
import os
from PIL import Image
 
f=h5py.File("/home/yuyangyg/DataSet/NYUDataV2/nyu_depth_v2_labeled.mat")
depths=f["depths"]
depths=np.array(depths)
path_converted='./nyu_depths/'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)
max=depths.max()
print (depths.shape)
print (depths.max())
print (depths.min())
 
depths=depths/max*255
depths=depths.transpose((0,2,1))
print (depths.max())
print (depths.min())
 
for i in range(len(depths)):
    print (str(i)+'.png')
    depths_img=Image.fromarray(np.uint8(depths[i]))
    depths_img=depths_img.transpose(Image.FLIP_LEFT_RIGHT)
 
    iconpath = path_converted + str(i) + '.png'
    depths_img.save(iconpath, 'PNG', optimize=True)
 

提取原深度圖rawDepths:

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import h5py
import os
from PIL import Image
 
f=h5py.File("/home/yuyangyg/DataSet/NYUDataV2/nyu_depth_v2_labeled.mat")
depths=f["rawDepths"]
depths=np.array(depths)
path_converted='./nyu_rawDepths/'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)
max=depths.max()
print (depths.shape)
print (depths.max())
print (depths.min())
 
depths=depths/max*255
depths=depths.transpose((0,2,1))
print (depths.max())
print (depths.min())
 
for i in range(len(depths)):
    print (str(i)+'.png')
    depths_img=Image.fromarray(np.uint8(depths[i]))
    depths_img=depths_img.transpose(Image.FLIP_LEFT_RIGHT)
 
    iconpath = path_converted + str(i) + '.png'
    depths_img.save(iconpath, 'PNG', optimize=True)

 

提取label:

# -*- coding: utf-8 -*-
import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import h5py
import os
from PIL import Image
f=h5py.File("/home/yuyangyg/DataSet/NYUDataV2/nyu_depth_v2_labeled.mat")
labels=f["labels"]
labels=np.array(labels)
 
path_converted='./nyu_labels'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)
 
labels_number=[]
for i in range(len(labels)):
    labels_number.append(labels[i])
    labels_0=np.array(labels_number[i])
    #print labels_0.shape
    print (type(labels_0))
    label_img=Image.fromarray(np.uint8(labels_number[i]))
    #label_img = label_img.rotate(270)
    label_img = label_img.transpose(Image.ROTATE_270)
 
    iconpath='./nyu_labels/'+str(i)+'.png'
    label_img.save(iconpath, 'PNG', optimize=True)
 

備註:使用Toolbox中的fill_depth_colorization.m函式時,輸入的引數應該是double型別,如果影象是uint8或其他型別,則需要強轉為double型別。

參考文章:

https://blog.csdn.net/yuyangyg/article/details/80690995

 

相關文章