CS 100 - Computer Literacy, Fall 2004
Lab 11
This lab assignment will have you write a jython program
that will make a black and white version of a color image.
Reminder
The program Jython Environment for Students (or JES) is the
development environment that we will use for this lab.
In the ACCC Labs, JES can be found by:
- Click on Start
- Then click on All Programs
- Then click on Class Applications
- Then click on Engineering
- Finally click on Jython Environment for Students
Images Using a GrayScale
A black and white picture uses various shades of gray.
These shades of grey all have the same amount of red,
green and blue color. The higher the color value, the
lighter the shade of gray is. The lower the color
value, the darker the shade of gray is. For example,
look at the following squares of various gray.
The amount of red, green and blue for the color is displayed
as text in each square. Note that the amount of red,
green and blue is the same in each square. Also note that
the larger the amount of color, the lighter the color of gray.
r = 0 g = 0 b = 0
| r = 63 g = 63 b = 63
| r = 127 g = 127 b = 127
| r = 191 g = 191 b = 191
| r = 255 g = 255 b = 255
|
Changing the color in a pixel
The color in a pixel can be changed by using the setRed(),
setGreen() and setBlue() functions in JES. Each of these
functions take two input values. The first input value is
the pixel to change, while the second input value is the
new amount of the color the pixel should have.
Determining the amount of gray
One method to determine which grayscale color to use
for a pixel when creating a black and white picture
from a color picture is to average the amount of
red, green and blue color the corresponding pixel
in the colored picture. This method works fairly
well and is fairly easy to understand and use.
Another method is to take a weighted average of the
amount of red, green and blue color instead of an
evenly-weighted average. A weighted average would
give more weight to certain values and less weight to
other values. A weighted average will be used when
determining the grade for this course. Exams have a higher
weight (i.e. more impact on the final grade), while
lab assignments have a lower weight (i.e. less impact
on the final grade). For determining the amount of
color for the graycolor color, the original amount of
green is often given a higher weight while the original
amount of blue is given a lesser weight. The percent
of each color that should be used according to some
research done is:
New JES Commands
Lab Assignment 11
Due: Friday 11/12/2004 by 8:00 am
Create a file using JES that will
- Contain a comment indicating your Name, Net-ID,
Course Name, Assignment Name and a short description of
the assignment
- Contain a JES function that will
- allow the user to pick an image using pickAFile().
- change the selected image to a black and white image. You may
use any method you wish to determine the amount of color for the
grayscale colors.
- display the black and white image.
- allow the user to save the image using pickAFile().
This function may call other functions that are built-in to JES or
that you have written.
On the ACCC lab computers, the H: drive is a permanent
storage area for you. Saving files to this drive on one
computer can be accessed from another computer (even another
computer in a different lab). It is suggested that you save
your python programs to the H: drive.
Use the UNIX turnin command to electronically hand-in your
python file using the project name of lab11.
Note: you will need to transfer your python file to your icarus
account before you can use turnin. You can do this by using the
file transfer function of SSH or by emailing your python file to
your incarus account. To submit the file in
<filename>.py for lab11, the turnin command is entered as:
turnin -c troy -p lab11 <filename>.py
You are invited to post any and all images you create in the
discussion board area in blackboard. You can use that area to
show the class how creative you are.