| | |
comparing images
Thread Solved |
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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()
Code with getRaster...I get a value of 0
I would appreciate any help. Thank you
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()
java Syntax (Toggle Plain Text)
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); }
java Syntax (Toggle Plain Text)
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+" "); }
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,
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,
Puneet Kalra
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
www.PuneetK.com
Sun Certified Java Programmer
Admin of Pikk - Object Relational Mapping Framework
•
•
Join Date: Oct 2007
Posts: 280
Reputation:
Solved Threads: 19
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.
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.
![]() |
Similar Threads
- Comparing Images For Similarity (Java)
- comparing images using labels (Java)
Other Threads in the Java Forum
- Previous Thread: Unable to use constructor paramaters
- Next Thread: Help me!!!!
| Thread Tools | Search this Thread |
addball android api applet application apps array arrays automation awt binary bluetooth businessintelligence busy_handler(null) button card chat class client code collision component constructor crashcourse css database draw eclipse ee error eventlistener exception fractal free game gis givemetehcodez graphics gui html ide image integer integration j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jni jpanel jtree julia jvm linux list loan machine map method methods migrate mobile netbeans newbie oracle output phone physics plazmic problem program programming project radio recursion scanner server service set sharepoint smart sms socket software sort sortedmaps sql string swing textfield threads transfer tree trolltech unlimited utility webservices windows






