How to resolve the algorithm Percentage difference between images step by step in the Common Lisp programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Percentage difference between images step by step in the Common Lisp programming language
Table of Contents
Problem Statement
Useful for comparing two JPEG images saved with a different compression ratios. You can use these pictures for testing (use the full-size version of each): The expected difference for these two images is 1.62125%
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Percentage difference between images step by step in the Common Lisp programming language
Source code in the common programming language
(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 (the fixnum (abs (- i j))) into difference of-type fixnum
finally (return (coerce (/ difference width height #.(* 3 255))
'double-float))))))
CL-USER> (* 100 (compare-images "Lenna50.jpg" "Lenna100.jpg"))
1.774856467652165d0
You may also check:How to resolve the algorithm Priority queue step by step in the Forth programming language
You may also check:How to resolve the algorithm Grayscale image step by step in the Clojure programming language
You may also check:How to resolve the algorithm Binary digits step by step in the REXX programming language
You may also check:How to resolve the algorithm Fast Fourier transform step by step in the PARI/GP programming language
You may also check:How to resolve the algorithm Cyclotomic polynomial step by step in the Perl programming language