Java BufferedImage Operation numPixelsDifferent(BufferedImage imgA, BufferedImage imgB)

Here you can find the source of numPixelsDifferent(BufferedImage imgA, BufferedImage imgB)

Description

num Pixels Different

License

Open Source License

Declaration

public static int numPixelsDifferent(BufferedImage imgA,
            BufferedImage imgB) 

Method Source Code

//package com.java2s;
/*****************************************************************************
 ** ANGRYBIRDS AI AGENT FRAMEWORK/*from w w w  . j  a  va 2s  . c  o  m*/
 ** Copyright (c) 2013,XiaoYu (Gary) Ge, Stephen Gould,Jochen Renz
 **  Sahan Abeyasinghe, Jim Keys, Kar-Wai Lim, Zain Mubashir,  Andrew Wang, Peng Zhang
 ** All rights reserved.
 **This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License. 
 **To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ 
 *or send a letter to Creative Commons, 444 Castro Street, Suite 900, Mountain View, California, 94041, USA.
 *****************************************************************************/

import java.awt.image.BufferedImage;

public class Main {
    public static int numPixelsDifferent(BufferedImage imgA,
            BufferedImage imgB) {

        int height = Math.min(imgA.getHeight(), imgB.getHeight());
        int width = Math.min(imgA.getWidth(), imgB.getWidth());
        int n = imgA.getWidth() * imgA.getHeight() + imgB.getWidth()
                * imgB.getHeight() - 2 * width * height;

        for (int y = 0; y < height; y++) {
            for (int x = 0; x < width; x++) {
                if (imgA.getRGB(x, y) != imgB.getRGB(x, y)) {
                    n += 1;
                }
            }
        }

        return n;
    }
}

Related

  1. mirror(final BufferedImage image, final boolean horizontal)
  2. newOptimizedImageLike(GraphicsConfiguration destination, BufferedImage img)
  3. newSubimage(BufferedImage src, int x, int y, int w, int h)
  4. nNeighbors(BufferedImage image, int i, int j)
  5. nrChannels(BufferedImage img)
  6. offset(final BufferedImage image, final float[] scales, final float[] offsets)
  7. open(BufferedImage image)
  8. openAsBufferedImage(String path)
  9. operatedImage(BufferedImage source, BufferedImageOp op)