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: Applying filters to immages Horizontal Flip to an image using java

  1. #1
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post Applying filters to immages Horizontal Flip to an image using java

    ImageLibrary jar file and images available @
    HTML Code:
    https://drive.google.com/folderview?id=0By-OXgq5-r0TbWs2cXRiblJpYVk&usp=sharing
    Im having trouble doing the "Horizontal Flip"..I did the psychadelic and overlay can someone please help with the horizontal flip im frustrated
    If you can please guide me in the right direction i would be really thankful, i have this due tonight..i just dont get it D:

    public class HussainDilawerA4Q1 //Class
    {  
      public static void main(String[]args) //Main Method
      {  
        double[] raster;
     
        //psychedelicImage
        ImageLibrary.loadImage("jennifer.jpg");
        raster = ImageLibrary.getImageRaster();
        double[] psychedelicImage = psycImage(raster);
        ImageLibrary.setImageRaster(psychedelicImage);
        ImageLibrary.drawImage();
     
        //OverlayImage
        ImageLibrary.loadImage("overlay-a.jpg");    
        raster = ImageLibrary.getImageRaster();
        ImageLibrary.loadImage("overlay-b.png");
        double[] raster1= ImageLibrary.getImageRaster();
        overLmethod(raster, raster1);
        ImageLibrary.setImageRaster(raster);
        ImageLibrary.drawImage();
     
        /* horizontal flip – flip an image horizontally, as shown in the example. 
    Accomplish this using a set of 2 loops, one nested in    the other. The outer
     loop goes through the y coordinates (the rows), and the inner loop goes 
    through the columns (x). To flip, simply reverse each horizontal array.
       */
     
        //HorizontalFlip
        //ImageLibrary.loadImage("jennifer.jpg");
        //raster = ImageLibrary.getImageRaster();
        //idk what to do here how many rasters and how many methods im suppose to make? 
     
      }
     
      public static double[] psycImage(double[] raster){
        //make an array to implement the changes on.
        double[] psychedelic = new double[raster.length];
     
        //Use a for loop to go through all the values and add 0.5 to it
        for(int i = 0; i < raster.length; i++){
          psychedelic[i] = raster[i]+0.5;
     
        //If the value is above 1 then subtract it by 1
          if( psychedelic[i] > 1 ){   
            psychedelic[i]=psychedelic[i]-1;
          }
        }
        return psychedelic;
      }
     
      public static void overLmethod(double[] target, double[] overlay){
     
        for(int i = 0; i < target.length; i++){
          if(overlay[i] != -1){
            target[i] = overlay[i];
     
          }
        }
      }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    How can the code be compiled and executed for testing?

    What does "flip an image horizontally" mean? For example where would the pixels in the upper left corner go?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    To compile the code and run it you need to download the ImageLibrary and import it in your ide and it all has to be in the same folder..especially your java file and all the images i provided a link to download the pdf and the jar library it explains it in there basically D: you use a swap method i think but im not sure uggh i got told i need two methods :/ im sorry im just super confused lol

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    To flip, simply reverse each horizontal array.
    Do the methods of those packages you are using return an array for the pixels?
    Is the above all that needs to be done? reverse contents of an array
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    The methods used are for the first filters are for psychedelic and overlay i don't have anything to do with them. I need to make a new method or methods to implement the horizontal flip and i need to call the method(s) in the main so when after that is done the 3rd image displayed will be a horizontal flip. It describes it in the pdf did you read where it says how the horizontal flip works? and the methods im using for psychedelic and overlay do return arrays but they contain the raster i used arrays because i needed them to go through all of the elements of the pics and all

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    Do you have any specific questions about writing java code? I'll leave the reading of the assignment and the API doc for the third party packages to you.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member IBeeJava's Avatar
    Join Date
    Mar 2013
    Location
    Winnipeg
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    horizontal flip – flip an image horizontally, as shown in the example. Accomplish this using a set of 2 loops, one nested in the other. The outer loop goes through the y coordinates (the rows), and the inner loop goes through the columns (x). To flip, simply reverse each horizontal array.

    Understandable, i need help with swapping the arrays, as in the raster image.. i want the values to flip horizontaly so it goes from 2.PNG

    TO

    Capture.PNG

    public static double[] horzFlip (double[] raster){

    for(int i = 0; i < raster.length; i++){

    }
    }

    that is the method I do not know how to flip them like how am i suppose to flip them using a swap method..

    after the methods are complete i can use this in main to show the image

    //Horizontal Flip
    ImageLibrary.loadImage("jennifer.jpg");
    raster = ImageLibrary.getImageRaster();
    double[] horizontalFlip = horzFlip(raster);
    ImageLibrary.setImageRaster(horizontalFlip);
    ImageLibrary.drawImage();

    ^ that goes in the main after the method/methods are complete?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Applying filters to immages Horizontal Flip to an image using java

    swap the pixels on the left side with the pixels at the right side
    Two indexes to the pixels: one at the left edge and one at the right edge.
    Swap the pixels at the two indexes and then increment the left index and decrement the right index
    continue until the indexes meet
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. how to flip image vertically
    By hwoarang69 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 7th, 2012, 08:11 PM
  2. Replies: 0
    Last Post: August 6th, 2011, 01:07 AM
  3. Java Tip Aug 4, 2010 - How to use File Filters
    By helloworld922 in forum Java Programming Tutorials
    Replies: 0
    Last Post: August 4th, 2010, 05:08 PM
  4. Java Tip Aug 4, 2010 - How to use File Filters
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: August 4th, 2010, 05:08 PM

Tags for this Thread