Created
May 9, 2010 11:51
-
-
Save mroth23/395107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def computeDifference(in: BufferedImage, compare: BufferedImage): BufferedImage = { | |
val w = in.getWidth | |
val h = in.getHeight | |
var result = new BufferedImage(w,h, BufferedImage.TYPE_INT_ARGB) | |
val graphics = result.getGraphics | |
graphics.setColor(java.awt.Color.BLACK) | |
graphics.clearRect(0,0,w,h) | |
for{ | |
x : Int <- 0 until w | |
y : Int <- 0 until h | |
}{ | |
val pixelA = in.getRGB(x, y) | |
val pixelB = compare.getRGB(x, y) | |
val rA = (pixelA >> 16)& 255 | |
val gA = (pixelA >> 8) & 255 | |
val bA = pixelA & 255 | |
val rB = (pixelB >> 16)& 255 | |
val gB = (pixelB >> 8) & 255 | |
val bB = pixelB & 255 | |
val diffsq = ((1 / 3) * (pow(rA - rB, 2) + pow(gA - gB, 2) + pow(bA - bB, 2))) | |
result.setRGB(x, y, ((65536 * diffsq) + (256 * diffsq) + diffsq).toInt) | |
} | |
result | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment