First, I want to thank s-gupta for his excellent work. Actually, I got some inspiration from his code and fixed some problems in it.
This repo is used to convert Depth images into HHA images. HHA is an encoding method which extract the information in the depth image which was proposed in Learning Rich Features from RGB-D Images for Object Detection and Segmentation. In this repo, I use NYU Depth V2 dataset as an example.
All we need is:
- A depth image
- (Optional) A raw-depth image
1. Modify main.m
depth_image_root = './depth' % dir where depth and raw depth images are in. saveHHA([mat2str(i-1), '_hha'], matrix, depth_image_root, D, RD);
depth_image_root is the directory of where depth images are in. The path of HHA can be defined by yourself by modifying parameters of ***saveHHA(imName, C, outDir, D, RD)***.
imName : name of HHA.
C : camera matrix
outDir : root of HHA images
D and RD : depth and raw-depth images. The raw-depth images are just used as masks, which you can understand from the corresponding code. So I both use depth images as this two parameters just for converience.
2. Modify saveHHA.m
Look at this line.
D = double(D)/10000;%./1000; The unit of the element inside D is 'centimeter'
Here, D is the depth image. You may confused about the number '10000'. Because when I save the depth data as 'png', I multiply it with 10000. We all know that float number can not be saved as png or jpg, so I scale it. Anyway, after this line, the unit of the element in D should be 'meter'. It's up to you how to convert it.
You can directly run main.m to use this repo.
Pictures below are RGB, Depth, Raw-depth, HHA in turn.