Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Save Kinect depth image in Matlab?

By using Kinect, I can get depth image in which each depth image pixel store the distance(in millimeter) between camera and object. Now I want to save them so that I can use later. What is the best recommendation?

I am thinking to save the depth image as an image (jpg/png, etc). However, the value is usually from 50 mm to 10000 mm while the normal image element can store from 0-255. Then I will need to scale the data to range 0-255 and that may exploit the data somehow.

like image 833
John Avatar asked Jun 12 '11 18:06

John


2 Answers

You can use any format like tiff or png that supports 16 bit grayscale images, since your data will fit in a 16 bit (2^16-1=65535).

The advantage of using these formats is of course that you will be able to read them using another program. You will most probably not want to use the jpeg format because of compression artifacts.

Here's what the matlab documentation says about imwrite for the png format:

By default, imwrite uses 8 bits per pixel, if image is double or uint8; 16 bits per pixel if image is uint16; 1 bit per pixel if image is logical.

So you'll be already fine if you have your data stored as uint16.

like image 137
brbr Avatar answered Nov 17 '22 09:11

brbr


You can store the matrix directly to disc using command save() and load(). But then only matlab will be able to read it. This is the best choice since you do not lose precision at all.

If you must scale the values to 0..255 then dont scale it linearly. You need higher precision for closer object. So just apply the following function to the matrix ln( DepthImage - 49)*25 to get roughly 0..255 values. Now save the image and when you load it apply reverse function. In such way (using lan function) your precision will be harmed less

like image 27
DanielHsH Avatar answered Nov 17 '22 09:11

DanielHsH