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

Thread: java help

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

    Default java help

    I need help with this plz

    Old-fashioned photographs from the 19th century are not quite black and white and not quite color, but seem to have shades of gray, brown, and blue. This effect is called sepia. Define and test a function named sepia that converts a color image to sepia. This function first calls the grayscale function to convert the color image to grayscale. Here is a code segment for then transforming the color component value of a single pixel to achieve a sepia effect. Note that the value for green does not change.


    import images.APImage;
    import images.Pixel;
    import java.util.Scanner;
     
    public class jm54{
     
       public static void main(String[]args){
          Scanner reader = new Scanner(System.in);
          APImage image = new APImage("smokey.jpg");
          image.draw();
          for (Pixel p: image){
             int red = p.getRed();
             int green = p.getGreen();
             int blue = p.getBlue();
             int average = (red + green + blue) / 3;
                p.setRed (average);
                p.setGreen(average);
                p.setBlue(average);  
                if (red < 63){
                    red = (int)(red * 1.1);
                    blue = (int)(blue * 0.9);
                 }else if (red < 192){
                	 red = (int)(red * 1.15);
                	 blue = (int)(blue * 0.85);
                 }else{
                	red = Math.min(int(red * 1.08), 255);
                			blue = (int)(blue * 0.93);
             }       
          }
         // System.out.print("Press return to continue:");
         // reader.nextLine();
          image.draw();
       }
    }


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

    Default Re: java help

    Please explain your problems.

    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
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: java help

    ok i manage to set the image to gray scale but i don't know how to convert it to sepia tone

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

    Default Re: java help

    What is the algorithm for converting pixel colors to sepia ?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java help

    int width = theoriginal.getWidth();
    int height = the original.gethieght(0
    APImage theClone = new APImage(width,height);
    for (int y = 0; y , height; y++0
    for (int x = 0;  x< width; x++){
    Pixel pixelInOriginal = theoriginal.getPixel(x, y);
    Pixel pixelInClone = theClone.getPixel(x, y);
    pixelInClone.setRed(pixelInOriginal.getRed());
    pixelInClone.setGreen(pixelInOriginal.getGreen());
    pixelInClone.setBlue(pixelInOriginal.getBlue());


    i think is this im sorry im really having trouble in this course i really dont understand this but im trying but its hard

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

    Default Re: java help

    Have you put that code in the program that you are working on? What happened?

    There are missing {}s following the for statements. {}s are needed to show the logic of the code.
    Code inside {}s should be indented 3-4 spaces to show nesting logic.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: java help

    ok the image turns gray but when at the end when i put this in it gives me an error

    red = Math.min(int(red * 1.08),255);

    ok i got the image to to stay gray but in the project description it gives me tells me to make image grayscale i got that part but im lost with the sepia part here description again:






    Old-fashioned photographs from the 19th century are not quite black and white and not quite color, but seem to have shades of gray, brown, and blue. This effect is called sepia. Define and test a function named sepia that converts a color image to sepia. This function first calls the grayscale function to convert the color image to grayscale. Here is a code segment for then transforming the color component value of a single pixel to achieve a sepia effect. Note that the value for green does not change.

    if (red < 63){
    red = (int)(red * 1.1);
    blue = (int)(blue * 0.9);
    }else if (red < 192){
    red = (int)(red * 1.15);
    blue = (int)(blue * 0.85);
    }else{
    red = Math.min(int(red * 1.08), 255);
    blue = (int)(blue * 0.93);
    }

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

    Default Re: java help

    it gives me an error
    If you want help with the error, copy the full text of the error message and paste it here.
    If you don't understand my answer, don't ignore it, ask a question.