Modify and Compare 2 images in Java -



Modify and Compare 2 images in Java -

i have got assignment need validate images. have got 2 sets of folders 1 actual , other folder contain expected images. these images of brands/companies.

upon initial investigation, found images of each brand have different dimension of same format i.e png

what have done far:- upon googling found below code compares 2 images. ran code 1 of brand , ofcourse result false. modify 1 of image such both images have same dimension.. got same result.

public void testimage() throws interruptedexception{ string file1="d:\\image\\bliss_url_2.png"; string file2="d:\\bliss.png"; image image1 = toolkit.getdefaulttoolkit().getimage(file1); image image2 = toolkit.getdefaulttoolkit().getimage(file2); pixelgrabber grab1 =new pixelgrabber(image1, 0, 0, -1, -1, true); pixelgrabber grab2 =new pixelgrabber(image2, 0, 0, -1, -1, true); int[] data1 = null; if (grab1.grabpixels()) { int width = grab1.getwidth(); int height = grab1.getheight(); system.out.println("initial width , height of image 1:: "+width + ">>"+ height); grab2.setdimensions(250, 100); system.out.println("width , height of image 1:: "+width + ">>"+ height); data1 = new int[width * height]; data1 = (int[]) grab1.getpixels(); system.out.println("image 1:: "+ data1); } int[] data2 = null; if (grab2.grabpixels()) { int width = grab2.getwidth(); int height = grab2.getheight(); system.out.println("width , height of image 2:: "+width + ">>"+ height); data2 = new int[width * height]; data2 = (int[]) grab2.getpixels(); system.out.println("image 2:: "+ data2.tostring()); } system.out.println("pixels equal: " + java.util.arrays.equals(data1, data2)); }

i want verify if content of images same i.e images belong same brand ,if not differences

please help me should do valid comparison.

maybe should not utilize external library assuming should own work. in point of view, way compare images average color of same portion of both images. if results equals (or similar due compression errors etc)

lets have 2 images image 1 4 pixel. (to simplify each pixel represented number should rgb)

1 2 3 4

[ (1+2+3+4) / 4 = 2.5 ]

image 2 twice bigger

1 1 2 2 1 1 2 2 3 3 4 4 3 3 4 4

[ ((4*1)+(4*2)+(4*3)+(4*4)) / 16 = 2.5]

the average pixel value (color) 2.5 in both images. (with real pixel colors, compare rgb colors separately. 3 should equal or close)

that's idea. now, should create caumputing each pixel of smallest image , corresponding pixels of bigest 1 (according scale difference of both images)

hope you'll find out solution !

java image-processing

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -