fread function for reading 10 bit raw file.
조회 수: 23 (최근 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에서 Computer Vision with Simulink에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!