Skip to content

Instantly share code, notes, and snippets.

@Zert
Created February 4, 2014 05:51
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Zert/8798756 to your computer and use it in GitHub Desktop.
Save Zert/8798756 to your computer and use it in GitHub Desktop.
(defun color-cie-de2000 (color1 color2 &optional kL kC kH)
"Return the CIEDE2000 color distance between COLOR1 and COLOR2.
Both COLOR1 and COLOR2 should be in CIE L*a*b* format, as
returned by `color-srgb-to-lab' or `color-xyz-to-lab'."
(pcase-let*
((`(,L₁ ,a₁ ,b₁) color1)
(`(,L₂ ,a₂ ,b₂) color2)
(kL (or kL 1))
(kC (or kC 1))
(kH (or kH 1))
(C₁ (sqrt (+ (expt a₁ 2.0) (expt b₁ 2.0))))
(C₂ (sqrt (+ (expt a₂ 2.0) (expt b₂ 2.0))))
(C̄ (/ (+ C₁ C₂) 2.0))
(G (* 0.5 (- 1 (sqrt (/ (expt C̄ 7.0)
(+ (expt C̄ 7.0) (expt 25 7.0)))))))
(a′₁ (* (+ 1 G) a₁))
(a′₂ (* (+ 1 G) a₂))
(C′₁ (sqrt (+ (expt a′₁ 2.0) (expt b₁ 2.0))))
(C′₂ (sqrt (+ (expt a′₂ 2.0) (expt b₂ 2.0))))
(h′₁ (if (and (= b₁ 0) (= a′₁ 0))
0
(let ((v (atan b₁ a′₁)))
(if (< v 0)
(+ v (* 2 float-pi))
v))))
(h′₂ (if (and (= b₂ 0) (= a′₂ 0))
0
(let ((v (atan b₂ a′₂)))
(if (< v 0)
(+ v (* 2 float-pi))
v))))
(ΔL′ (- L₂ L₁))
(ΔC′ (- C′₂ C′₁))
(Δh′ (cond ((= (* C′₁ C′₂) 0)
0)
((<= (abs (- h′₂ h′₁)) float-pi)
(- h′₂ h′₁))
((> (- h′₂ h′₁) float-pi)
(- (- h′₂ h′₁) (* 2 float-pi)))
((< (- h′₂ h′₁) (- float-pi))
(+ (- h′₂ h′₁) (* 2 float-pi)))))
(ΔH′ (* 2 (sqrt (* C′₁ C′₂)) (sin (/ Δh′ 2.0))))
(L̄′ (/ (+ L₁ L₂) 2.0))
(C̄′ (/ (+ C′₁ C′₂) 2.0))
(h̄′ (cond ((= (* C′₁ C′₂) 0)
(+ h′₁ h′₂))
((<= (abs (- h′₁ h′₂)) float-pi)
(/ (+ h′₁ h′₂) 2.0))
((< (+ h′₁ h′₂) (* 2 float-pi))
(/ (+ h′₁ h′₂ (* 2 float-pi)) 2.0))
((>= (+ h′₁ h′₂) (* 2 float-pi))
(/ (+ h′₁ h′₂ (* -2 float-pi)) 2.0))))
(T (+ 1
(- (* 0.17 (cos (- h̄′ (degrees-to-radians 30)))))
(* 0.24 (cos (* h̄′ 2)))
(* 0.32 (cos (+ (* h̄′ 3) (degrees-to-radians 6))))
(- (* 0.20 (cos (- (* h̄′ 4) (degrees-to-radians 63)))))))
(Δθ (* (degrees-to-radians 30)
(exp (- (expt (/ (- h̄′ (degrees-to-radians 275))
(degrees-to-radians 25)) 2.0)))))
(Rc (* 2 (sqrt (/ (expt C̄′ 7.0) (+ (expt C̄′ 7.0) (expt 25.0 7.0))))))
(Sl (+ 1 (/ (* 0.015 (expt (- L̄′ 50) 2.0))
(sqrt (+ 20 (expt (- L̄′ 50) 2.0))))))
(Sc (+ 1 (* C̄′ 0.045)))
(Sh (+ 1 (* 0.015 C̄′ T)))
(Rt (- (* (sin (* Δθ 2)) Rc))))
(sqrt (+ (expt (/ ΔL′ (* Sl kL)) 2.0)
(expt (/ ΔC′ (* Sc kC)) 2.0)
(expt (/ ΔH′ (* Sh kH)) 2.0)
(* Rt (/ ΔC′ (* Sc kC)) (/ ΔH′ (* Sh kH)))))))
@Bigbublik
Copy link

Да ты наркоман :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment