Question

I am comparing 2 similar images and would like to see if both are similar .Currently I used the code:

public void foo(Bitmap bitmapFoo) {
    int[] pixels;

    int height = bitmapFoo.getHeight();
    int width = bitmapFoo.getWidth();

    pixels = new int[height * width];

    bitmapFoo.getPixels(pixels, 0, width, 1, 1, width - 1, height - 1); 


}

and I call the function : foo(img1) where :

img1=(Bitmap)data.getExtras().get("data");

I would like to know how to get the above getpixel,I tried assigning it to variable but did not work .Should it have a return type ?? and in format it is ?

And also how do I compare 2 images??

Also both the images may be of different dimensions based on the mobile camera the snapshot is taken from .

Also can it recognize if the same image is shot in the morning and night ???

Thanks in Advance.

Was it helpful?

Solution 2

If you want to copy the pixels of the bitmap to a byte array, the easiest way is:

int height = bitmapFoo.getHeight();
int width = bitmapFoo.getWidth();

pixels = new int[height * width];

bitmapFoo.copyPixelsToBuffer(pixels);

See the documentation

I should warn you that you will have to handle this with care, any other way you will get OutOfMemoryError.

To get All Pixels

bitmapFoo.copyPixelsToBuffer(pixels);

or

bitmapFoo.getPixels(pixels, 0, width, 0, 0, width, height);

To get One Pixel

The two arguments must be two integers within the range [0, getWidth()-1] and [0, getHeight()-1]

int pix = bitmapFoo.getPixel(x, y);

OTHER TIPS

This code will compare pixel from base image with other image.

  1. If both pixel at location (x,y) are same then add same pixel in result image without change. Otherwise it modifies that pixel and add to our result image.

  2. In case of baseline image height or width is larger than other image then it will add red color for extra pixel which is not available in other images.

  3. Both image file format should be same for comparison.

  4. Code will use base image file format to create resultant image file and resultant image contains highlighted portion where difference observed.

Here is a Link To Code with sample example attached.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top