MATLAB: How to Deinterleave the 16-bit Byte-Interleaved Image Data

16-bit8-bitdeinterleaveinterleave

Suppose that I have an image matrix I (m by n), with each pixel as a 16-bit value.
What I would like to do is to extract the first 8 bits of each element to form a new matrix A, and extract the last 8 bits of each element to form a new matrix B.
For instance, I[1][1] could be 65280 (convert to binary: 1111111100000000). In this case, A[1][1] = 11111111, and B[1][1] = 00000000. And this will apply to all the elements to extract A(m by n) and B(m by n) from I(m by n).

Best Answer

A = floor(I/256);
B = mod(I, 256);