This quiz must be submitted in Gradescope by 12:00pm CST on Tuesday, March 30, 2021.
This quiz covers the Python modules pillow and numpy as covered in Lectures 24--26.
Quizzes are INDIVIDUAL, closed book, and only allow access to specified resources. For this quiz you can access:
Because of spring break, it's been a while since you completed Worksheet 10. Reading through the solutions would probably be a good idea.
There are two problems on this quiz, numbered 2 and 3. The point breakdown is:
Points | Item |
---|---|
3 | autograder |
4 | problem 2 |
4 | problem 3 |
11 | total |
Write a program that reads a color bitmap image (mode RGB) from a file, finds all pixels that are pure bright red (value (255,0,0)
), and changes such pixels to pure bright blue (value (0,0,255)
). All other pixels should remain unchanged. The modified image should then be saved to an output file.
The program should take two command line arguments:
In case you'd like to test your program, here are a pair of images that provide sample input and expected output. You'll want to download them and save them wherever you work on your quiz code.
Save your program to quiz10prob2.py
and upload it to Gradescope.
For this quiz problem, you need to add explanatory comments to a given code sample.
To explain what is expected, here is an example. The following program makes a numpy array and prints some parts of it.
# Undocumented sample
import numpy as np
A = np.arange(35).reshape(5,7)
print(A[:,2])
print(A[4,3])
Here is a documented version of the same program, where every line of code is explained by a comment above it.
# Documented sample
import numpy as np
# Arrange the integers 0...34 in a matrix
# with 5 rows and 7 columns. Square each
# one and add 10.
A = np.arange(35).reshape(5,7)**2 + 10
# Print column 2 of the matrix
print(A[:,2])
# Print the average (arithmetic mean) of
# all the entries of the matrix
print(np.mean(A))
Notice that each comment is detailed enough that if you were only given the contents of the comment, you would be able to re-create the corresponding code. (In normal programming practice you wouldn't use this many comments, nor include this much detail, but I am showing what is expected in this problem.)
Add the same kind of explanatory comments to the following program:
# Add a detailed explanatory comment above each line of code.
import numpy as np
B = np.arange(13,43,5) + np.arange(30).reshape(5,6)
print(np.sum(B[::2,2::3]))
print(B[1:3]**2 - 1)
Put your documented version of the program in a file quiz10prob3.py
and submit it to gradescope. (Remember to add the required header and a docstring so it confirms to the course coding standards.)