c++opencvimage-processingcomputer-visiongray-code

How to obtain this result from a 256 bits monochrome picture?


I just found this image in the book I am studying for Computer Vision (Digital Image Processing by Rafael C. Gonzalez and Richard E. Woods):

image showing picture transformed in different ways

The book does not explain how to reach this result, and I was wondering how I could reach the same results on other images.

The context in which I found the picture on the book is "block transform coding with the DFT, WHT, and DCT". The text near the image says:

(a) A 256-bit monochrome image.
(b)–(h) The four most significant binary and Gray-coded bit planes of the image in (a).

Do you know any possible way to reach this weird result?


Solution

  • Here are binary "bit planes".

    If you have questions on Gray code, please first read up on it. Then we can discuss that. The ideas aren't much different from binary code.

    That photo of a book page you have there... shows the planes of some source image. Noise in the source image becomes successively more apparent in the lower planes.

    Noise, through various copying and printing steps that act like a lowpass, turns into grayscale. That's why only the highest planes show fairly clean edges and flat black/white.

    Note that each plane is stretched to be fully black or white. If I didn't do that, you'd just get ever darker pictures, the further down the bits you go.

    im = cv.imread(cv.samples.findFile("lena.jpg"), cv.IMREAD_GRAYSCALE)
    
    for k in range(8):
        title = f"bit position {k}, value {2**k}"
        plane = ((im >> k) & 1)
        cv.imshow(title, plane * 255)
        cv.waitKey()
        cv.destroyWindow(title)
    

    bit 7 bit 6

    bit 5 bit 4

    bit 3 bit 2

    bit 1 bit 0


    plane = (im & (1 << k)) # and no scaling by 255
    

    bit 7 bit 6

    bit 5 bit 4