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 11 of 11

Thread: Image manipulation program help

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Image manipulation program help

    Hi. Beginner here. I have a question about a Java program on manipulation of photos.

    I want to learn how to rotate a photo 90 degrees, rotate it 180 degrees, enlarge it by doubling its width and length, and stitching them.

    So far I have written a code segment on how to copy a photo:

    public class PhotoTools {


    public static Photograph copy(Photograph photo) {


    Photograph copy_of_photo = new Photograph(photo.getWidth(), photo.getHeight()); /*create a new photo and get dimensions*/

    for (int row = 0; row < photo.getWidth(); row++){ //2 loops going through each column then row
    for (int col = 0; col < photo.getHeight(); col++){
    Pixel copy = photo.getPixel(row, col); //set pixels to get the pixels in the photo
    copy_of_photo.setPixel(row, col, copy); //copy pixels to new photo
    }

    }
    return copy_of_photo; //return new copied photo
    }

    ---------------------------------------------------------------------------

    Please do not give me actual code.
    I was hoping I could get hints on ways to approach the other methods.

    Thank you for your time.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image manipulation program help

    What package is the Photograph class in? I don't recognize it. Does that package have classes and methods to do what you want?

    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulation program help

    I am using a custom class created by someone.

    Photograph Class

    Constructor Summary
    Photograph(int width, int height)
    Create a blank photo of a specified size.

    Method Summary

    int getHeight()
    Access height of photo.

    Pixel getPixel(int x, int y)
    Access one of the Pixels in the photo.

    int getWidth()
    Access width of photo.

    void setPixel(int x, int y, Pixel p)
    Set one of the Pixels in the photo.


    Constructor Detail
    Photograph

    public Photograph(int width,int height)
    Create a blank photo of a specified size.

    Method Detail
    getWidth

    public int getWidth()
    Access width of photo.
    Returns:
    width (in pixels)

    getHeight

    public int getHeight()
    Access height of photo.
    Returns:
    height (in pixels)

    getPixel
    public Pixel getPixel(int x,int y)
    Access one of the Pixels in the photo.
    Parameters:
    x - x-coordinate of desired pixel
    y - y-coordinate of desired pixel
    Returns:
    Pixel at position (x, y) in the photograph. Note that the origin (0, 0) is located at the upper left corner of the photo.


    setPixel

    public void setPixel(int x,int y,Pixel p)
    origin (0, 0) is located at the upper left corner of the photo.



    -----------

    Class Pixel (class that represents a single pixel in a photograph)

    Constructor Summary
    Pixel(int red, int green, int blue)
    Create a new Pixel object by specifying the levels of red, green, and blue colors present.


    Method Summary
    int getBlue()
    Returns the level of blue seen in the Pixel
    int getGreen()
    Returns the level of green seen in the Pixel
    int getRed()
    Returns the level of red seen in the Pixel




    Method Detail
    getRed

    public int getRed()
    Returns the level of red seen in the Pixel
    Returns:
    level of red (0 to 255)


    getGreen

    public int getGreen()
    Returns the level of green seen in the Pixel
    Returns:
    level of green (0 to 255)


    getBlue

    public int getBlue()
    Returns the level of blue seen in the Pixel
    Returns:
    level of blue (0 to 255)

    --------

    --- Update ---

    These packages were created by my teacher and I own nothing. I was hoping for tips or hints on how I can rotate 90/180 degrees, stitch, enlarge or some insight on how to think about this problem. Thanks.

  4. #4
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulation program help

    Here is what I have so far for stretch. The user will input 0 or 1 in the driver.
    ---------------------------------------------------------
    public static Photograph stretched(Photograph photo, int type) {
     
    		// In other words, 
    		//if type is 0, then each column of pixels in the original photo will appear twice in the new one.  
    		//If type is 1, then each row in the original photo will appear twice in the new one.
     
    		//0 = horizontal stretch
    		// 1 = vertical stretch
    		Photograph stretched_photo = new Photograph(photo.getWidth(), photo.getHeight());
     
     
     
    		if (type == 0){
     
    			Photograph horizontal_stretch = new Photograph (2*photo.getWidth(), photo.getHeight());
     
    			for (int row = 0; row < photo.getWidth(); row++){
    				for (int col = 0; col< photo.getHeight(); col++){
     
    					Pixel p = photo.getPixel(row, col);
    					horizontal_stretch.setPixel(row, col, p);
    					horizontal_stretch.setPixel(row, col, p);
    				}
     
    			}
    		    stretched_photo.equals(horizontal_stretch);   
    			return stretched_photo;
    		}
     
    		else if (type == 1){
     
    			Photograph vertical_stretch = new Photograph (photo.getWidth(), 2*photo.getHeight());
     
    			for (int row = 0; row < photo.getWidth(); row++){
    				for (int col = 0; col< photo.getHeight(); col++){
     
    					Pixel p = photo.getPixel(row, col);
    					vertical_stretch.setPixel(row, col, p);
    				    vertical_stretch.setPixel(++row, col, p);
    				}
     
    			}
    			 stretched_photo.equals(vertical_stretch);  
    		       return vertical_stretch;
    		}
     
    		return stretched_photo;
    	}

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image manipulation program help

    Sorry, without the classes in the package, there is not way to compile, execute and test the code.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulation program help

    Thanks for your help. Do you have any hints as to how I would go about approaching rotating an image or enlarging it.
    For rotating 90 degrees i know the new Column = row and new_Row = col. And 180 degrees is just a copy but upside down. Not sure how to set pixels for that. For enlarging I'm having trouble duplicating an extra column or row for horizontal and vertical stretch respectively. I would imagine it's the same as copy but I set pixels twice.
    Any hints or ideas would help.

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image manipulation program help

    The rotate ideas sound reasonable.
    No ideas on how to stretch.
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulation program help

    In the prompt, I have to try and duplicate an extra column or row.

    For Horizontal stretch I have to duplicate an extra column...So in instead of have (for first row) {(0,0), (0,1), (0,2), (0,3)} I have to make it {(0,0),(0,0),(0,1),(0,1),(0,2),(0,2),(0,3),(0,3)}

    Same for the vertical stretch except I duplicate a row in each pixel/ grid...

    I just dont't know how

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image manipulation program help

    What problem are you having? For vertical or for horizontal or both
    Choosing which row to duplicate
    duplicating the chosen row
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    Mar 2013
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulation program help

    I have to enlarge the whole image... if I understand row then i can get column (same concept)

    For horizontal stretch..I have to duplicated the column of each pixel in a photo.
    For vertical stretch..I have to duplicate the row of each pixel in a photo

    Im having trouble understanding how to duplicate...I know how to copy an image. Im guessing I need to tweak that method but I dunno how to set pixels for the new duplicate after I've made it.

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Image manipulation program help

    how to duplicate
    Would that be the same as copying the same row or column two times?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. string manipulation
    By nhiap6 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 17th, 2012, 06:32 AM
  2. string manipulation
    By nhiap6 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 16th, 2012, 12:28 PM
  3. [SOLVED] problem with time manipulation!
    By arvindbis in forum What's Wrong With My Code?
    Replies: 4
    Last Post: September 30th, 2011, 02:47 PM
  4. String Manipulation.
    By Nemus in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 21st, 2011, 03:02 PM
  5. String manipulation help
    By Duff in forum Loops & Control Statements
    Replies: 7
    Last Post: March 19th, 2010, 04:02 AM

Tags for this Thread