Results 1 to 8 of 8
  1. #1
    rj99 is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default xor two images to get difference

    Hi I'm writing a client/server remote viewer application where screenshots of the desktop are sent across the network over a socket. I'd like to reduce the size of the transfer by getting the difference between the two images and then sending the difference.

    I'd just like to know how would i do this is there already a ready made class that can do this or would i have to implement my own and if i do how would i do this?

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    A typical method is to split the files into chunks and send a cryptographic hash (MD5, SHA) of each. If the hashes are different then those chunks are different.

    You could look at how MPEG videos work in terms of frame-difference. There are a number of reference (or "I") frames and other frames which encode the difference between them.

    A completely different approach is to directly send the screen-update messages across the network. Depending on the platform you could use VNC or XWindow commands.

  3. #3
    rj99 is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    I want to be able to XOR the images and send the differences how do i do this in java?

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    If you xor two images, you will get another image the same size as the original. You won't reduce the transfer size by doing that.
    You need to isolate which parts of the image have changed, and send only them, or abstract instructions of how to get to the new image from the old one (e.g. add a line here, some text here, skew by this amount).

    Anyway, to XOR two images, you can use PixelGrabber or some other method of getting the underlying pixel values and work through them in a loop.
    Last edited by OrangeDog; 04-08-2009 at 03:10 AM.

  5. #5
    rj99 is offline Member
    Join Date
    Apr 2009
    Posts
    3
    Rep Power
    0

    Default

    Thanks for the reply. Can you give me some example code to xor two images together?

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Java Code:
    int[] image1;
    int[] image2;
    BufferedImage result;
    // instantiate result
    // fill arrays using PixelGrabber
    for (int x=0; x<width; x++) {
        for (int y=0; y<height; y++) {
            result.setRGB(image1[width*y+x] ^ image2[width*y+x]);
        }
    }
    The only use for this would be a bit-by-bit check of whether an image has changed - requiring unnecessary amounts of processing compared to the methods I have already outlined.

  7. #7
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Posts
    671
    Rep Power
    6

    Default

    Unless the two images are extremely similar...with no differences in scale, shift, or rotation, a difference approach will not buy you anything. I recommend converting them to jpeg at the lowest quality factor you are willing to live with.

    The javax.imagio package contains what you need to do that.

  8. #8
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    I would expect the images to be similar - screenshots of an evolving desktop are likely to change only in certain places (a character at a time in a word processor or a small window area). There certainly won't be any scale, shift or rotation transformations.

Similar Threads

  1. what is the difference
    By ron87 in forum New To Java
    Replies: 5
    Last Post: 01-04-2011, 05:31 PM
  2. What is the difference between
    By arnab321 in forum New To Java
    Replies: 2
    Last Post: 01-19-2009, 05:49 AM
  3. what is the difference between jsp and jsf?
    By makpandian in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 12-31-2008, 06:55 PM
  4. difference
    By nishant in forum New To Java
    Replies: 2
    Last Post: 09-17-2008, 07:04 PM
  5. Difference between ASP and JSP
    By barney in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 08-07-2007, 08:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •