2

Java application for Android. There is the following piece of xml:

<TableRow> <ImageView android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: layout_margin = "10dp" android: src = "@ drawable / icon_security" /> <TextView android: layout_width = "wrap_content" android: layout_height = "wrap_content" style = "@ style / DesignerTextStyle2" android: layout_gravity = "center_vertical" android: text = "@ string / welcome_security_calls" /> </ TableRow> 

I need to compare pixel image processing of the certain image on the screen (e.g. it is third image on the screen) with the famous image (i.e. this image - "@ drawable / icon_security").

Can you show me an example for solving this problem?

3
  • Are you looking to compare images using pixel values? Commented Jul 29, 2015 at 9:20
  • 1
    Comparing equality or similarity? Could you be more specific? Commented Jul 29, 2015 at 11:36
  • Comparing absolute equality Commented Jul 29, 2015 at 11:44

1 Answer 1

2

This is the Java code that I use to compare two images using pixel values from URL

package imager; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; import java.io.IOException; import java.net.URL; public class Imagecompare { public static void main(String args[]) { String s1; BufferedImage img1 = null; BufferedImage img2 = null; try { URL url1 = new URL("http://www.lac.inpe.br/JIPCookbook/Resources/ImageSimilarity/d02.jpg"); URL url2 = new URL("http://www.lac.inpe.br/JIPCookbook/Resources/ImageSimilarity/s02.jpg"); img1 = ImageIO.read(url1); img2 = ImageIO.read(url2); } catch (IOException e) { e.printStackTrace(); } int width1 = img1.getWidth(null); int width2 = img2.getWidth(null); int height1 = img1.getHeight(null); int height2 = img2.getHeight(null); if ((width1 != width2) || (height1 != height2)) { System.err.println("Error: Images dimensions mismatch"); System.exit(1); } long diff = 0; for (int y = 0; y < height1; y++) { for (int x = 0; x < width1; x++) { int rgb1 = img1.getRGB(x, y); int rgb2 = img2.getRGB(x, y); int r1 = (rgb1 >> 16) & 0xff; int g1 = (rgb1 >> 8) & 0xff; int b1 = (rgb1 ) & 0xff; int r2 = (rgb2 >> 16) & 0xff; int g2 = (rgb2 >> 8) & 0xff; int b2 = (rgb2 ) & 0xff; diff += Math.abs(r1 - r2); diff += Math.abs(g1 - g2); diff += Math.abs(b1 - b2); } } double n = width1 * height1 * 3; double p = diff / n / 255.0; double percnt = 100.0-(p*100.0); System.out.println("PERCENT: " +percnt); } } 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.