NYU Depth Dataset V2

NYU Depth Dataset V2数据集的读取

NYUD V2数据集下载网址如下:
https://cs.nyu.edu/~silberman/datasets/nyu_depth_v2.html
NYU Depth Dataset V2_第1张图片
下载到的Labeled dataset是 .mat文件。

给个百度云链接:
链接:https://pan.baidu.com/s/1zWFKXU37QWEb-ZSYce4rWg
提取码:9u4i

提取好的数据集
在这里插入图片描述
提取好的百度云链接:
链接:https://pan.baidu.com/s/1PtYMsaK6n9Kb_zw00BM_Ww
提取码:km2j

python代码读取数据

import numpy as np
import matplotlib.pyplot as plt
import scipy.io as sio
import h5py
import os
from PIL import Image
import cv2

f = h5py.File(".\data\\nyu_depth_v2_labeled.mat")

# extract images
images = f["images"]
images = np.array(images)

path_converted = '.\\NYU\\nyu_images'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)

images_number = []
for i in range(len(images)):
    images_number.append(images[i])
    a = np.array(images_number[i])
    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)
    iconpath = '.\\NYU\\nyu_images/' + str(i) + '.png'
    img.save(iconpath, optimize=True)
    # exit(0)

print("image extract finished!!!!!")

# extract depths
depths = f["depths"]
depths = np.array(depths)

path_converted = '.\\NYU\\nyu_depths/'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)

max = depths.max()
depths = depths / max * 65535
depths = depths.transpose((0, 2, 1))

for i in range(len(depths)):
    print(str(i) + '.png')
    depths_img = np.uint16(depths[i])
    depths_img_new = cv2.flip(depths_img, 1)
    print(depths_img_new.max(), depths_img_new.min())
    iconpath = path_converted + str(i) + '.png'
    cv2.imwrite(iconpath, depths_img_new)
    # exit(0)
print("depths extract finished!!!!!")


labels = f["labels"]
labels = np.array(labels)

path_converted = '.\\NYU\\nyu_labels/'
if not os.path.isdir(path_converted):
    os.makedirs(path_converted)

labels_max = labels.max()
labels = labels / labels_max * 65535
labels = labels.transpose((0, 2, 1))

for i in range(len(labels)):

    label_img = np.uint16(labels[i])
    label_img_new = cv2.flip(label_img, 1)

    iconpath = '.\\NYU\\nyu_labels/' + str(i) + '.png'
    cv2.imwrite(iconpath, label_img_new)
    # exit(0)

print("labels extract finished!!!!!")


0.png
NYU Depth Dataset V2_第2张图片

你可能感兴趣的:(python,计算机视觉,人工智能)