Computer Science 15-110 (Lecture 4), Spring 2010
Homework 6a
Due:  Thu 25-Feb-2010 at 10pm (see hw6 for details)


This part of hw6 is collaborative (so you should work in small groups).  The same rules as hw5 apply (read them carefully!).


  1. ImageEditing (grayScale, zoomIn, zoomOut)
  2. rotateImage
  3. Bonus/Optional:  greenScreen
  4. Bonus/Optional:  polarRose

  1. ImageEditing (grayScale, zoomIn, zoomOut)
    Continuing with your group work in recitation, complete the grayScale, zoomIn, and zoomOut methods from last semester's hw8.
     
  2. rotateImage
    Write a method that takes a BufferedImage and an angle θr (specified as a double, measured in degrees, not radians), and returns another BufferedImage of the same size that is the original image rotated counterclockwise by the given angle around the image's center point.  As the two images should be the same size, note that:  (a) some source pixels will map outside of the entire target image (and so should be ignored); and (b) some target pixels (near the corners) will not be mapped to by any source pixels (and so should be black).

    Hint #1:  to solve this, we need to map each point (xt,yt) in the target image to a point (xs,ys) in the source image.  One approach (and the one we will use here) is to use polar (r,θ) coordinates, since then we'd only have to add the given angle θr to the angle coordinate (see?).  So we'll convert to polar, add the angle θr, then convert back to cartesian coordinates.  Read the relevant portion of the Wikipedia page on Polar Coordinates to see how to map from cartesian (x,y) coordinates to polar (r,θ) coordinates and back again.

    Hint #2:  For the math to work right, you need to use the center of each image as the origin (0,0).  Think about that!  Also, don't forget that in pixel math, up is down, but in real math (such as on that Wikipedia page), up is up!

    Hint #3:  Java includes the arc methods Math.asin, Math.acos, and Math.atan.  These return angles in radians, so you may wish to also use Math.toDegrees and/or Math.toRadians at some point.
     
  3. Bonus/Optional:  greenScreen
    Write a method named greenScreen that takes three parameters -- a background image, a foreground image, and a transparent color (the green in the green screen) -- and returns a new image, the same size as the background image, but where all the pixels "close" to the given transparent color are replaced by the corresponding pixels in the foreground image.  Include some compelling example images.  Keep your image files small, please.
     
  4. Bonus/Optional:  polarRose
    Write a method named polarRose that takes three integer parameters -- a size in pixels, and the values n and d -- and returns a new size-by-size square image containing a polar rose specified by the equation r = cos(kθ), where k=n/d.  Here are some polar roses for various values of n and d:



    Numerous details are left to you, so just make reasonable assumptions.  Refer to the Wikipedia page on Polar Roses for more information.

Carpe diem!