[英]MATLAB: Reading both Bytes of a Unsigned 16-bit binary file
I have a binary Band Sequential (1-band, BSQ file), which is an unsigned 16-bit (2-byte) integer. 我有一个二进制Band Sequential(1波段,BSQ文件),它是一个无符号的16位(2字节)整数。
Currently I'm reading the whole (image) through multibandread : 目前我通过multibandread读取整个(图像):
img=multibandread('IMAGE.bsq',[400 400 1],'uint16',0,'bsq','n');
What process in MATLAB would allow me to read both bytes individually? MATLAB中的哪个过程允许我单独读取两个字节? ie I would like to read the file into 2 new arrays in MATLAB eg byte1 (400x400x1) and byte2 (400x400x1).
即我想在MATLAB中将文件读入2个新数组,例如byte1(400x400x1)和byte2(400x400x1)。
Can this be achieved through fread ? 这可以通过fread来实现吗? I note in the 'precision' section it is possible to skip source values (eg
'N*source=>output'
), but I'm unsure of the exact process. 我注意到在'precision'部分中可以跳过源值(例如
'N*source=>output'
),但我不确定确切的过程。
One way would be splitting your current img
with bitwise operations. 一种方法是使用按位运算拆分当前的
img
。 The LSB image would be: LSB图像将是:
img1 = bitand(img, 255); %// 0x00FF
and the MSB image would be: 和MSB图像将是:
img2 = bitsra(img, 8);
Not mandatory, but maybe you'll also want to convert these into uint8
s: 不是强制性的,但也许你也想将它们转换成
uint8
:
img1 = uint8(img1);
img2 = uint8(img2);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.