Skip to content

Instantly share code, notes, and snippets.

@r00k
Last active November 6, 2016 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save r00k/dff143520347676514ac40d03c55260f to your computer and use it in GitHub Desktop.
Save r00k/dff143520347676514ac40d03c55260f to your computer and use it in GitHub Desktop.
(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))))
(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