Last active
November 6, 2016 00:46
-
-
Save r00k/dff143520347676514ac40d03c55260f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn calculate-fitness [reference-image-data individual-image-data] | |
"Takes two vectors of ints 0-255, representing the rgba data for our | |
reference image and individual-image-data. Returns the sum of squares | |
difference between the two, which represents how similar the two images are." | |
(let [differences (map - reference-image-data individual-image-data) | |
squares (map #(* % %) differences) | |
my-ints (int-array squares) | |
sum-of-squares (areduce my-ints idx ret 0 (+ ret (aget my-ints idx))) | |
maximum-difference (* (count reference-image-data) | |
(* 256 256))] | |
(- 1 (/ sum-of-squares maximum-difference)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn calculate-fitness [reference-image-data individual-image-data] | |
"Takes two vectors of ints 0-255, representing the rgba data for our | |
reference image and individual-image-data. Returns the sum of squares | |
difference between the two, which represents how similar the two images are." | |
(let [differences (map - reference-image-data individual-image-data) | |
squares (map #(* % %) differences) | |
sum-of-squares (reduce + squares) | |
maximum-difference (* (count reference-image-data) | |
(* 256 256))] | |
(- 1 (/ sum-of-squares maximum-difference)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment