NYU Depth V2数据集相关介绍

一、参考资料

NYU Depth Dataset V2官网

论文:Indoor Segmentation and Support Inference from RGBD Images

二、 相关介绍

1.简介

NYU-Depth V2数据集由来自微软 Kinect 的RGB和深度相机记录的各种室内场景的视频序列组成。它具有:

  • 1449对密集标记的RGB和深度图像;
  • 来自3个城市的464个新场景;
  • 407,024个新的无标签帧;
  • 每个对象都标有类别和实例编号(如cup1、cup2、cup3等)。

2. 下载数据集

NYU Depth V2数据集的下载链接可以在多个地方找到。以下是一些可用的下载链接:

  1. 官方下载地址:NYU Depth V2的官方网站提供了数据集的下载,链接为 NYU Depth Dataset V2 homepage
  2. TensorFlow Datasets:TensorFlow Datasets也提供了NYU Depth V2数据集,可以通过以下链接访问 nyu_depth_v2 on TensorFlow Datasets
  3. 超神经(HyperAI)提供的下载信息:超神经平台上也有关于NYU Depth V2数据集的下载信息,链接为 NYU Depth V2 on HyperAI
  4. ATYUN官网提供的链接:ATYUN官网上也有关于NYU Depth V2数据集的介绍和下载链接,链接为 sayakpaul/nyu_depth_v2 on ATYUN
  5. Gitee AI:Gitee AI上也有该数据集的镜像,可以通过以下链接访问 nyu_depth_v2 on Gitee AI

3. 训练集与验证集

SplitExamples
'train'47,584
'validation'654

三、常用操作

1. 深度值归一化

# 方法一
max_depth = np.max(depths)
depth_normalized = (depth / max_depth) * 255

# 方法二
depth_normalized = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
depth_normalized *= 255  # 转换到0-255范围

2. RGB/深度图/标注图可视化

为了可视化NYU Depth V2数据集中的原图、深度图和标注图,我们可以使用Python的h5py库来读取.mat文件,然后使用matplotlib库来生成热力图。以下是如何实现这一过程的代码示例:

import h5py
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
matplotlib.use('TkAgg')
from PIL import Image


# 读取数据
# 指定.mat文件路径
mat_file_path = './data/nyu_depth_v2_labeled.mat'

# 使用h5py打开.mat文件
with h5py.File(mat_file_path, 'r') as f:
    # 提取RGB图像、深度图和标注图
    images = f['images'][:]  # Nx3xWxH
    depths = f['depths'][:]  # NxWxH
    labels = f['labels'][:]  # NxWxH

    # 假设取第一个样本进行可视化
    image = images[0]  # 选择第一个深度图像
    depth = depths[0]  # 选择第一个深度图像
    label = labels[0]  # 选择第一个深度图像

    # image = images[0, :, :, :]  # 选择第一个图像
    # depth = depths[0, :, :]  # 选择第一个深度图
    # label = labels[0, :, :]  # 选择第一个标注图

# 转换颜色空间
# 将图像数据从3xWxH转换为HxWx3
image = image.swapaxes(0, 2)
# 将深度和标注图数据从WxH转换为HxW
depth = depth.swapaxes(0, 1)
label = label.swapaxes(0, 1)

# 可视化
# 定义颜色映射
cmap = plt.cm.jet
# cmap = plt.cm.hot
# cmap = plt.cm.plasma
# cmap = plt.cm.viridis
# cmap = plt.cm.Greys

# 可视化RGB图像
plt.figure(figsize=(12, 6))
plt.subplot(131)
plt.imshow(image)
plt.title('Original Image')
# plt.axis('off')  # 不显示坐标轴

# 可视化深度图
depth_normalized = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
plt.subplot(132)
plt.imshow(depth_normalized, cmap=cmap, interpolation='nearest')
plt.title('Depth Map (Heatmap)')
# plt.axis('off')  # 不显示坐标轴

# 可视化标注图
label_normalized = (label - np.min(label)) / (np.max(label) - np.min(label))
plt.subplot(133)
plt.imshow(label_normalized, cmap=cmap, interpolation='nearest')
plt.title('Label Map (Heatmap)')
# plt.axis('off')  # 不显示坐标轴

# 显示图表
plt.tight_layout()
plt.show()
# 默认
depth_normalized = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))

