// This script calculates and displays the difference between two images. // A resultant image of all black would indicate no differences. // It verifies the images are the same size and assumes they are aligned. NamesDefaultToHere(1); // Get the base-line image img1 = NewImage("$Sample_Images\tile.jpg"); newWindow("img1", img1); // Get (or create) the new image // In this example, img2 becomes the opposite of img1 // If you comment out the filter("negate") line, then img2 will be the same as img1 img2 = NewImage(img1); img2 << filter("negate"); newWindow("img2", img2); // Get image sizes (width and height) { w1, h1 } = img1 << getSize(); { w2, h2 } = img2 << getSize(); if ( AND(w1 == w2, h1 == h2), // images are same size // Get the pixel values for each color component, for each image, as matrices { r1, g1, b1 } = img1 << getPixels("rgb"); { r2, g2, b2 } = img2 << getPixels("rgb"); // Calculate difference for each pixel, for each color component rd = abs(r1 - r2); gd = abs(g1 - g2); bd = abs(b1 - b2); // Create and display the image showing the difference diffImg = NewImage("rgb", {rd, gd, bd}); w = newWindow("Diff Image", diffImg); , 1, // images are not the same size show("Images are not the same size, can't diff them"); );