📚 The CoCalc Library - books, templates and other resources
License: OTHER
Exercise: draw the letter H
Define a function that takes as input an RGB image and a pair of coordinates (row, column), and returns a copy with a green letter H overlaid at those coordinates. The coordinates point to the top-left corner of the H.
The arms and strut of the H should have a width of 3 pixels, and the H itself should have a height of 24 pixels and width of 20 pixels.
Start with the following template:
Test your function like so:
Exercise: visualizing RGB channels
Display the different color channels of the image along (each as a gray-scale image). Start with the following template:
Now, take a look at the following R, G, and B channels. How would their combination look? (Write some code to confirm your intuition.)
Exercise: Convert to grayscale ("black and white")
The relative luminance of an image is the intensity of light coming from each point. Different colors contribute differently to the luminance: it's very hard to have a bright, pure blue, for example. So, starting from an RGB image, the luminance is given by:
Use Python 3.5's matrix multiplication, @
, to convert an RGB image to a grayscale luminance image according to the formula above.
Compare your results to that obtained with skimage.color.rgb2gray
.
Change the coefficients to 1/3 (i.e., take the mean of the red, green, and blue channels, to see how that approach compares with rgb2gray
).