在这里插入图片描述
深度值归一化处理

# 深度值归一化处理:1-depth
depth_normalized = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
depth_normalized = (np.ones_like(depth_normalized)-depth_normalized)

在这里插入图片描述

3. 保存RGB图/深度图/标注图

import h5py
import numpy as np
import os
import matplotlib.pyplot as plt
from PIL import Image
import matplotlib
matplotlib.use('TkAgg')


# 读取数据
# 指定.mat文件路径
mat_file_path = './data/nyu_depth_v2_labeled.mat'

# RGB图像、深度图和标注图的保存目录
images_path = './nyu_images/'
depths_path = './nyu_depths/'
labels_path = './nyu_labels/'

if not os.path.exists(images_path):
    os.makedirs(images_path)
if not os.path.exists(depths_path):
    os.makedirs(depths_path)
if not os.path.exists(labels_path):
    os.makedirs(labels_path)

# 定义颜色映射
cmap = plt.cm.jet
# cmap = plt.cm.hot
# cmap = plt.cm.plasma
# cmap = plt.cm.viridis
# cmap = plt.cm.Greys

# 使用h5py打开.mat文件
with h5py.File(mat_file_path, 'r') as f:
    # 提取RGB图像、深度图和标注图
    images = f['images'][:]  # Nx3xWxH
    depths = f['depths'][:]  # NxWxH
    labels = f['labels'][:]  # NxWxH

    # 保存RGB图像
    for idx, image in enumerate(images):
        # 将图像数据从3xWxH转换为HxWx3
        image = image.swapaxes(0, 2)
        image_path = os.path.join(images_path, f'image_{idx}.png')
        plt.imsave(image_path, image, cmap=cmap)
        print(f'image saved as {image_path}')

    # 保存深度图像
    for idx, depth in enumerate(depths):
        # 将深度和标注图数据从WxH转换为HxW
        depth = depth.swapaxes(0, 1)
        # 深度值归一化
        depth_normalized = (depth - np.min(depth)) / (np.max(depth) - np.min(depth))
        depth_image_path = os.path.join(depths_path, f'depth_{idx}.png')
        plt.imsave(depth_image_path, depth_normalized, cmap=cmap)
        print(f'depth_image saved as {depth_image_path}')
    
    # 保存标注图像
    for idx, label in enumerate(labels):
        # 将深度和标注图数据从WxH转换为HxW
        label = label.swapaxes(0, 1)
        # 标注值归一化
        label_normalized = (label - np.min(label)) / (np.max(label) - np.min(label))
        label_image_path = os.path.join(labels_path, f'label_{idx}.png')
        plt.imsave(label_image_path, label_normalized, cmap=cmap)
        print(f'label_image saved as {label_image_path}')

四、FAQ

Q:AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'

Traceback (most recent call last):
  File "/media/yoyo/Ubuntu 18.0/cache/Make3D-2/make3d_demo2.py", line 9, in <module>
    plt.figure(figsize=(8, 6))
  File "/home/yoyo/miniconda3/envs/demo-tf/lib/python3.9/site-packages/matplotlib/pyplot.py", line 934, in figure
    manager = new_figure_manager(
  File "/home/yoyo/miniconda3/envs/demo-tf/lib/python3.9/site-packages/matplotlib/pyplot.py", line 464, in new_figure_manager
    _warn_if_gui_out_of_main_thread()
  File "/home/yoyo/miniconda3/envs/demo-tf/lib/python3.9/site-packages/matplotlib/pyplot.py", line 441, in _warn_if_gui_out_of_main_thread
    canvas_class = cast(type[FigureCanvasBase], _get_backend_mod().FigureCanvas)
  File "/home/yoyo/miniconda3/envs/demo-tf/lib/python3.9/site-packages/matplotlib/pyplot.py", line 280, in _get_backend_mod
    switch_backend(rcParams._get("backend"))  # type: ignore[attr-defined]
  File "/home/yoyo/miniconda3/envs/demo-tf/lib/python3.9/site-packages/matplotlib/pyplot.py", line 343, in switch_backend
    canvas_class = module.FigureCanvas
AttributeError: module 'backend_interagg' has no attribute 'FigureCanvas'
# 解决办法
matplotlib切换图形界面显示终端TkAgg

import matplotlib
matplotlib.use('TkAgg')
  • 7
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

花花少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值