Java Picture Processor with PGM files and Multi Arrays
I need some Java help, I've sought out help from my professor with no luck. We're doing a picture processing program in Java. Basic functions are flip vertical and horizontal, invert and rotate. They've written most of the code, which can be found here: http://www.cs.colostate.edu/~cs160/pub/Pic.java
The requirements and PGM files are here: CS160 | Main / HW6
Basically I don't know how to get started. They have a comment in each method (eg negate) // YOUR CODE GOES HERE. I'm pretty good on the logic/understanding part of the java program but am struggling with the code part. I see that there is a private method that handles the image into an array, I'm thinking I probably need to use that. When I've tried it gives me an veriable scope error.
I really don't know, can you please help me out?
Re: Java Picture Processor with PGM files and Multi Arrays
Quote:
Originally Posted by
snow_mac
Basically I don't know how to get started. They have a comment in each method (eg negate) // YOUR CODE GOES HERE. I'm pretty good on the logic/understanding part of the java program but am struggling with the code part.
Ok, they basically reduce the picture to an array of color values for each pixel. And they ask you to manipulate the pixel values and restore them in the same array. This exercise is not about picture processing, but an original way to teach you about loops and array manipulations.
First I'd make the width and height variables global to the class:
Code Java:
// This 2-d array contains the pixel values.
private int[][] imageData = null;
private int width;
private int height;
Don't forget to change them in method readPGM() so that they don't get declared locally. (Remove the int in front of width and height.)
This is what the negate method could be:
Code Java:
// Negate the image.
// That is, if a pixel has the value 0, replace it with MAXVAL.
// If a pixel has the value 1, replace it with MAXVAL-1.
// If a pixel has the value 7, replace it with MAXVAL-7, etc.
public void negate()
{
for (int y = 0; y < height; y++)
for (int x = 0; x < width; x++)
imageData[x][y] = MAXVAL - imageData[x][y];
}
The other methods are just other transformations of the same array. For some of them you might have to create a local temporary array to store values before overwriting the original one.
Note: I haven't been able to test this since I don't have a PGM file lying around.
Best of luck with the assignment,
Alice
Re: Java Picture Processor with PGM files and Multi Arrays
Hi, what would you put in the Program11 class in order to call the method negate()? Do you have to create an instance?