Saving kinect depth frame(uint16) but Why it is too dark ?
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Recently I works on kinect using matlab. I take depth frame which is in uint16 format. But when I display it or save it using matlab command like: imshow & imwrite respectively, it shows too dark image.But when set the display range or convert it in uint8 format it becomes brighter.But i want to save it as a brighter format without converting in uint8 format like setting the range between 0 to 4500.
vid = videoinput('kinect',1);
vid2 = videoinput('kinect',2);
vid.FramesPerTrigger = 1;
vid2.FramesPerTrigger = 1;
% % Set the trigger repeat for both devices to 200, in order to acquire 201 frames from both the color sensor and the depth sensor.
vid.TriggerRepeat = 200;
vid2.TriggerRepeat = 200;
% % Configure the camera for manual triggering for both sensors.
triggerconfig([vid vid2],'manual');
% % Start both video objects.
start([vid vid2]);
trigger([vid vid2])
[imgDepth, ts_depth, metaData_Depth] = getdata(vid2);
f=imgDepth;
figure,imshow(f);
figure,imshow(f,[0 4500]);
imwrite(f,'C:\Users\sufi\Desktop\matlab_kinect\Data_image\output\depth\fo.tiff');
stop([vid vid2]);
When i set display range:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165474/image.png)
Wihtout setting display range:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165475/image.png)
When i save the image in PNG format:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/165478/image.png)
0 comentarios
Respuestas (1)
Walter Roberson
el 24 de Jun. de 2017
You can construct
new_image = im2uint16(mat2gray(imgDepth));
The result will be a 2D image that is 16 bits per pixel and for which the maximum value is 65535 with all other values scaled appropriately.
However, the resulting image will be all relative values, not values useful for finding absolute depth. Absolute depth values happen to come out the way you have noted -- at least unless you want to make it into an indexed image in which the indices are the absolute values and you include a colormap that displays it brighter.
4 comentarios
Walter Roberson
el 25 de Jun. de 2017
imshow(f,[0 4500]) is for display purposes, and it effectively works as:
low = 0; high = 4500;
temp = double(f);
temp(temp < low) = low;
temp(temp > high) = high;
temp = (temp - low) ./ (high - low); %now it is the range 0 to 1
image(temp);
colormap(gray);
except that the actual implementation is much more
low = 0; high = 4500;
image(temp);
caxis([low, high]);
colormap(gray);
where caxis has the same effect as the computation I showed.
That is, in order to get the brightness you want, the data has to be manipulated internally to be scaled to be in the range 0 at the low value you want and 1 at the high value you want, for display purposes. That is fine for internal display purposes, but the result is not the absolute data values you need.
The code I posted that computes cmap and writes to the tiff file, results in a tiff file that holds the original absolute data and also holds information saying how each of those absolute data values is to be represented as a brightness.
If you want to duplicate the visual effect of imshow(I, [0 4500]) you could use
maxdepth = 4500;
relative_depths = min(1, (0:65535).' ./ maxdepth);
cmap = [relative_depths, relative_depths, relative_depths]; %greyscale
imwrite(imgDepth, cmap, 'fo.tiff');
This should work in any viewer that supports large color maps. In MATLAB you would
[depth_in, cmap_in] = imread('fo.tiff');
image(depth_in); colormap(cmap_in);
Your cmap_in will end up with 65536 entries, most of which will be 1.
The way to indicate in an image file that the absolute value of the data is not the same as how that data should be displayed is to associate a colormap.
Ver también
Categorías
Más información sobre Kinect For Windows Sensor en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!