Bit-plane slicing (source code)

= Bit-plane slicing

\b[Bit-plane slicing] extracts the same bit position from every integer sample of a <digital image>, producing one binary image per <bit plane>. For an unsigned $n$-bit sample $p$ and $0\leq k<n$,
$$
b_k(p)=\left\lfloor\frac p{2^k}\right\rfloor\bmod2,
\qquad p=\sum_{k=0}^{n-1}2^kb_k(p).
$$
Equivalently, <bitwise AND> with the mask $2^k$ isolates that position, and a <bit shift> or nonzero test converts it to zero or one. Linux's frame-buffer API describes the underlying bit-plane storage convention as plane $k$ carrying bit $k$ of every sample.<The Frame Buffer Device API in the Linux Kernel documentation>[§2, FB_TYPE_PLANES]{ref}

For an original four-bit sample $p=13$, the binary digits are $1101$: the planes have $(b_3,b_2,b_1,b_0)=(1,1,0,1)$. Their contributions reconstruct $8+4+0+1=13$. Displaying each plane as a black-and-white image makes its pattern visible, but does not give every plane equal numerical significance.

\Image[/bit-plane-slicing-demo.png]
{title=An original four-bit image, two extracted <bit planes> and reconstruction from the two most significant planes}
{description=Every grid entry shows its integer value. The binary panels map zero to black and one to white; the input and reconstruction use the common zero-to15 grayscale. The alternating row pattern is visible in the least significant plane.}

Keeping only planes three and two gives $\widehat p=4\lfloor p/4\rfloor$. The discarded remainder satisfies $0\leq p-\widehat p\leq3$, by integer division. A one-unit change from seven to eight nevertheless flips every one of the four bits, so the binary patterns need not vary smoothly as intensity codes change. Nor is a low <bit plane> automatically noise: it can encode a deliberately structured pattern, as the example shows.

Slicing is an operation on the stated integer encoding. Applying it to a <floating-point number>'s stored bit pattern examines sign, exponent and fraction fields rather than the same unsigned intensity significance. The sample type and <pixel format> therefore belong in the definition of the operation.