The documentation for Wand, says that the Image.compare
method returns a tuple containing the difference image and a integral number representating the difference between these.
The problem is that this number always returns a float with the value of 0.6231802821079919
, even if the images are the same!
I just want to get a value that tells me the percentage that an image differs from another.
This is my code. Its actually comparing PDFs but converts each page to images, just input the same pdf in both parameters to see that it returns 0.6231802821079919
.
What do I do with this number?
from wand.image import Image
def get_pdf_difference(control_pdf, test_pdf):
with Image(filename=control_pdf, format='pdf') as control:
with Image(filename=test_pdf, format='pdf') as test:
control.format = 'png'
test.format = 'png'
if len(control.sequence) != len(test.sequence):
raise AttributeError('PDFs are of different length')
final_diff = 0
for i, control_page in enumerate(control.sequence):
test_page = test.sequence[i]
#Docs gives an example doing this but not changing anything
#control_page.fuzz = control_page.quantum_range * 0.20
result_image, result_metric = control_page.compare(test_page)
final_diff += result_metric
return final_diff/len(control.sequence)
diff = get_pdf_difference('test.pdf', 'test.pdf')
print(diff)