Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

An RGB image is encoded in the form of a three-dimensional array: the first two dimensions are the spatial dimensions of the image, the third corresponds to the bands.

  • Create the array corresponding to the RGB image 40×8040 \times 80 sketched Figure 1:

    A simple image.

    Figure 1:A simple image.

    To do this, create first a black image with the correct dimensions (numpy.zeros generates an array filled with zeros). Then assign the desired value to the elements of the matrix, proceeding band by band, by using for example:

    f[m1:m2, n1:n2, b] = x

    This statement assigns the value x to the pixels of the band b located between the rows m1 and m2-1 and the columns n1 and n2-1 (in Python, indices starts at 0).


Correction

Objectives

  • Synthesize an RGB image (and know, for example, that yellow = green + red).

  • Manipulate the value / color correspondence.

  • Use the : operator.

Image synthesis

As usual, do not forget the modules:

The image is composed of blocks of homogeneous color with size 20 × 20 pixels, so as to form an image of 40 × 80 pixels. Also, it contains three bands as it is an RGB image. Therefore we create an array f of size 40 × 80 × 3:

We use Additive color to create the colors. Thus, yellow is obtained by combining green and red.

The bands can be displayed separately:

<Figure size 1500x700 with 3 Axes>

And finally the color image:

<Figure size 640x480 with 1 Axes>