Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compare similar images and return: (pixels, diff_image) #238

Closed
willjs12 opened this issue May 15, 2015 · 0 comments
Closed

Compare similar images and return: (pixels, diff_image) #238

willjs12 opened this issue May 15, 2015 · 0 comments
Labels

Comments

@willjs12
Copy link

@willjs12 willjs12 commented May 15, 2015

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)
@dahlia dahlia added the enhance label May 15, 2015
@dahlia dahlia closed this in b7efb6a Dec 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.