Saving kinect depth frame(uint16) but Why it is too dark ?

2 Ansichten (letzte 30 Tage)
sufian ahmed
sufian ahmed am 24 Jun. 2017
Kommentiert: Walter Roberson am 25 Jun. 2017
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:
Wihtout setting display range:
When i save the image in PNG format:

Antworten (1)

Walter Roberson
Walter Roberson am 24 Jun. 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 Kommentare
sufian ahmed
sufian ahmed am 25 Jun. 2017
Bearbeitet: sufian ahmed am 25 Jun. 2017
May b i cant express my problem clearly. sorry for that.First of all what i want to do ...i want to take the distance between sensor and pixel. now in depth image [x,y]=val is the distance.. so i draw a vertical line upon it and get the distance in intersecting point, all are ok...but image looks so darker.it looks odd to watch. but in kinect matlab video, they do something like: using display range(figure,imshow(f,[0 4500]);) to show brighter. but i only can show it but cant save it as the brighter looks. how can i do that ? and what they did actually using display range.They say something kinect works better in range 0 to 4.5 m. so they do that...really confused.
Walter Roberson
Walter Roberson am 25 Jun. 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.

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by