have been, for the past few weeks trying to figure out how I can compare images. From my experience in what I have been working on, I know it is almost impossible to compare two images and get a 100% match but I am not looking for a 100% match either. I have tried to employ different techniques but maybe I havent done them well, or they are just not the right ones. I will outline them below with the problems i ecountered.
PS all the images are in grayscale

Technique 1-
I got a selected number of images, got the pixel values in an array, got the max the maximum and minimum values of these arrays, and tried to compare with the image that is completely different (but with the same background). The problem here is the image seems to lie within the max and the min at times, and works well other times

Technique 2-
I tried to get the average number of pixel by pixel area so that I can use this to compare with my other image, still nothing seems to give me results. with this technique, I would sample say 5 images, get average per pixel area, save to an array. then get another 5 images that Iam comparing with, and do the same but Iam still not getting any results

Technique 3-
I wanted to count the number of white and black pixels but there is something about my array that I dont get, I mean Iam getting results that are of the likes of - -12566464 and not 255 or 0. and when I use getRaster, I end up getting only 0..

below is the code without getRaster()

BufferedImage myImage = null;
 
	int size =imgHeight * imgWidth;
	
	myImage= new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_BYTE_GRAY);
	
	PixelGrabber grabber  = new PixelGrabber(myImage,  0, 0, imgWidth , imgHeight , pixels , 0, imgWidth);
	
	try { 
	
		grabber.grabPixels();
	}
	
	catch (InterruptedException e) { 
		System.out.println(e);
	}

Code with getRaster...I get a value of 0

BufferedImage myImage = null;
	
	int size =imgHeight * imgWidth;
	
	myImage= new BufferedImage(imgWidth, imgHeight, BufferedImage.TYPE_BYTE_GRAY);
	DataBufferByte dbb = (DataBufferByte)myImage.getRaster().getDataBuffer();
   	
           byte pixels[] = dbb.getData();
    
	for (byte pix : pixels) {
                     System.out.println(pix+" ");
            }

I would appreciate any help. Thank you

I've seen a web site that suggested dividing the image into a number of blocks (eg 4 x 6) and averaging the pixels in each block (thus giving, in tis case 24 numbers) that characterise the picture. More and smaller bocks = more selective.
Maybe you can find that via Gogle?

Well, Im not sure what you meant by comparing images.

If you are trying to compare images based on pixels colors then you can use getPixelColor method of Robot class.

getPixelColor(int x, int y)
Returns the color of a pixel at the given screen coordinates.

but still it will be a memory-consuming process to compare images using this way.

Regards,

Basically i want to compare images, say image one has only a background, image 2 has the same background plus something in the foreground foreground image, and maybe the third image is slightly different from the first image(since every captured still image can never be identical)....I have used pixel grabber to grab pixels of the whole image since I dont want to do this for a specific part of the image..hope this can help abit in my question

I would second JamesCherill's suggestion of subdividing the pixel array into a smaller number of regions, perhaps 10x10, with each region assigned the average of those pixels. Then subtract the two arrays and compare the result against some tolerance threshold value to determine if they are "the same enough" for your purposes.

im new to image comparing...
im wondering how we compare images while using a videocam...
im trying to embed this on my robotic project...but has little knowledge on comparing...

Like any other image comparison, it depends on what you are wanting to accomplish. Read through the wiki on Computer Vision and figure out which area you are trying to work in. Then seek out further information on that particular branch.

This question has already been answered. Start a new discussion instead.