Percentage difference between images: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Fix Perl 6 -> Raku links) |
|||
Line 1,254: | Line 1,254: | ||
=={{header|Python}}== |
=={{header|Python}}== |
||
You must install the [https://pillow.readthedocs.io/ Python Imaging Library] to use this example. |
You must install the [https://pillow.readthedocs.io/ Python Imaging Library] to use this example. [https://pypi.org/project/Pillow/ Install with pip] : pip install Pillow |
||
{{works with|python version 3.x}} |
{{works with|python version 3.x}} |
||
<lang python>import Image |
<lang python>from PIL import Image |
||
i1 = Image.open("image1.jpg") |
i1 = Image.open("image1.jpg") |
||
Line 1,272: | Line 1,272: | ||
ncomponents = i1.size[0] * i1.size[1] * 3 |
ncomponents = i1.size[0] * i1.size[1] * 3 |
||
print "Difference (percentage):", (dif / 255.0 * 100) / ncomponents</lang> |
print ("Difference (percentage):", (dif / 255.0 * 100) / ncomponents)</lang> |
||
{{works with|python version 2.x}} |
{{works with|python version 2.x}} |