I have a binary Band Sequential (1-band, BSQ file), which is an unsigned 16-bit (2-byte) integer.
Currently I'm reading the whole (image) through multibandread:
img=multibandread('IMAGE.bsq',[400 400 1],'uint16',0,'bsq','n');
What process in MATLAB would allow me to read both bytes individually? i.e. I would like to read the file into 2 new arrays in MATLAB e.g. byte1 (400x400x1) and byte2 (400x400x1).
Can this be achieved through fread? I note in the 'precision' section it is possible to skip source values (e.g. 'N*source=>output'
), but I'm unsure of the exact process.
One way would be splitting your current img
with bitwise operations. The LSB image would be:
img1 = bitand(img, 255); %// 0x00FF
and the MSB image would be:
img2 = bitsra(img, 8);
Not mandatory, but maybe you'll also want to convert these into uint8
s:
img1 = uint8(img1);
img2 = uint8(img2);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With