Today's classwork focuses on transforming images and will use Eclipse to snarf a large Java program that you will modify. You will write several methods to manipulate the images. You will submit your solutions via Eclipse. If you don't finish in class, then you should finish by the next class period.
We will use Eclipse to download a partial program to get started Using Eclipse, download the project classwork/05_pixmap_cps006_spring10
![]() | Images are stored by computers in a variety of formats, such as gif, jpg, tiff,
and png. These formats differ in how faithfully they represent
the original picture, how well they can be compressed to reduce the
space each image takes up, or how well they can be copied from one
type of computer to another. However, no matter what format the image
is stored in, it can always be represented of as a mapping of (x, y)
pixel position to a color (the range of colors may be restricted to
values of grey or just black and white). Thus, for the remainder of
this project, we will refer to all formats of digital images as pixmaps.
This programming project involves manipulating pixmaps by transforming each color in the original pixmap using the same algorithm. Your program will be able to read in gif, jpg, and png image formats, and perform several operations on these images including darkening, inverting, posterizing, coverting it to grey scale. |
Complete the following problems and test your solution by running it within Eclipse
For each of the problems below, you will complete the transformColor
method
of the appropriate class that, given a Color
parameter
representing a current pixel in the pixmap, returns a new Color
whose
component values have been changed based on the algorithm described that will
replace the original pixel. To test your solution, right-click on the file named Main.java within
your project and select Run -> Java Application from the menu that
appears. This will cause a Java program to appear that allows you to open, transform,
and save images. To load a different image to test, click on the Open
button and select an image from
the images folder there. To test your method on every pixel in the displayed image,
click on the button corresponding to the name of the class in which you worked.
![]() |
Create a photographic negative of the image by inverting each of the three RGB components of the current color. For example, if the current color has the values (255, 0, 128) for its red, green, and blue components, respectively; then the resulting color should have the values (0, 255, 127) for its red, green, and blue components. In other words, each value is the other's opposite within the range of possible values from 0 .. 255. |
![]() | Darken the image by reducing the
values of each of the three RGB components of the current color by some
amount (like the
darker method of Java's
Color class. Do not call the darker method, instead you
will reproduce those results by manipulating the three RGB components of
the color directly. This method should undo what the Brighten method does (
as long as no colors were already as bright as possible). Be careful not to
produce a color outside the range from 0 ... 255.
|
![]() |
Brighten the image by increasing the values of each of the three RGB components
of the current color by some amount (like the
brighter method of Java's Color class.
Again, do not call the brighter method, but write it yourself by
manipulating the three RGB components of the color directly.
|
![]() |
Create a posterized version of the image by reducing its total number
of colors. To do this, you should restrict the values each of the three
RGB components of the current color can be. Specifically, if the value
of a component is between 0 and 63 inclusive, it should be set to 49;
if the value of a component is between 64 and 127 inclusive, it should
be set to 98; if the value of a component is between 128 and 191
inclusive, it should be set to 147; and if the value of a component is
between 192 and 255 inclusive, it should be set to 196. In this way,
the 256 possible values each component can have is resticted to just
4. |
![]() |
Create an image that has only shades of grey values by computing the
average value of the current color's three RGB components and using
that average value for all three components of the new color. For
example, if the current color has the values (255, 0, 128) for
its red, green, and blue components, respectively; then the resulting
color should have the values (127, 127, 127) for its red,
green, and blue components. |
![]() |
Complete the transformColor method of the WeightedGreyScale color
transformer class such that it uses the weights suggested in
this article The idea is to take the average of 30% of the red color, 59% of the green color and 11% of the blue color, and use this average for its red, green and blue components. For example, if the current color has values (255, 0, 128) for its red, green and blue components, respectively; then the resulting color should have the values (90,90,90) for its red, green and blue components.
|
Make sure you add a README.txt (put in your name, how long it took, who you got help from).
Electronically submit through Eclipse your Java code and README.txt file to the Class05-Jan28 classwork folder.