0

Recently I work 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 scaling 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 the display range:

When I set display range:

Without setting the display range:

Without setting display range:

Sardar Usama
  • 19,536
  • 9
  • 36
  • 58
sufi
  • 1
  • 4
  • 1
    That probably happens because uint16 ranges from 0 to 65535, while uint8 ranges from 0 to 255, so when you convert to uint8 the values are being clamped. What you probably want to do is scaling your values from 0 to 65535 before saving in order to take advantage of the full range of the 16 bits – jmds Jun 25 '17 at 00:11
  • but when i set display range it looks brighter.i dont need to convert it in uint8. I need uint16 which i get from sensor but it is too dark to visulalize. nothing clearly shown... thats the probelm....I need to visualize this image in my ppt – sufi Jun 25 '17 at 06:26

2 Answers2

0

The values in a 16bit image range from 0 to 65535.

If we take a look at the histogram of your image:

enter image description here

We see that the max value is 7995. But that's just a few outliers. Most information is somewhere between 700 and 4300.

So all our values are in 5-10% of our value range. That makes it look very dark.

In order to make it look better for humans we have to normalize it. (Some image viewer do this automatically).

So in order to get a nicer image into your power point presentation you have two options.

a) display it in an image viewer that can display it nicely and take a screenshot

b) normalize the image in matlab and save it to a file.

You can further improve the image by removing those outliers befor normalization.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • But sir how can i normalize it. I have no idea... please tell what changes i make in my code – sufi Jun 25 '17 at 15:32
  • @sufi is it too much to ask that you google "image normalization matlab"? you won't have any success in programming if you expect to be spoon-fed everything. you should know how to normalize a matrix in matlab. if not stop what you are doing right now and learn the very basics of matlab. you can normalize an image through matrix operations or by using provided image processing functions. – Piglet Jun 26 '17 at 06:55
0

One simple way can be scaling the image based on following formula:

    Pixel_value=Pixel_value/4500*65535

If you want see the exact image that you get from uint8 ; I guess the following steps will work for you.

Probably while casting the image to uint8 matlab firstly clip the values above some threshold lets say 4095=2**12-1 (i'm not sure about value) and then it makes right shifts (4 shifts in our case) to make it inside the range of 0-255.

So i guess multiplying the value of uint8 with 256 and casting it as uint16 will help you get the same image

        Pixel_uint16_value= Pixel_uint8_value*256 //or Pixel_uint16_value= Pixel_uint8_value<<8 
        //dont forget to cast the result as uint16
MIRMIX
  • 1,052
  • 2
  • 14
  • 40