View Full Version : Dr Java help

04-14-2012, 02:25 AM
Some questions and answers
1. Is there extra credit? Yes! To get it, you must first make an on-time submission
that conforms to our testability requirement (REALLY!).
Then, working with 3 images, butterfly1.jpg and two others, at least one you get
yourself (NOT from G&E, but take your own or get one from the Web), try to do
the best edge detection you can with variations of "numPixels" for blurring and
"amount" for detection threshold, possibly other algorithms. Write a wordprocessed report with a 3-5 page written description of what you did and the
results, and include an informative selection of the 3 original images and examples
of bad, better, and best results for each, and maybe others. Acceptable reports will
earn up to 50 points just added to your project score (like another 1/2 project!)
Email reports to the Prof. within a week of the project due date.
2. Lateness? No extra credit, and the usual 14% off per 24 hours late.
3. What (a) blurring "numPixels" value and (b) edge detecting "amount" did you use
to get the sample output, and what values should we use?
I used 2 for numPixels and 10 for amount; use those in your submission.
4. How should I structure my program?
I can think of two good ways: Either is OK. WAY One is to write 3 methods: A
method to return a new blurred Picture (made from a Picture parameter), a
method to return the new line detection Picture (made likewise), and a third to
copy a smaller Picture into a specified place of a bigger Picture.
WAY Two: Write a method to copy the original into a bigger Picture, plus two
others: one to blur and one to detect lines. The blur and line detect methods take as
parameters the result Picture and two rectangular regions of it. Both methods
access the colors from the first region and change the colors in the second region.
5. How should I begin?
First, get your program to copy the source Picture into the upper-left 6th of the
Second (or third), write and test code to copy the source WITHOUT CHANGE
AGAIN into the lower-left 6th. When that works, (NOT BEFORE) modify that
code to do the blurring. (You must put in if statements now to avoid crashes!)
Third (or second), write and test code to copy the source without change AGAIN
into the upper-middle 6th. When that works, (NOT BEFORE) modify that code to
make the gray scale image. (Tricky: NOT ALL gray scale Pixels will be changed!)
After the third step, you'll have no trouble finishing!
6. How do I make the differences of the averages (on textbook page 184) into a grayscale color? Easy: Use a variable like diff to hold the absolute value that G&E's
code computed, and use
*****//RGB intensities all the same: that's gray!

I have this up to now

import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.text.*;
import java.util.*;
import java.util.List; // resolves problem with java.awt.List and java.util.List

* A class that represents a picture. This class inherits from
* SimplePicture and allows the student to add functionality to
* the Picture class.
* Copyright Georgia Institute of Technology 2004-2005
* @author Barbara Ericson ericson@cc.gatech.edu
public class Picture extends SimplePicture
///////////////////// constructors //////////////////////////////////

* Constructor that takes no arguments
public Picture ()
/* not needed but use it to show students the implicit call to super()
* child constructors always call a parent constructor

* Constructor that takes a file name and creates the picture
* @param fileName the name of the file to create the picture from
public Picture(String fileName)
// let the parent class handle this fileName

* Constructor that takes the width and height
* @param width the width of the desired picture
* @param height the height of the desired picture
public Picture(int width, int height)
// let the parent class handle this width and height

* Constructor that takes a picture and creates a
* copy of that picture
public Picture(Picture copyPicture)
// let the parent class do the copy

* Constructor that takes a buffered image
* @param image the buffered image to use
public Picture(BufferedImage image)

////////////////////// methods ///////////////////////////////////////

* Method to return a string with information about this picture.
* @return a string with information about the picture such as fileName,
* height and width.
public String toString()
String output = "Picture, filename " + getFileName() +
" height " + getHeight()
+ " width " + getWidth();
return output;


public static void main(String[] args)
String fileName = FileChooser.pickAFile();
Picture pictObj = new Picture(fileName);

public void vignette();
int width = i.getWidth(); //might need different function
int height = i.getHeight(); //might need different function
double xC = width/2.0;
double yC = height/2.0;
double s = (xC * xc) + (yC * yC);
distMax = Math.sqrt(s);
for (Pixel p: i){
int x = p.getX();
int y = p.getY();
int red = p.getRed();
int green = p.getGreen();
int blue = p.getBlue();
int distX = (x - xC);
int distY = (y - yC);
double s = (distX * distX) + (distY * distY);
double distPix = Math.sqrt(s);
double whiteColorWeight = distPix/distMax;
int newRed = ((whiteColorWeight*255) + ((1.0*whiteColorWeight)*red));
int newGreen = ((whiteColorWeight*255) + ((1.0*whiteColorWeight)*green));
int newBlue = ((whiteColorWeight*255) + ((1.0*whiteColorWeight)*blue));

} // this } is the end of class Picture, put all new methods before this

04-14-2012, 01:10 PM
I think you're meant to do your own homework!