elixir-image/image

Hamming distance is returning {:ok, 0} always.

Closed this issue · 0 comments

I have 3 images to test, image 1 and 2 are similar, and I expected the result to be less than or equal to 10. Image 3 is completely different. I'm always comparing image 1 to image 2 or image 2.

Image 1
image

Image 2
image

Image 3
image

My code is:

  {:ok, vix_image_1} = Vix.Vips.Image.new_from_file("./tmp/ap-images/image_1.png")
  {:ok, vix_image_2} = Vix.Vips.Image.new_from_file("./tmp/ap-images/image_2.png")
  {:ok, vix_image_3} = Vix.Vips.Image.new_from_file("./tmp/ap-images/image_3.png")

  {:ok, hash_image_1} = Image.dhash(vix_image_1)
  {:ok, hash_image_2} = Image.dhash(vix_image_2)
  {:ok, hash_image_3} = Image.dhash(vix_image_3)

  Image.hamming_distance(hash_image_1, hash_image_2) |> IO.inspect(label: :compare_image_1_and_image_2)
  Image.hamming_distance(hash_image_1, hash_image_3) |> IO.inspect(label: :compare_image_1_and_image_3)

The result:

compare_image_1_and_image_2: {:ok, 0}
compare_image_1_and_image_3: {:ok, 0}

I've also tried comparing the variables with vix_image_1 and vix_image_2, and vix_image_1 and vix_image_3, but the result is the same.

Does anyone have any idea what could be the problem?