Topics: Multidimensional Arrays & Image Files
Today's lab uses image manipulation to demonstrate multidimensional array commands.
For example, if we stored our image in the variable, img, we could access the red value by:
print "Upper left has red:", img[0,0,0]and the amount of green:
print "Upper left has green:", img[0,0,1]and the amount of blue:
print "Upper left has blue:", img[0,0,2]Any point can be accessed via its coordinates (i,j) and the color channel (0 for red, 1 for green, and 2 for blue).
What does this code do? Work through it first, and then try on your computer. This program assumes that you have a file called bf1.png in the same directory. You can use that file, or substitute one of your own.
import matplotlib.pyplot as plt import numpy as np img = plt.imread('bf1.png') #Read in image from bf1.png plt.imshow(img) #Load image into matplotlib plt.show() height = img.shape width = img.shape newImage = np.zeros((height,width,3)) for i in range(height): print "processing row", i for j in range(width): newImage[i,j,0] = img[i,j,0] newImage[i,j,1] = 0 newImage[i,j,2] = 0 plt.imshow(newImage) #Open window to show image (close to continue) plt.show() plt.imsave('face2.png',newImage)
newR = (r+g+b)/3 newG = (r+g+b)/3 newB = (r+g+b)/3
Landsat Satellite Program is a joint program of USGS and NASA that has provided continuous images of the earth since 1972. The data is publicly available through the USGS-EROS site and has been invaluable in mapping changes in the earth. Today, we will use data images from the USGS remote sensing gallery:
The gallery consists usually of pairs of images demonstrating change over time. Our challenges for today are:
For each lab, you should submit a lab report by the target date to: kstjohn AT amnh DOT org. The reports should be about a page for the first labs and contain the following:
Target Date: 23 March 2016
Title: Lab 7: Multidimensional Arrays and Image Files
Name & Email:
Purpose: Give summary of what was done in this lab.
Procedure: Describe step-by-step what you did (include programs or program outlines).
Results: If applicable, show all data collected. Including screen shots is fine (can capture via the Grab program).
Discussion: Give a short explanation and interpretation of your results here.
This course will use the on-line Rosalind system for submitting programs electronically. The password for the course has been sent to your email. Before leaving lab today, complete the first two challenges.