I seem to be unable to read in a 10bit image file using the following code:
fid = fopen(filename,'r'); data = fread(fid,inf,'ubit10');
If I were to look at the first few values, I would get something like this:
>> data(1:3) ans = 41 102 524
However, I happen to know the expected data:
>> known_data(1:3) ans = 280 163 218
Upon further investigation, I found out that the "fread" command is not doing what I expected. I figured this out by reading in 16-bit integers and then extracting the 10-bit values. Here is the horrid mess I came up with:
data = fread(fid,inf,'uint16'); temp = dec2bin(data(1:3),16); temp = [temp(1,:) temp(2,:) temp(3,:)] temp = 010001100000101000110011011010001000100001001000
fixed_data = [ bin2dec(temp(1:10)) bin2dec(temp(11:20)) bin2dec(temp(21:30)) ]
fixed_data = 280 163 218
Is there a better, more efficient way to do this? Or is it possible that I am using "fread" in correctly?
Thanks for any help in advance.