-
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. My code is:
The result: compare_image_1_and_image_2: {: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? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
While I believe that the implementation of Thats partially why I implemented However if the idea is to store an image hash in a database so you can do similarity comparisons in SQL then thats not going to work. I would welcome any help on an improved image hash mechanism and I will revalidate the implementation as best I can. Let me know if |
Beta Was this translation helpful? Give feedback.
-
Arrgghhh, it does look like there is an aggegious error in |
Beta Was this translation helpful? Give feedback.
-
I've published Image version 0.38.4 that fixes this issue. Image hashes for your test imagesEach image now correctly generates a dhash. However note the limitations of image hashing. Whilst the human eye can detect the similarities between the first two images, hashing does sees quite a big difference. # Open images
iex> i1 = Image.open!("/Users/kip/Desktop/image_1.png")
%Vix.Vips.Image{ref: #Reference<0.513719039.295043093.140240>}
iex> i2 = Image.open!("/Users/kip/Desktop/image_2.png")
%Vix.Vips.Image{ref: #Reference<0.513719039.295043093.140245>}
iex> i3 = Image.open!("/Users/kip/Desktop/image_3.png")
%Vix.Vips.Image{ref: #Reference<0.513719039.295043094.141349>}
# Calculate image hashes
iex> Image.dhash i1
{:ok, <<143, 155, 120, 254, 187, 185, 205, 102>>}
iex> Image.dhash i2
{:ok, <<252, 248, 239, 210, 146, 96, 96, 152>>}
iex> Image.dhash i3
{:ok, <<3, 31, 135, 142, 55, 135, 7, 7>>}
# Calculate hamming distance. Hamming distance is just a count
# of the bits that are different between two hashes. This means that
# of the 64 bits in the hash, 37 of them are different.
iex> Image.hamming_distance i1, i2
{:ok, 37} |
Beta Was this translation helpful? Give feedback.
I've published Image version 0.38.4 that fixes this issue.
Image hashes for your test images
Each image now correctly generates a dhash. However note the limitations of image hashing. Whilst the human eye can detect the similarities between the first two images, hashing does sees quite a big difference.