This preview shows page 1. Sign up to view the full content.
Unformatted text preview: 11/19/2008 Announcement ECS 10
11/18 Midterm Midterm grades should be available later this week. Solutions later today on myUCDavis. myUCDavis. Final Final program will be due Dec 3. Image Image Processing
What’s What’s the difference between graphics and image processing? Gears Gears of War is computer graphics – synthetically synthetically created images. Photoshop Photoshop is image processing – altered photographs. Binary Binary Files
All All of the data we have been working with is in text files. Lots Lots of data is text: .tsv, .rtf, .html .tsv, Lots of data is not a text file: pictures, movies, songs, songs, Word documents. NonNon-text files are known as binary. binary A misnomer, since text is binary too. misnomer, Every Every character is a binary number between 0 and 255 (eight bits). All All Data is Binary
Variable Variable is a box, labeled with name and also type. All Data is Binary
Variable Variable is a box, labeled with name and also type. 00100011 00100011 char (type: string) char (type: string) 1 11/19/2008 All Data is Binary
The ord() The ord() function just changes the label. num = ord(‘a’) 00100011 num (type: int) Reading Binary Data
Using readline() Using readline() trys to interpret everything as a string. Mostly Mostly does not make sense. Writing a program to read most kinds of binary binary data is a big job. Fortunately Fortunately somebody probably already did it, and published a module. Image Image Data
Many Many image file formats. Can you name some? Differ Differ in how they compress the data. The The same image is different sizes in different formats! Both Both are lists of binary numbers. But very different. Programs Programs that read them (Irfanview) know (Irfanview) from the file type how to interpret the data. Basic Basic Image Format Idea
List List of pixels. Every Every pixel has a color. Each Each color is represented by three binary numbers, between 0 and 255 (eight bits). 255 One One pixel: [ 44, 12, 0] A list of pixels: [ [44, 12, 0], [6, 35, 126], [81, 0, 212], ... PIL – Python Image Module
Knows Knows how to read all the different image file formats. Lets Lets you write programs to alter the image data data. Shows Shows you the altered images. Getting Getting the image data
turkeyData = im.getdata() color = turkeyData # first pixel color color is (100, 132, 91) This This is not exactly a list – notice the parens rather than the square brackets – it’s a tuple. tuple PIL PIL uses tuples a lot so we need to understand them. 2 11/19/2008 Tuples
A tuple is very similar to a list, but it does less tuple stuff. Tuples cannot be changed. Tuples For For instance: clist = [100, 132, 91] 132 91] x = clist clist = 97 ctupe = (100, 132, 91) x = ctupe But But trying ctupe = 97 would crash! ctupe Why three numbers?
Most Most people have three kinds of cone cells in their eyes that detect red, green and blue light (the primary colors). Other colors of light primary are are mixtures of these three. Color Color blind people have just two kinds of cones. So So the computer only has to produce red, green and blue; if it projects more than one, the eye sees it as some other color. RGB RGB color
A color tuple gives the strength of each of color each of the primary colors at the pixel. ( Red, Green, Blue ) or ( R, G, B) So… ( 255, 0, 0) is pure red 255, ( 0, 255, 0) is pure green ( 0, 0, 255) is pure blue 3 ...
View Full Document
This note was uploaded on 03/23/2011 for the course ECS 10 taught by Professor Amenta during the Winter '07 term at UC Davis.
- Winter '07