s-gupta / rcnn-depth

Learning Rich Features from RGB-D Images for Object Detection and Segmentation
BSD 2-Clause "Simplified" License
365 stars 150 forks source link

groundTruth data to png request #45

Closed matthewchung74 closed 5 years ago

matthewchung74 commented 5 years ago

Is it possible to save the groundTruth files as pngs? I unfortunately don't have matlab.

matthewchung74 commented 5 years ago

for interpreting the masks, I'm still not sure how to tell what is what based on the rgb value, but for reading the files, here is what I ended up doing.

import scipy
from scipy import io
from PIL import Image as PILImage
import os

def modify_image_name(path, ext):
  return os.path.basename(path).split('.')[0] + '.' + ext

def mat2png_hariharan(mat_file, key='GTcls'):
  mat = io.loadmat(mat_file, mat_dtype=True, squeeze_me=True, struct_as_record=False)
  return mat[key].Segmentation

mat = 'groundTruth/img_5007.mat'
numpy_img = mat2png_hariharan(mat, 'groundTruth')

pil_img = PILImage.fromarray(numpy_img)
pil_img = pil_img.convert('RGB')
pil_img.save(os.path.join('./', modify_image_name(mat, 'png')))