Here you can find the source of compareImage(BufferedImage img1, BufferedImage img2)
Parameter | Description |
---|---|
img1 | a parameter |
img2 | a parameter |
public static double compareImage(BufferedImage img1, BufferedImage img2)
//package com.java2s; //License from project: Apache License import java.awt.image.BufferedImage; import java.awt.image.Raster; public class Main { /**// ww w. j av a 2 s . c om * Assume that img1, img2 sizes are equals * @param img1 * @param img2 * @return */ public static double compareImage(BufferedImage img1, BufferedImage img2) { Raster data1 = img1.getRaster(); Raster data2 = img2.getRaster(); int width = data1.getWidth(); int height = data2.getHeight(); double[] p1 = new double[3]; double[] p2 = new double[3]; double result = 0; for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { data1.getPixel(x, y, p1); data2.getPixel(x, y, p2); result += Math.abs(comparePixel(p1, p2)); } } return result; } public static double comparePixel(double[] p1, double[] p2) { double result = 0; for (int i = 0; i < p1.length; i++) { result += Math.abs(p2[i] - p1[i]); } return result; } public static int comparePixel(int[] p1, int[] p2) { int result = 0; for (int i = 0; i < p1.length; i++) { result += Math.abs(p2[i] - p1[i]); } return result; } }