Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Java Picture Processor with PGM files and Multi Arrays

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?


  2. #2
    Member
    Join Date
    Nov 2010
    Location
    New Zealand
    Posts
    32
    Thanks
    3
    Thanked 4 Times in 4 Posts

    Default Re: Java Picture Processor with PGM files and Multi Arrays

    Quote Originally Posted by snow_mac View Post
    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:

    // 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:

    // 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

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default 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?

Similar Threads

  1. New To Java (Help with arrays)
    By SilentPirate in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 16th, 2010, 05:48 AM
  2. Multi-dimension ArrayList example
    By adeola in forum Collections and Generics
    Replies: 3
    Last Post: March 26th, 2010, 03:23 AM
  3. Multi-dimension ArrayList example
    By helloworld922 in forum Java Programming Tutorials
    Replies: 1
    Last Post: February 3rd, 2010, 11:01 AM
  4. Replies: 1
    Last Post: October 19th, 2009, 11:53 PM
  5. Details about 'CopyTo' of Arrays in Java
    By Fendaril in forum Collections and Generics
    Replies: 18
    Last Post: November 13th, 2008, 08:31 AM