0% found this document useful (0 votes)
803 views

1/3/2012 CS Basic Image Processing

The document discusses the cImage module for reading and displaying images in Python. It defines key image fundamentals like pixels, which store red, green, and blue intensity values, and images, which are matrices of pixels. It also introduces the ImageWin object as a canvas for displaying images. Code examples are provided to load an image, get its width and height, display it in a window, modify a pixel, and redraw the image. An assignment is given to add a green line to an image today and swap red and blue values of all pixels tomorrow.

Uploaded by

Matt Carlberg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
803 views

1/3/2012 CS Basic Image Processing

The document discusses the cImage module for reading and displaying images in Python. It defines key image fundamentals like pixels, which store red, green, and blue intensity values, and images, which are matrices of pixels. It also introduces the ImageWin object as a canvas for displaying images. Code examples are provided to load an image, get its width and height, display it in a window, modify a pixel, and redraw the image. An assignment is given to add a green line to an image today and swap red and blue values of all pixels tomorrow.

Uploaded by

Matt Carlberg
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

cImage module We will be using the Python file cImage.

py that contains code for reading and displaying images. Put the following line of code (preferably at the top of your own Python file) to tell the computer you will be using functipons/objects in from cImage.py: from cImage import * Image fundamentals: Pixel Object: an individual dot in an image. Pixel object stores three color intensities: red intensity, green intensity, and blue intensity. Each intensity is between 0 and 255. Color Red Green Blue White Black Yellow Pink Red 255 0 0 255 0 255 255 Green 0 255 0 255 0 255 0 Blue 0 0 255 255 0 0 255

Image object: A matrix (2-dimensional array) of pixels.

h =height of image

w = width of image ImageWin object: Can be thought of as a canvas that can display images. Nothing gets displayed on the canvas unless you draw it. Some very useful lines of code: #displaying an image from cImage import * myImage = FileImage( whatever.gif ) w = myImage.getWidth() h = myImage.getHeight() myWindow = ImageWin( any title you want , w, h) myImage.draw(myWindow)

#change the top right pixel to a red pixel topRightPixel = myImage.getPixel(0, w-1) newTopRightPixel = Pixel(255, 0, 0) myImage.setPixel(0,w-1, newTopRightPixel) myImage.draw(myWindow) myWindow.exitOnClick()

First image processing assignment: Today: Load Jellyfish.gif, make a green horizontal line that goes across the middle of the image. Tomorrow: For the file Jellyfish.gif, switch the red and blue intensity values for EVERY pixel in the image.

You might also like