Topics: Multidimensional Arrays & Image Files

Today's lab uses image manipulation to demonstrate multidimensional array commands.

Image files

There are many different formats to store images. Some store the information about the color of every pixel ("picture element" or dot on the screen). Others store end points of lines or boundaries of regions and the colors of each. We focus on the former, and in particular, use the png (portable network graphics) file format, which is popular for storing images captured from cameras and is `lossless' (every pixel captured is stored, so, can also be quite large). Each pixel is represented by its the percentage of red, green, and blue ("RGB") values. Images are stored as a grid of red values, a grid of green values, and a grid of blue values.

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[0]
width = img.shape[1]
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)

Challenges:

Landsat Satellite Data

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:

http://remotesensing.usgs.gov/gallery/

The gallery consists usually of pairs of images demonstrating change over time. Our challenges for today are:

Lab Report

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.

Using Rosalind

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.