Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.Sign up
GitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Compare similar images and return: (pixels, diff_image) #238
Would love to see Wand support the equivalent to this command line usage. This is supported by the 'RMagick" ruby gem.
diff_file = tempfile.NamedTemporaryFile(delete=False) diff_file.close() command = 'compare -metric AE ' + file1 + ' ' + file2 + ' ' + diff_file.name + ' ' + '2>&1' proc = subprocess.Popen(command, stdout=subprocess.PIPE, shell=True, universal_newlines=True) (out, err) = proc.communicate() try: pixels = int(float(out)) # pixels is the total number of pixels that were different except: print('Image comparison failed: ' + out) else: # diff_file contains an image showing all of the pixels in the 2 images where the pixels that were # different are red, and the pixels that were the same are lightened diff_img = Image(diff_file.name) os.remove(diff_file.name)
The equivalent code using the ruby gem looks like this:
img1 = Magick::Image.read(file1).first img2 = Magick::Image.read(file2).first diff_img, pixels = img1.compare_channel(img2, Magick::AbsoluteErrorMetric)