View on GitHub

CSUMB 205 - Image Class

A wrapper class for PIL's Image class for academic purposes

download .ZIPdownload .TGZ

CSU Monterey Bay CST205

Simple Multimedia Classes

Current Version: v0.8.12

This project offers students access to a simple RGB Image class, which is built on the use of the Image module in the PIL package. As PIL is no longer updated for Python 3, this package relies on Pillow.

This package assumes that the user is using at least Python 3.4.

If you have not installed Python 3.4.2 or greater, please download it from python.org.


USAGE

RGB IMAGE

The expected usage of this module is within a Python script. As such, to use this module, you will want to include the code...

 from simpleImage import rgbImage

...at the top of your file. This will allow you to use the RGB Image class, and create RGB Image objects.

CREATE an RGB IMAGE

There are two ways to create an RGB Image object from an existing image. You can either pass the path to an image file, like so:

 myImage = rgbImage("/path/to/my/image/file/IMAGE.jpg")

...or you can simply call the constructor with no inputs.

 myImage = rgbImage() 

This will open a dialog screen, where you can navigate to and choose your image file.

You can also make a blank image. To do this, you must pass a TRUE boolean to the constructor through the "blank" keyword. You can also specify the height and width, but these will default to 100 and 100.

 myImage = rgbImage(blank=True, height=500, width=1200)

So, what can you DO?

Once you have created your object, there are (currently) a limited number of things you can do. You can get the height and width of your picture by accessing their respective variables.

 >>> print(myImage.height)
 500
 >>> print(myImage.width)
 1200

We can also get individual pixels from the image. We have two methods for doing this. We can either get an individual pixel...

 a_pixel = myImage.getPixel(1,2)
     or
 a_pixel = myImage.getPixel( (1,2) )

Both methods will get the same pixel. The only difference if the formatting of the input. You can choose whichever is more comfortable for you.

We can also get all of the pixels as a Python list. We do this with the function...

 all_my_pixels = myImage.getAllPixels() 

Once we have a pixel (or a list of pixels), we can modify them.

Each pixel has a few basic functions that you should know about. As a pixel is a set of RGB values in a specific location, we have functions to get those values. Here are examples of them...

 >>> a_pixel = myImage.getPixel( (1,2) )
 >>> print(a_pixel.getRed())
 60
 >>> print(a_pixel.getGreen())
 120
 >>> print(a_pixel.getBlue())
 20
 >>> print(a_pixel.getX())
 1
 >>> print(a_pixel.getY())
 2

From here, we can see the basic values of each.

A pixel also has a few basic "setter" functions. These are exemplified here...

 >>> a_pixel.setRed(255)
 >>> a_pixel.setBlue(0)
 >>> a_pixel.setGreen(79)

Our pixel is now one whose RGB values are (255,79,0).


Now, back to our image. Once we have modified our pixels as we see fit, we can either view it, save it, or change the name our saved image will have.

To view the image, simply add the line or type...

 myImage.show() 

To change the name, call the function...

 myImage.setName("A Silly Image") 

NOTE: What you pass in should be a function, with no file extension

To save the image, call the function...

 myImage.save() 

That's it for now. Check out the more detailed documentation for more information.