APCS: Image Processing Project, Activity 7


4 points

Read Activity 7 on pages 17 - 18, and check out mirrorTemple() at the bottom of page 17.

We'll write a more general version of mirrorTemple() called mirrorPart(), which will mirror a part of an image, to either the left or the right. You may want to copy mirrorTemple() and then modify it. Here is the header line of mirrorPart():

public void mirrorPart(int mirrorPoint, int rowStart, int rowEnd, int colStart, int colEnd, String type), where

mirrorPoint = the column value at which the vertical 'mirror' is located
rowStart = the row at which the rectangle of pixels begins
rowEnd = the row at which it ends
colStart = the column at which the rectangle of pixels begins
colEnd = the column at which it ends
type = String that indicates whether the rectangle will be mirrored to the left or to the right. If 'type' stores "LtoR", the rectangle will be mirrored left-to-right. (My code actually just looks at the first letter in 'type' to see if it is an "L".) Otherwise, the rectangle will be mirrored right-to-left.

The main issue is how to use the mirror differently, depending on whether the mirroring is left-to-right or right-to-left. Inside the inner loop, you can set up an if statement that runs if the mirroring is left-to-right and an else that runs if the mirroring is right-to-left. In either case, you'll need to give appropriate values to leftPixel and rightPixel. If it's left-to-right, you'll set rightPixel equal to leftPixel. If it's right-to-left, you'll set leftPixel equal to rightPixel.

Once you have the method written, test it by doing a left-to-right mirroring on 'temple.jpg' to fix the right-hand side of the top of the temple, as seen on page 17. You can run PictureExplorer to find the values of mirrorPoint etc.

Then run PictureExplorer to find the parameters for a mirroring of the seagull in 'seagull.jpg'. Use your mirrorPart() to do both a left-to-right and right-to-left mirroring.

You are not asked to do the Exercises on page 18.

Resources:
Student Guide
Javadoc

 

Links:
Image Processing Project
AP Computer Science