Question 2. Bitmap Image Processing
A bitmap image is a matrix of pixels. Each pixel holds a color value, which can be coded with the RGB (Red, Green, Blue) convention: a color value is a vector -->c = (r, g, b) where r, g and b are real numbers between 0 and 1. Equivalently, we can see the bitmap image as a triple (R; G; B), where R, G, B are three matrices containing the red, green and blue values respectively. The following example shows both representations of a 3 × 2 pixels bitmap image.
In this exercise, we test matrix operations on those colorful matrices.
(a) Choose a nice colorful photo (or use the classical one provided with the assignment) in PNG format and import it in Sage by executing the provided pieces of code. This will give you three matrices R, G and B as described above. Show your picture with the provided rgbplot function (which you can reuse in the next parts).
(b) Grayscale colors are the RGB triples of the form (x, x, x). We can therefore turn any picture into grayscale by calculating a weighted average x of the three colors on each pixel. A good average you may use is: x = 0.3r + 0.59g + 0.11b. Convert your picture to grayscale and show it with rgbplot.
(c) Given a color (r; g; b), its inverse color is the RGB triple (1 − r, 1 − g, 1 − b). Invert the colors of your picture and show the resulting inverted picture. (d) Calculate the transpose of your image and show it. What geometric transformation does this represent?
(e) A horizontal flip of a bitmap picture is a reflection of the picture about a vertical axis located in the center of the picture. Calculate the horizontal flip of your picture and show it.
(f) Rotate your picture by 90◦
counterclockwise, and show the result.
Students succeed in their courses by connecting and communicating with an expert until they receive help on their questions
Consult our trusted tutors.