【语义分割】——SUN_RGBD数据集解析
简介:
虽然RGB-D传感器已经在⼀些视觉任务上实现了重⼤突破,⽐如3D重建,但我们还没有在⾼级场景理解上实现类似的性能飞跃。造成这种情况的主要原因之⼀可能是缺乏⼀个具有合理⼤⼩的基准,其中包括⽤于培训的3D注释和⽤于评估的3D度量标准。在本⽂中,我们提出了⼀个RGB-D基准套件,⽬的是为了在所有主要场景理解任务中推进最新的技术⽔平。我们的数据集由四个不同的传感器捕获,包含10,000张RGB-D图像,其规模与PASCAL VOC类似。整个数据集被密集地注释,包括146,617个2D多边形和58,657个具有精确对象⽅向的3D 边框,以及⼀个3D房间布局和场景类别。这个数据集使我们能够训练需要⼤量数据的算法来完成场景理解任务,使⽤直接和有意义的3D度量来评估它们,避免对⼩测试集进⾏过拟合,并研究交叉传感器的偏差。
这⾥我们主要解析其语义分割的部分
1. 语义标注解析
这⾥我们主要解析其语义分割的部分。⽬标是得到原始图像,语义label图像,语义可视化图像,类别⽂件。
Code(参考⾃:):
import os
import os.path as osp
import shutil
from PIL import Image
from scipy.io import loadmat
import matplotlib.pyplot as plt
import numpy as np
import random
from tqdm import tqdm
import h5py
import scipy
imgpath ='./SUNRGBD'
SUNRGBDMeta_dir ='./SUNRGBDtoolbox/Metadata/SUNRGBDMeta.mat'
SUNRGBD2Dg_dir ='./SUNRGBDtoolbox/Metadata/SUNRGBD2Dg.mat'
labeltxt ="./"
imagepath ='./images'
labelpath ='./labels'
visualpath ='./visual'
for path in[imagepath, labelpath, visualpath]:
if ists(path):
os.makedirs(path)
bin_colormap = np.random.randint(0,255,(256,3))# 可视化的颜⾊
bin_colormap = bin_colormap.astype(np.uint8)
labels =[]
procesd =[]
# load the data from the matlab file
SUNRGBD2Dg = h5py.File(SUNRGBD2Dg_dir, mode='r', libver='latest')
SUNRGBDMeta = scipy.io.loadmat(SUNRGBDMeta_dir, squeeze_me=True,
struct_as_record=Fal)['SUNRGBDMeta']
glabel = SUNRGBD2Dg['SUNRGBD2Dg']['glabel']
# classlabels
g37list = SUNRGBD2Dg['g37list']
for i in range(g37list.size):
classstring = np.array(SUNRGBD2Dg[g37list[i][0]]).tostring().decode('utf-8')
classstring = place("\x00","")
print(classstring)
labels.append(classstring)
with open(labeltxt,'w')as f:
with open(labeltxt,'w')as f:
content =','.join(labels)
f.write(content)
for i, meta in tqdm(enumerate(SUNRGBDMeta)):
meta_dir ='/'.bpath.split('/')[:-2])
real_dir = meta_dir.split('/n/fs/sun3d/data/SUNRGBD/')[1]
rgb_path = os.path.join(real_dir,'image/'+ bname)
# rgbimage
srcname = osp.join(imgpath, rgb_path)
t ="sun_{}".bname)
dstname = osp.join(imagepath, t)
rgbimg = Image.open(srcname)
# labelimage
label = np.array(
SUNRGBD2Dg[glabel[i][0]][:].transpo(1,0)).\
astype(np.uint8)
labelname = osp.join(labelpath, t.replace(".jpg",".png"))
labelimg = Image.fromarray(label,'L')
labelimg.save(labelname)
# debug show
# plt.subplot(1, 2, 1)
# plt.imshow(rgbimg)
# plt.subplot(1, 2, 2)
# plt.imshow(labelimg)
# plt.show()
# visualimage
visualname = osp.join(visualpath, t.replace(".jpg",".png"))
visualimg = Image.fromarray(label,"P")
palette = bin_colormap #long palette of 768 items
visualimg.putpalette(palette)
visualimg.save(visualname,format='PNG')
可视化结果:
labellist
共有37个类别,
wall,floor,cabinet,bed,chair,sofa,table,door,window,bookshelf,picture,counter,blinds,desk,shelves,curtain,dresr,pillow,mirror,floor_mat,clothes,ceiling,boo ks,fridge,tv,paper,towel,shower_curtain,box,whiteboard,person,night_stand,toilet,sink,lamp,bathtub,bag
2. 关键点解析
2.1 h5py数据的解析
要先索引到,然后再从总的数据中读取SUNRGBD2Dg[]
np.array(SUNRGBD2Dg[glabel[i][0]][:].transpo(1, 0))
2.2 PIL灰度图以platte保存成彩图
关键是⽤:putpalette(palette)指定颜⾊
bin_colormap = np.random.randint(0,255,(256,3))# 可视化的颜⾊bin_colormap = bin_colormap.astype(np.uint8)
visualimg = Image.fromarray(label,"P")
palette = bin_colormap #long palette of 768 items
visualimg.putpalette(palette)
visualimg.save(visualname,format='PNG')