Displaying an image#

Displaying an image needs to convert the pixel intensities \(\{i_1,\dots,i_B\}\) into gray levels or colors. Screens are basically a matrix of pixels, each composed of red, green and blue luminophores (the shape, size and number of luminophore depends of the technology). Colors can be recreated by tuning the luminophore intensities, thanks to the principles of additive color. The correspondance between the numerical value of the intensities and colors on the screen is visually reprensented by a colormap.

Displaying a 2D grayscale image#

A 2D grayscale image is an array with \(d=2\) dimensions where each pixel contains a scalar (\(B=1\)). Therefore, each pixel is displayed with a specific gray level. Fig. 16 shows the same image with different colormaps. As you can see, the choice of the colormap changes the perception of the colors, even though the information contained by the pixels remains unchanged.

../_images/colormaps.svg

Fig. 16 An image showing Buzz Aldrin displayed with the colormaps given below the images.#

Colormaps are sometimes useful to bring out dark objects in an image with poor contrast. The code below shows an image with one bright spot, clearly visible on the first image, along four faint spots which are not visible with the usual colormap “gray”. However, the socalled “jet” colormap makes the faint spots visible. Also, displaying the logarithm of the image helps to make the spots visible (see Histogram transformations).

import numpy as np
import skimage.io as io
import matplotlib.pyplot as plt

# Load the image
img = io.imread("../_static/figs/spots.png")

# Prepare the figure with three images
fig, axs = plt.subplots(1, 3, figsize=(15, 5))

# Display the image with colormap gray
axs[0].imshow(img, cmap="gray")
axs[0].set_title("Colormap 'gray'")

# Display the image with colormap jet
axs[1].imshow(img, cmap="jet" )
axs[1].set_title("Colormap 'jet'")

# Display the logarithm of the image
img_log = np.log(1. + img)
axs[2].imshow(img_log, cmap="gray")
axs[2].set_title("Logarithm with colormap 'gray'")

# Show the figure
plt.show()
../_images/35974d11b9b3442a6142b3ee77aa8224be8b0708ebdd08e0f1a030da8ef68c99.png

Displaying a 2D color image#

As we have seen in Human vision, the retina of human eye contains three kinds of cone cells which are basically sensitive to blue, green and red light. So, a color image is simply a composition of the intensities of this three wavelength, so that \(B=3\). Each of this three bands codes the intensity of red, green and blue lights of the image, hence the name RGB (red, green, blue). This is why digital screens are made of red, green and blue luminophores, which are small dots composing the pixels.

Displaying other types of images#

There is no easy way to display an image which is not a 2D grayscale or RGB image. Such image are either not displayed, or displayed by using a specific representation. For example, only three bands can be selected and displayed as an RGB image. Another possibility is to gather the bands into three groups and compute the means within each group, with these means becomint the three bands of a standard RGB image.