fread function for reading 10 bit raw file.
22 次查看(过去 30 天)
显示 更早的评论
When I read 10 bit raw file in fread as Uint16 and as uint8 the size of the data is doubled in case of reading as uint8. Wanted to know how fread function internally reads 10 bit data in uint8 and uint16 data type.
sample of my code below:
fid = fopen('2.raw');
data = fread(fid,'uint16');
fclose(fid);
0 个评论
采纳的回答
Peter O
2022-3-10
编辑:Peter O
2022-3-10
To confirm, you're saying that result of importing the file as UINT8 is double the array size as importing as UINT16? That's to be expected. uint8 will read in blocks of 8 bits from your file (range 0 to 255; e.g. one byte) sequentially, while uint16 will read in blocks of 16 bits (range 0 to 65536, two bytes). If your file is 96 bytes long, then you'll see 96 8-bit values, but only 48 16-bit values.
If you look at their sizes you'll likely see that the array bytes are the same. Each 16-bit value storage uses twice as many bytes.
a = uint8([1,2,3,4]);
b= uint16([1,2]);
whos;
Edit:
Important detail I left off: Since you have 10 bit data, assuming it's in block form, neither method is going to import your data correctly, because it does not know that directly. See the documentation for fread. You'll want to specify the bitn version. Use '*ubit10' instead of to place the 10-bit data into uint16 format for MATLAB to use.
data = fread(fid,'*ubit10');
更多回答(1 个)
Jan
2022-3-10
If the 10bit data are written as bitstream, 8 numbers use 10 bytes. If you read this as UINT8 or UINT16 does not matter: the sequence of bits in the memory is equal. If these bits are interpreted as UINT8 or UINT16 will change the values, of course.
A difference is that the number if bytes need not be even, such that reading the file as UINT16 might skip the last byte.
To import the data use the fomat UBIT10:
fid = fopen('2.raw');
data = fread(fid, 'ubit10=>uint16');
fclose(fid);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Processing Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!