有标签的数据集是原始数据集的子集。它是由成对的RGB和深度帧同步组成的,并且每个图像都有多个标签。除了加上标签的深度地图之外(右),还包含了一组预处理的深度地图(中),该预处理的深度地图已经利用Colorization方法把确实数据填充了。与原始数据集不同,有标签数据集是一个matlab中的mat文件,有如下几个变量:
accelData-采用Nx4的加速度计值矩阵,当每帧都被取走。这些列包括设备的滚动、偏航、俯仰和倾斜角度。
depths-HxWxN维度的矩阵深度图,其中H和W分别为高度和宽度,N为图像的个数。深度元素的值是米。
images-HxWx3xN RGB图像矩阵,其中H和W分别是高度和宽度,N是图像的数量
labels-HxWxN标签矩阵,其中H和W分别是高度和宽度,N是图像数量。 标签范围从1…C,其中C是类的总数。 标签的范围从1…C是类的总数。如果一个像素的标签值为0,那么这个像素就没有标记。
names-每个类的英文名称的Cx1单元格数组
namesTolds-从英文标签名称到ID(使用C键值对)
rawDepths-HxWxN深度图矩阵,其中H和W分别是高度和宽度,N是图像数量。 这些深度图是kinect的原始输出
scenes-每个图像拍摄场景名称的Cx1单元阵列
原始数据集包含利用Kinect得到的原始的图像以及加速度存储(accelerometer dumps)。RGB相机和深度相机采样率是20至30 FPS(帧/秒)(随着时间会有变化)。While the frames are not synchronized, the timestamps for each of the RGB, depth and accelerometer files are included as part of each filename(不是很懂这句的意思,求解释)。数据集分为不同的文件夹,这对应于每个场景的拍摄,都被命名为‘living_room_0012′ 或者 ‘office_0014′。文件结构如下所示:
/ …/bedroom_0001/ …/bedroom_0001/a-1294886363.011060-3164794231.dump …/bedroom_0001/a-1294886363.016801-3164794231.dump … …/bedroom_0001/d-1294886362.665769-3143255701.pgm …/bedroom_0001/d-1294886362.793814-3151264321.pgm … …/bedroom_0001/r-1294886362.238178-3118787619.ppm …/bedroom_0001/r-1294886362.814111-3152792506.ppm
a-开头的是 accelerometer dumpsd-开头的是深度图像r-开头的是原始rgb图像 Note:由于原始数据集没有经过预处理,所以原始深度图像需要投影到RGB坐标系使得其对齐。The matlab toolbox has several useful functions for handling the data. To run the unit tests, you must have matlab’s xUniton your path.
demo_synched_projected_frames.m – Demos synchronization of the raw rgb and depth images as well as alignment of the rgb and raw depth.eval_seg.m – Evaluates the predicted segmentation against the ground truth label map.get_projected_depth.m – Projects the raw depth image onto the rgb image plane. This file contains the calibration parameters that are specific to the kinect used to gather the data.get_accel_data.m – Extracts the accelerometer data from the binary files in the raw dataset.get_projection_mask.m – Gets a mask for the images that crops areas whose depth had to be inferred, rather than directly projected from the Kinect signal.get_synched_frames.m – Returns a list of synchronized rgb and depth frames from a given scene in the raw dataset.get_train_test_split.m – Splits the data in a way that ensures that images from the same scene are not found in both train and test sets.关于解析mat文件中的names字段的粗略代码~,可以解析出来,由于我暂时没有用到这个name所以还没有做完整的解析过程。
name = data['names'] print(name.shape[0]) for i in range(name.shape[0]): pass a = data['names'][0][0] obj = data[a] str = "".join(chr(i) for i in obj[:]) print(str)之所以对Image保存成jpg格式没什么好说的~,把深度保存成jpg格式的话方便直观的看到深度的信息但是这种方式会把原始的深度值保存成像素值,所以我们为了保留原始的深度值进行利用,因此对depth而言单独保存成npy文件。这样就不会破坏深度值。
import numpy as np from scipy import misc import h5py dataFile = 'nyu_depth_data_labeled.mat' data = h5py.File(dataFile) image = np.array(data['images']) depth = np.array(data['depths']) print(image.shape) image = np.transpose(image,(0,2,3,1)) print(image.shape) print(depth.shape) image_path = '/home/jzj/yuanlei/easy_net/1/' depth_path = '/home/jzj/yuanlei/easy_net/2/' depth_img_path = '/home/jzj/yuanlei/easy_net/3/' for i in range(image.shape[0]): print(i) index = str(i) image_index_path = image_path + index + '.jpg' out_img = image[i, :, :, :] misc.imsave(image_index_path, out_img) for i in range(depth.shape[0]): print(i) index = str(i) depth_index_path = depth_path + index + '.npy' out_depth = depth[i,:,:] np.save(depth_index_path,out_depth) for i in range(depth.shape[0]): print(i) index = str(i) depth_index_path = depth_path + index + '.jpg' out_depth = depth[i,:,:] misc.imsave(depth_index_path,out_depth)
