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)
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:
http://remotesensing.usgs.gov/gallery/
The gallery consists usually of pairs of images demonstrating change over time. Our challenges for today are: