MATLAB: Reading 10bit raw image in Matlab

bitfread

I have a 10bit raw image (input.yuv) and would like to read it in Matlab. To do so, I am using the following commands:
fid = fopen('input.yuv','r');
a = fread(fid,'uint16');
fclose(fid);
When I get the max(a(:)), it is 730. However, I have white pixels in the image. My question is that:
  1. To get the image data between 0 and 1, should I divid them by (2^16-1) or (2^10-1). The original content is 10bit.
  2. Why I don't get (2^10-1 or 2^16-1) for the white pixels?

Best Answer

You have not decoded the yuv to its 4:4:2 components.
YUV with 8 bits per channel does not use the full range of values for any component. Also, white is not encoded as the largest possible value: white is U component and V component 0 (they are signed) which gets stored as YCrCb with Cr and Cb = 128 each https://en.m.wikipedia.org/wiki/YUV