Marla Geha from Yale University taught a short course in Singapore at Yale-NUS College. This tutorial comes from her and is a great way to get started using Python. More information from her short course at Yale can be found at this link: http://www.astro.yale.edu/mgeha/Singapore/
Also the images needed for this exercise are at the bottom of the tutorial.
Download the images puzzle1.png and puzzle2.png from the class website (linked below). Open ipython in the same directory and display each image. I suggest you read and display the images using the following commands:
import matplotlib.pyplot as plt from matplotlib.image
# Read in image
img = imread(‘puzzle1.png’)
# Display image
imgplot = plt.imshow(img)
You can type these commands directly into the python command, or run the example.py code which reads/displays puzzle1 (>>> run example.py). The image has been read into an array called img. This array has three columns of data corresponding to red, green and blue colors. See http://matplotlib.org/1.3.1/users/image_tutorial.html for more details on the structure of this array.
These files contains an image of something famous, however the image has been distorted. For puzzle1, the famous object is in the red values, however the red values have all been divided by 10. The blue and green values are all meaningless random values (“noise”) added to obscure the real image. You must undo these distortions to reveal the real image. First, set all the blue and green values to 0 to get them out of the way. Look at the result. If you look very carefully, you may see the real image, although it is very dark (way down towards 0). Then multiply each red value by 10, scaling it back up to approximately its proper value. What is the famous object?
For puzzle2, the famous object is in the green and blue values, however, these have been divided by a factor of 20. The red values are meaningless random values. Solve this puzzle similar to above. What is this famous object?
The resources for this tutorial are below.
image above is “puzzle1.png” – download and save with that name
image above is “puzzle2.png” – download and save with that name
example.py – copy and save as example.py to run