In general, you can find me on campus Monday, Tuesday, & Thursday
I'm reachable by e-mail most any time
An example implementation: color.py
Some comments:
Historically, displays have been divided between vector and raster
vector - pictures are drawn as a set of precise lines, connecting arbitrary points on the screen
raster - pictures are drawn by scanning the screen in a discrete sequence of
rows
A similar distinction continues - graphical objects can be described by images or geometry
A digital image is a 2 dimensional array of pixel colors
Pixel = "picture element"
Each pixel is a sample of a continuous, analog image
Pointillism can be considered to take a similar approach -
breaking an image down into discrete samples
Basic image data in computer memory is a stream of numbers
1 239 120 1 1 37 94 8 92 31 80 92 134 89 2 3 50 9 3 10 93 109 134 ...
Important additional information is:
Total memory needed for a simple image:
width * height * components * bytes_per_component
e.g. a 512x512, RGB, 8-bit image requires 768 kilobytes
Image data is often saved in or loaded from a file
There are many common image formats: JPEG, TIFF, PNG, GIF, etc
Features which may vary between formats are:
Provides support for reading, writing, and manipulating images in several formats.
PIL website: www.pythonware.com/products/pil/
Handbook: www.pythonware.com/library/pil/handbook/
PIL is installed on all the PCs in rooms 242 and 265
The PIL installer for Windows can be grabbed from my Python
installation page.
It's also included in the 'kitchensink' distribution for Mac OS/X
>>> import Image >>> img = Image.open("foo.jpg") >>> img.size (512, 512) >>> img.mode 'RGB' >>> newimg = img.resize((32,32)) >>> newimg.save("bar.tif")
Note: don't do "from Image import *", because that will replace the normal open() function with the Image package's open().
img = Image.open('myimage.tif')
img = Image.new('RGB', (640,480), (255, 255, 255))
img.save('newimage.jpg')
img2 = img1.resize( (256, 256), Image.ANTIALIAS )
img2 = img1.transpose( Image.FLIP_TOP_BOTTOM )
img2 = img1.rotate(30)
img2 = img1.convert( 'L' )
imgdata = img.tostring()
img.fromstring(imgdata)
or
img = Image.fromstring('RGB', (640, 480), imgdata)
rgb = img.getpixel( (10, 31) )
img.putpixel( (10, 31), (255, 255, 0) )
GL function names follow a standardized scheme
All begin with "gl", followed by the basic name of the command
When there's only one possible form of arguments:
When arguments can take multiple forms:
e.g. the Color function has the forms:
Constants are defined for certain function arguments
Constant names are all in capital letters, in the form:
e.g. possible arguments for glBegin() are:
Images are drawn with glDrawPixels
glDrawPixels(width, height, format, type, pixels)
width & height are the size of the image, in pixels.
format is GL_RGB for RGB images, or GL_LUMINANCE for greyscale
(there are other formats as well).
type indicates the data type of the pixel data.
GL_UNSIGNED_BYTE is standard for 8-bit-per-channel images.
pixels is the actual array of image data.
Use the tostring() function with PIL images.
img = Image.open("foo.jpg") glDrawPixels(img.size[0], img.size[1], GL_RGB, GL_UNSIGNED_BYTE, img.tostring())
The position to draw an image at is given with glRasterPos
glRasterPos2f(x, y)or
glRasterPos3f(x, y, z)
Example: drawimage.py
DUE: Thursday, 22 September 2005, 11:59:59 pm
(via e-mail, to depape@buffalo.edu)
Create a program that dynamically displays multiple images
the program must:
Some possibilities:
Extra credit will be given for making the program interactive - i.e. allow the user to control some part of what happens with the keyboard and/or mouse
E-mail your program, and any required images, to me at depape@buffalo.edu
Be sure to include your name, and the OS you wrote the program on, in comments in the code.