OpenCV: Pseudo Coloring of Images

Somehow I have fallen in love with Thermal Imaging. It is quite fascinating to see things differently via Infrared or Thermal Camera. I also like TEM,SEM and AFM (-microscopes) images which reveal a world of its own.


The key to carry out image manipulation such as this, lies in the method in which data is stored in memory and how these values are interpreted. Generally the pixel values of a Image is stored as a Single dimensional array in the memory. However complication/confusion arise when the image is multi channel.Ex: an RGB image.
If a 100x100 px Binay Image is present then it is clear that 100 x 100 = 10000 bits of linear space in memory is required.But if 100x100 px RGB image is to stored, then 100 x 100 x 3(for the channels R,G,B) x  n( Number of bits required to represent the max value) = 30000n bits are required.


The following Diagram explains clearly the arrangement in memory and how a single-channel pixels are mapped to multi-channel pixels.


Image: