Percentage difference between images: Difference between revisions

CL example
(Parentesis in RGB diff ada code (tested on Gnat))
(CL example)
Line 115:
1.625587
</pre>
 
=={{header|Common Lisp}}==
 
This is based upon the C version. Strangely enough, the percentage is 1.77% which is off by about a tenth of a percent.
 
<pre>(require 'cl-jpeg)
;;; the JPEG library uses simple-vectors to store data. this is insane!
(defun compare-images (file1 file2)
(declare (optimize (speed 3) (safety 0) (debug 0)))
(multiple-value-bind (image1 height width) (jpeg:decode-image file1)
(let ((image2 (jpeg:decode-image file2)))
(loop for i of-type (unsigned-byte 8) across (the simple-vector image1)
for j of-type (unsigned-byte 8) across (the simple-vector image2)
sum (/ (coerce (the fixnum (abs (- i j)))
'double-float)
255.0d0)
into difference of-type double-float
finally (return (/ difference width height 3))))))</pre>
 
CL-USER> (* 100 (compare-images "Lenna50.jpg" "Lenna100.jpg"))
1.7748564676686198d0
 
=={{header|E}}==
Anonymous user