For this assignment, we will get fancier in our ability to process images. We will now think of an image as a three-dimensional array of pixels: the first dimension corresponds to the rows, the second to the columns, and the third to the color bands. Note that parts A and B are team assignments, and that part C is an individual assignment. A description of which methods are part of which assignment is at the bottom of this web page.
We will again use the EzImage class, which gives us some of the basic tools that we need. For images, you can again use background1.jpg, background2.jpg, background3.jpg, amy.jpg, or dave.jpg, or obtain your own image instead if you like: you can use your picture from the Carleton directory or you can take a picture with a digital camera.
Your mission is to write new methods for PhotoLab
. If
you're working with a different partner, you can start again from
scratch or grab the code that one of you wrote as a starting
point. The PhotoLab
that you submit this time around will
have a different (additional) set of methods, so it doesn't matter if
you had problems last time with some of your methods. Here are the
methods that your PhotoLab
class should have:
public PhotoLab(EzImage image)
public EzImage getOldImage()
public EzImage getNewImage()
public boolean crop(int rowStart, int rowStop,
int colStart, int colStop)
rowStart
through rowStop
and
colStart
through colStop
. If any of the
parameters are out of range for your image, leave the image unchanged
and return false
. Otherwise, return true.
public boolean dither()
Dithering should only be done on gray images, so return false if
the image isn't gray already. You can use the EzImage
instance method copyToGrayScale()
to convert an image to
gray.
In order for dithering to work, you must make your changes to the same image that you are looping over. Dithering by reading one image and making your changes on a copy will not work correctly, because the "error" never gets a chance to accumulate. In other words, make sure that you make a gray scale copy of the image first, and then do all dithering work (looping, reading, writing, etc.) on the copy itself.
public boolean overlay(EzImage overlayImage,
int row, int col)
overlayImage
onto the image, as in the
example below. If overlayImage
can't be placed on the
image (perhaps because it is too large or row
or
col
are not valid), return false
. Otherwise,
return true
.
public boolean circleCrop(int centerRow, int
centerCol, int radius)
centerRow
and centerCol
and a radius of radius
. Since
the image itself must still be rectangular to fit inside a window,
make the background of the rest of the image white. See example below,
which was cropped from background3.jpg. If
centerRow
, centerCol
, radius
,
or some combination thereof are invalid, return
false
. Otherwise, return true
.public boolean scale(double scaling)
scaling
is 2, for example, your
image should double in size. Likewise, if scaling
is
0.25, your image should be 1/4 the size of the original. If
scaling
factor is less than or equal to 0, make no
changes to the image and return false
. Otherwise, return
true
.public boolean blur(int radius)
Test your program by writing a corresponding
PhotoLabTester
class. Check the return values from your
methods, and print out text indicating whether or not your methods
were successful.
Assignment "A" is a team assignment. It consists of getting the
constructor, crop
, and dither
methods
working. You and your partner should submit PhotoLab
and
PhotoLabTester
, along with any associated images, in a
directory called image2a
.
overlay
, circleCrop
, and scale
working. Submit all of your work (which includes assignment "A") in a
directory called image2b
.
blur
working, and
should be done individually. For this individual assignment,
you may consult with others, trade ideas, and obtain help; but the
code that you write should be your own. Submit your work (which
includes assignments "A" and "B" from your teamwork) in a directory
called image2c
.
Good luck, and have fun!