Java BufferedImage Compare compareImages(BufferedImage imageOne, BufferedImage imageTwo)

Here you can find the source of compareImages(BufferedImage imageOne, BufferedImage imageTwo)

Description

compare Images

License

Open Source License

Declaration

public static double compareImages(BufferedImage imageOne, BufferedImage imageTwo) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.image.BufferedImage;

public class Main {
    public static double compareImages(BufferedImage imageOne, BufferedImage imageTwo) {
        int useWidth = imageOne.getWidth() > imageTwo.getWidth() ? imageTwo.getWidth() : imageOne.getWidth();
        int useHeight = imageOne.getHeight() > imageTwo.getHeight() ? imageTwo.getHeight() : imageOne.getHeight();

        int maxWidth = imageOne.getWidth() < imageTwo.getWidth() ? imageTwo.getWidth() : imageOne.getWidth();
        int maxHeight = imageOne.getHeight() < imageTwo.getHeight() ? imageTwo.getHeight() : imageOne.getHeight();

        int differenceCount = 0;

        for (int x = 0; x < useWidth; x++) {
            for (int y = 0; y < useHeight; y++) {
                if (imageOne.getRGB(x, y) != imageTwo.getRGB(x, y))
                    differenceCount++;/*  w  w w.  j a v  a 2s.c  om*/
            }
        }

        return differenceCount / (useWidth * useHeight) + ((maxWidth * maxHeight) - (useWidth * useHeight));

    }
}

Related

  1. compare(BufferedImage p1, BufferedImage p2)
  2. compareBufferedImages(BufferedImage bufferedImage1, BufferedImage bufferedImage2)
  3. compareImage(BufferedImage biA, BufferedImage biB)
  4. compareImage(BufferedImage img1, BufferedImage img2)
  5. compareImage(BufferedImage img1, BufferedImage img2)
  6. compareImages(BufferedImage imgA, BufferedImage imgB)
  7. compareImages(final BufferedImage firstImage, final BufferedImage secondImage)
  8. compareImages(final BufferedImage img1, final BufferedImage img2)
  9. compareImgToFile(BufferedImage img, File file)