Save Kinect depth image in Matlab?
Asked Answered
R

2

6

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.

Robles answered 12/6, 2011 at 18:18 Comment(0)
M
8

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.

Mccue answered 13/6, 2011 at 7:13 Comment(0)
F
2

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

Forefather answered 12/6, 2011 at 19:48 Comment(2)
Thank you very much for your advice. It is a nice suggestion to use ln function for scaling. However, consider Depthimage = 100. Then ln(100-49)*25 = 7.15. When value 7.15 7.15 is stored in a matrix (as an image), it become 7.00. And if I apply reverse function, I will get 92.86. I lost my precision.Robles
Anyway, I will use save() and load()Robles

© 2022 - 2024 — McMap. All rights reserved.