Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Summary For this assignment, we’re going to do some picture processing. We’ve al

ID: 3634400 • Letter: S

Question

Summary

For this assignment, we’re going to do some picture processing. We’ve already written most of the program for you. It’s in two files: Picture.java and Program11.java. The program takes at least two command-line arguments, in this order:

input file
output file
a series of commands, one per command-line argument:
h: flip the picture horizontally. Someone facing left now faces right.
v: flip the picture vertically. A portrait now stands on its head.
n: negate (invert) the picture. Black becomes white, white becomes black, nearly black becomes nearly white, etc.
Sample run (in Linux)

% javac Program11.java
% rm -f out.pgm
% java Program11 Cam.pgm out.pgm n h
% display out.pgm
Sample run (in Eclipse)


Set up the run configuration for the command line arguments
Run the program
To view the result, open a Linux window, go to the subdirectory in the
workspace where your program and picture file(s) are located.
Use the Linux 'display' command to view the picture
The set of command line arguments given above (Cam.pgm out.pgm n h) will transform the input file Cam.pgm into the output file out.pgm, after negating it and flipping it horizontally. The display command can then be used to display the resulting file.

Data Format

This program only works on PGM (Portable Gray Map) files. A PGM file contains a picture, just like a GIF or JPEG file, but it’s grayscale (not color), and it’s in a very easy-to-read format.

Required Functions

Look for “YOUR CODE GOES HERE” in the skeleton. Finish those three functions. You may only change the bodies of those functions—nothing else! Well, OK, you should add the comment at the top with your name, date, etc.

Skeleton Code and sample PGM file here:

http://www.cs.colostate.edu/~cs160/assignments/HW11f11.html

Explanation / Answer

// Flip the image horizontally.
// If it's a person looking left, they'll end up looking right.

public void horizontalFlip() {
int [][] tempImage = imageData;
for (int y = 0; y < imageData.length; y++) {
int width = imageData[y].length;
for (int x = 0; x < width; x++) {
imageData[y][x] = tempImage[y][width-x-1];
}
}
}


// Flip the image vertically.
// A picture of a person will end up standing on their head.

public void verticalFlip() {
int [][] tempImage = imageData;
for (int y = 0; y < imageData.length; y++) {
int width = imageData[y].length;
for (int x=0; x < width; x++) {
imageData[y][x] = tempImage[imageData.length - y - 1][x];
}
}
}

// Rotate the image right, i.e., 90 degrees clockwise.
// A picture of a person will end up getting
// rotated right by 90 degrees.

public void rotateRight() {
int [][] tempImage = imageData;
if (tempImage.length == 0) {
return;
}
imageData = new int [tempImage[0].length][tempImage.length];

for (int y = 0; y < imageData.length; y++) {

for (int x=0; x < imageData[0].length; x++) {
imageData[y][imageData[0].length-x-1] = tempImage[x][y];
}
}
}

// Rotate the image left, i.e., 90 degrees counterclockwise.
// A picture of a person will end up getting
// rotated left by 90 degrees.

public void rotateLeft() {
rotateRight();
rotateRight();
rotateRight();
}

// Bleep the image using a white rectangle.

public void bleep(int top_row,
int top_col,
int bottom_row,
int bottom_col) {
for (int y = top_row; y <= bottom_row; y++) {
for (int x=top_col; x<=bottom_col; x++) {
imageData[y][x] = MAXVAL;
}
}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote