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

Thread: Image manipulations

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Image manipulations

    Hi,
    I am a new user, I hope I have posted in the right section.
    I have an MVC application java that captures an image from file, saving it to an object of type BufferedImage. I would like to do the AND logical operation between two images but do not know how to do, I can not find the sample code, where can I find it?
    I would use JAI but I have a 64 bit system and searching in internet I saw that JAI can be used only on 32-bit systems and jdk 1.3 or so. Or should I use OpenCV? What can I use?
    Thanks


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    do the AND logical operation between two images
    Can you explain what "AND operation" means with images? It does not make sense to me.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    580
    Thanks
    0
    Thanked 105 Times in 90 Posts

    Default Re: Image manipulations

    If you dont mind about hardware acceleration you could simply iterate over all pixels, do the calculations yourself, and write them back to a target image.

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulations

    Thanks Norm for the reply
    logical operations of which I speak have to do such as reported in this file
    https://www.google.it/url?sa=t&rct=j...66699033,d.d2k
    Thanks

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    Do you have any more questions now?
    If you don't understand my answer, don't ignore it, ask a question.

  6. #6
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulations

    The question is how do I make the logical operations between images? if there is some sample code in the internet and if I have to use a library or not.
    Thanks

  7. #7
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    logical operations between images?
    What does a "logical operation" between images mean? Can you explain what you are talking about?
    If you don't understand my answer, don't ignore it, ask a question.

  8. #8
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulations

    I need to load and load image1 image2 applicazioen in MVC, I have to get a immagine3 that contains only the parts common to both image1 and image2. I need to see some sample code. Can you help me? I do not know if I was clear.

  9. #9
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    I have to get a immagine3 that contains only the parts common to both image1 and image2
    By common parts do you mean a pixel by pixel comparison of the two images from 0,0 (upper left) to width,length (lower right)and when the pixels match, that pixel is copied to image3? What value is the pixel set to if the pixels don't match?
    If you don't understand my answer, don't ignore it, ask a question.

  10. #10
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulations

    You should compare pixel by pixel, but do not know
    Thanks

  11. #11
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    The BufferedImage class has methods that allow you to access the pixels in the image.
    If you don't understand my answer, don't ignore it, ask a question.

  12. #12
    Junior Member
    Join Date
    May 2014
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Image manipulations

    I tried to make the difference between two images in this way, but as a result I get a black image, why?

    public void Diff() throws IOException {
            BufferedImage image1 = ImageIO.read(new File("coloured-pencils.jpg"));
            BufferedImage image2 = ImageIO.read(new File("happy.jpg"));
            BufferedImage image3 = new BufferedImage(image1.getWidth(), image1.getHeight(), image1.getType());
     
     
            int img1H = image1.getHeight();
            int img1W = image1.getWidth();
     
            int img2H = image2.getHeight();
            int img2W = image2.getWidth();
     
            int argb1, alpha1, red1, green1, blue1;
            int argb2, alpha2, red2, green2, blue2;
     
            int aDiff, rDiff, gDiff, bDiff;
            int diff;
     
            if (img1H == img2H && img1W == img2W) {
                for (int x = 0; x < image1.getHeight(); x++) {
                    for (int y = 0; y < image1.getWidth(); y++) {
                        argb1 = image1.getRGB(x, y);
                        argb2 = image2.getRGB(x, y);
     
                        alpha1 = (argb1 >> 24) & 0xFF;
                        red1 = (argb1 >> 16) & 0xFF;
                        green1 = (argb1 >> 8) & 0xFF;
                        blue1 = (argb1) & 0xFF;
     
                        alpha2 = (argb2 >> 24) & 0xFF;
                        red2 = (argb2 >> 16) & 0xFF;
                        green2 = (argb2 >> 8) & 0xFF;
                        blue2 = (argb2) & 0xFF;
     
                        aDiff = Math.abs(alpha1 - alpha2);
                        rDiff = Math.abs(red1 - red2);
                        gDiff = Math.abs(green1 - green2);
                        bDiff = Math.abs(blue1 - blue2);
     
                        diff = (aDiff << 24) | (rDiff << 16) | (gDiff << 8) | bDiff;
                        image3.setRGB(x, y, diff);
                    }
     
                }
                this.setOriginalImage(image3);
            } else {
     
            }
        }
    Thanks

  13. #13
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,400
    Thanks
    49
    Thanked 2,212 Times in 2,185 Posts

    Default Re: Image manipulations

    Try doing some debugging by printing out the values of the variables that are used to see what the code is doing.
    For example what is in diff for each x and y?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. How to show the output image (using java) as resultant image in webpage
    By Mumpy Zinu in forum JavaServer Pages: JSP & JSTL
    Replies: 1
    Last Post: February 24th, 2014, 07:00 AM
  2. String Manipulations Help
    By phantasms in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 6th, 2013, 10:09 PM
  3. Selecting and dragging a image from multiple image in Java Applet
    By CY5 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 26th, 2013, 02:44 PM
  4. Create image Jpeg from an object of Image class.
    By Ramandeep in forum File I/O & Other I/O Streams
    Replies: 2
    Last Post: December 31st, 2011, 10:34 PM
  5. Replies: 2
    Last Post: February 14th, 2011, 04:36 PM