Some Helpful Hints for next Assignment

The assignment is pretty straight forward: just replace each green pixel with the corresponding pixel from another image. What could possibly go wrong?

 

The first step is to load the two images into memory so that you can work on them. That bit of code is easy:

     BufferedImage foreground_img = null;
     foreground_img = Read_Image (args[0]);

     BufferedImage background_img = null;
     background_img = Read_Image (args[1]);
Since foreground_img contains all the green pixels that we want to replace, we can just write over those pixels in memory. After we have replaced all the green pixels, then we can write foreground_img into a new file.

 

The meat of your program will look something like this:

     if ( pixel x,y is green )
        foreground_img.setRGB (x, y, background_img.getRGB(x,y));
The big problem: what does "green" look like? Just looking for 00FF00 will yield very few replaced pixels. In reality, there are shades of green that you will want to replace. In short, that if-statement above is kind of complex.

Determine an effective method for allowing the user to adjust the RGB tolerances.

 

There are a lot of ways this program can crash. The more user input you need, the more ways there are to mess up. Provide ample error checking.

Here is another possibly useful tidbit of code from my program:

     if ( args[0].indexOf(".jpg") < 0 )
      {
       System.out.println ("Usage Error: input file must end in .jpg");
       System.exit (1);
      }