Processing Kinect Depth data in MATLAB - matlab

So I used Kinect to obtain some depth images and they are now saved. So if I want to process this depth image to get the Z value (i.e. the distance from the object to the Kinect) how should I do that?
I have been doing some research online and found out that I need to be saving the image as a 16bit depth image for the depth values to be stored instead of an 8 bit depth image which can only store up to 256 values. based on: Save Kinect depth image in Matlab?
But I still do not quite understand the image I am getting. When I use imread and uses the data cursor to look at the individual pixels, I only obtain the XY coordinates and an Index value. the index value does not seem to represent the distance in mm.
Can anyone clear this part for me please.
Thanks.

looks like your are reading an indexed image with imread()
try this:
[idx, map] = imread('yourImage');
RGB = ind2rgb(idx, map);
and see if RGB contains the correct value.

Related

MATLAB imread() wrong gray scale

I made a simple grayscale image with paint.net:
Then I simply read the image using MATLAB imread() and got something like this (same thing for Octave):
I checked the background value and it's 55 instead of 255.
I then tried the same thing in Python using pyplot.imread() and get the expected result:
I saw this a couple of times even when I was reading something like Lena in MATLAB -- the gray scale was totally messed up. Does anyone know what's wrong with imread in MATLAB (and Octave)?
Your PNG image is an RGB image, not a gray-value image. It was saved as an indexed image, meaning that 56 different RGB values were stored in a table, and the image references those RGB values by specifying an index for each pixel.
The image you're seeing consists of the indices into the color table, not the actual RGB values saved.
You need to read both the indices and the color map as follows:
[img,cm] = imread('https://i.stack.imgur.com/rke2o.png');
Next, you can recover the original RGB image using ind2rgb, or, given that you are looking for a gray-value image, you can recover the gray-values using ind2gray:
img = ind2gray(img,cm);

Depth Image in Matlab

I have a depth image taken from Kinect V2 which is given below. I want to extract the pixel value x at any specific coordinate and its depth value in Matlab. I used the follwing code in Matlab but it gives me 16-bit value. However, I'm not sure is it pixel value or depth value of pixel x.
im=imread('image_depth.png');
val=im(88,116);
display(val);
Result
val= (uint16) 2977
Would someone please help me that, how to extract both pixel and depth value in Matlab?
The image name hints it is a depth map. The color map is stored usually in separate file usually in different resolution and with some offset present if not aligned already. To align RGB and Depth images see:
Align already captured rgb and depth images
and the sub-link too...
The image you provided peaks with color picker the same 0x000B0B0B color for the silhouette inside. That hints it is either not Depth map or it has too low bit-width or the SO+Brownser conversion lose precision. If any pixel inside returns the same number for you too then the depth map is unusable.
In case your peaks returns 16 bit value it hints RAW Kinect depth values. If the case see:
Kinect raw depth to distance in meters
Otherwise it could be just scaled depth so you can convert your x value to depth like:
depth = a0 + x*(a1-a0)
where <a0,a1> is the depth range of the image which should be stated somewhere in your dataset source ...
From your description, and the filename, the values at each location in your image are depth values.
If you need actual color values for each pixel, they would likely be stored in a separate image file, hopefully of the same dimension.
What you are seeing here is likely the depth values normalized to a displayable region with MATLAB or your picture viewing software.
You will need to look at the specs to see how a value like 2977 converts to the physical world (e.g. cm). Hopefully it is just a scalar value you can multiply to get that answer.

about read kinect depth information from matlab

I am using MATLAB 2015a
I get the snapshot of kinect depth video from Kinect with format of .fig However,when I use data cursor to get the depth information, it shows different type of number, it indeed confuse me.
[X Y]:[402 174]
index: 3201
[R G B]: [0.7843 0.7843 0.7843]
what does index specifies? does INDEX specifies the physical distance of that data cursor point from kinect camera?
Thanx !
Index is the distance to the camera plane in millimeters.
Note: If you want to do processing, you may want to try to get the depth data as an array, rather than as a .fig. If all you have is the .fig (and it's open and active), you can get the depth array as depth = get(gcf,'CData')

Kinect v2 sensor Color-Depth Mapping misalignment using matlab [duplicate]

I have collected data using Kinect v2 sensor and I have a depth map together with its corresponding RGB image. I also calibrated the sensor and obtained the rotation and translation matrix between the Depth camera and RGB camera.
So I was able to reproject the depth values on the RGB image and they match. However, since the RGB image and the depth image are of different resolutions, there are a lot of holes in the resulting image.
So I am trying to move the other way, i.e. mapping the color onto the depth instead of depth to color.
So the first problem I am having is that the RGB image has 3 layers and I have to convert the RGB image to grayscale to do it and I am not getting the correct results.
Can this be done?
Has anyone tried this before?
Why can't you fit the Z-depth to the RGB?
To fit the low res image to the high- res should be easy, as long as both represent the same size of data (i.e. corners of both images are the same point)
It should be as easy as:
Z_interp=imresize(Zimg, [size(RGB,1) size(RGB,2)])
Now Z_interp should have the same amount of pixels as RGB
If you still want to do it the other way around, well, use the same approach:
RGB_interp=imresize(RGB, [size(Zimg,1) size(Zimg,2)])
The Image Acquisition Toolbox now officially supports Kinect v2 for Windows. You can get a point cloud out from Kinect using pcfromkinect function in the Computer Vision System Toolbox.

Mapping Depth onto RGB Kinect using MATLAB

I am trying to map the Depth map onto the RGB image on the Kinec using MATLAB.
So here are the steps that I took:
(1) Obtain the images using a C++ program.
(2) Using the depth value from each pixel on MATLAB, I was able to obtain the XYZ distances of all the pixels in mm.
(3) Then using some equations, I was able to obtain the XY pixel coordinates of those depth pixels on the RGB image.
So I am left with a huge cell containing all the locations of the depth map w.r.t the color image.
So my question is now if I want to overlay the depth image on the color image, how can I do that?
Can anyone help me?
Thanks;