colordiff = (Rdiff, Gdiff, Bdiff) where
Rdiff = |R1-R2| Gdiff = |G1-G2| Bdiff = |B1-B2|
here's what I have:
Expand|Select|Wrap|Line Numbers
- import java.awt.image.*;
- import javax.imageio.*;
- import java.io.*;
- public class ImageDiff
- {
- public static void main (String args[]) throws IOException
- {
- int startX, startY, endX, endY, color1, color2;
- File imageFile1 = new File("pisa1.jpg");
- BufferedImage image1 = ImageIO.read(imageFile1);
- File imageFile2 = new File("pisa2.jpg");
- BufferedImage image2 = ImageIO.read(imageFile2);
- startX = image1.getMinX();
- startY = image1.getMinY();
- endX = startX + image1.getWidth();
- endY = startY + image1.getHeight();
- for (int i=startX; i<endX; i++) {
- for (int j=startY; j<endY; j++) {
- color1 = image1.getRGB(i,j);
- color2 = image2.getRGB(i,j);
- image1.setRGB(i,j,color1-color2);
- }
- }
- File outImage = new File("pisadiff.jpg");
- ImageIO.write(image1, "jpg", outImage);
- }
- // Converting R-G-B values into a single integer
- public static int RGBint (int R, int G, int B)
- {
- return (R*256*256+G*256+B);
- }
- // grab the R value from a single integer
- public static int getRFromRGB (int color)
- {
- return ((color & 0x00FF0000) >> 16);
- }
- // grab the G value from a single integer
- public static int getGFromRGB (int color)
- {
- return ((color & 0x0000FF00) >> 8);
- }
- // grab the B value from a single integer
- public static int getBFromRGB (int color)
- {
- return (color & 0x000000FF);
- }
- }