×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    43

    How is it possible to compare 2 images stored in a byte[] array..??

    Hi,
    i am vinay, sir i am capturing image on mobile for every 5 seconds into byte[] array...
    So here for every 5 seconds a image is stored into array...

    From that byte[] array, i should be able to compare the 1st image data to the 2nd image data, 2nd image to 3rd image and so on....
    so how could be this done programmatically.....
    If the above is not possible tell me

    1. How can i read them separately from byte[] i.e one image after the other..??
    2. How many buffers should i take for this..... should i store each image in a
    single buffer..[ 1st image in one buffer, 2nd image in another buffer and compare
    both]??


    I really beg you help sir please find a way for this sir....

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How is it possible to compare 2 images stored in a byte[] array..??

    Well, if you want to compare two byte arrays, you need to have two byte arrays to compare. So, you need at least two buffers.

    The byte arrays you have are probably JPEG data streams. I'm not sure how useful it is to compare them in this format. You might be better off to have the raw pixel data.

    Code:
    int width = img.getWidth();
    int height = img.getHeight();
    int[] pixels = new int[width * height];
    img.getRGB(pixels, 0, width, 0, 0, width, height);
    Each int in the array is a 32 bit ARGB value for a single pixel.

    You can compare to int[] easily:

    Code:
    private static boolean areIdentical(int[] a, int[] b) {
        boolean same;
        if (a.length != b.length) {
            same = false;
        } else {
            same = true;
            int i = 0;
            while (same && i < a.length) {
                if (a[i] != b[i]) {
                    same = false;
                }
                i++;
            }
        }
        return same;
    }
    However, this will tell you only whether or not two images are identical. A slight fluctuation in lighting would cause even the smallest difference, and the two images would not be identical (even if they look the same to human eyes).

    You might want to think about how much difference between two images you want to detect.

    Graham.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    43

    Re: How is it possible to compare 2 images stored in a byte[] array..??

    Quote Originally Posted by grahamhughes View Post
    Well, if you want to compare two byte arrays, you need to have two byte arrays to compare. So, you need at least two buffers.

    The byte arrays you have are probably JPEG data streams. I'm not sure how useful it is to compare them in this format. You might be better off to have the raw pixel data.

    Code:
    int width = img.getWidth();
    int height = img.getHeight();
    int[] pixels = new int[width * height];
    img.getRGB(pixels, 0, width, 0, 0, width, height);
    Each int in the array is a 32 bit ARGB value for a single pixel.

    You can compare to int[] easily:

    Code:
    private static boolean areIdentical(int[] a, int[] b) {
        boolean same;
        if (a.length != b.length) {
            same = false;
        } else {
            same = true;
            int i = 0;
            while (same && i < a.length) {
                if (a[i] != b[i]) {
                    same = false;
                }
                i++;
            }
        }
        return same;
    }
    However, this will tell you only whether or not two images are identical. A slight fluctuation in lighting would cause even the smallest difference, and the two images would not be identical (even if they look the same to human eyes).

    You might want to think about how much difference between two images you want to detect.

    Graham.
    Hi sir,
    thanks for ur valuable reply....
    Sir how can we know that an image is in which format...
    U are saying that i am taking a jpeg image for comparision which would not work for me...
    So please tell me how can i get raw pixel data....Sir mention it programmatically sir please....

    >>**Sir my need is "I should get raw pixel data after capturing an image from mobile camera".....Sir i am new to this image processing technology so please dont disappoint me sir...give me any code which worths sir....

  4. #4
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: How is it possible to compare 2 images stored in a byte[] array..??

    Quote Originally Posted by srinivasreddy501 View Post
    tell me how can i get raw pixel data
    I already did...

    Quote Originally Posted by grahamhughes View Post
    You might be better off to have the raw pixel data.

    Code:
    int width = img.getWidth();
    int height = img.getHeight();
    int[] pixels = new int[width * height];
    img.getRGB(pixels, 0, width, 0, 0, width, height);
    Each int in the array is a 32 bit ARGB value for a single pixel.

Similar Threads

  1. wav file to Byte[] array in J2ME (+playing it)
    By norrissmith in forum Mobile Java General
    Replies: 3
    Last Post: 2011-04-16, 14:24
  2. Drawing PNG images against Array Images
    By melas21 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2004-01-19, 21:55
  3. Problem with PNG Images
    By cyphre666 in forum Mobile Java Media (Graphics & Sounds)
    Replies: 4
    Last Post: 2003-12-12, 18:20
  4. ways of drawing immutable images (stored as png file on device/disk) for 60 series.
    By montooshah in forum Mobile Java Media (Graphics & Sounds)
    Replies: 2
    Last Post: 2003-12-01, 05:42
  5. Loading images from byte array on 6130i
    By enlightment in forum Mobile Java General
    Replies: 2
    Last Post: 2002-06-05, 19:44

Posting Permissions

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