Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong phash value for 195x64 images #34

Open
ursfassler opened this issue Feb 21, 2022 · 1 comment
Open

Wrong phash value for 195x64 images #34

ursfassler opened this issue Feb 21, 2022 · 1 comment

Comments

@ursfassler
Copy link

The phash is all 0 when the image is more than 194 pixels wide and has a height of 64 pixels or less, e.g. a resolution of 195x64 pixels.

Steps to reproduce:

  • Create a image with a resolution of 195x64 pixels
  • Run TestRadish with this image
  • The phash is all 0's

Problem:

  • in ph_radon_projections, projs.nb_pix_perline at index 134 is not changed, i.e. this value is 0
  • in ph_feature_vector, there is a division with the 0 value from projs.nb_pix_perline[134] (nb_pixels):
    feat_v[k] = (line_sum_sqd / nb_pixels) -
                (line_sum * line_sum) / (nb_pixels * nb_pixels);
@damix911
Copy link

damix911 commented Feb 22, 2022

I conducted a little experiment to help characterize the family of image sizes that cause the algorithm to "fail". It seems that the problem is really with aspect ratios more than with sizes.

The results suggest that any image with an aspect ratio greater than 3, as well as any image with an aspect ratio lesser than 1/2, will cause the algorithm to fail.

I wrote a program that creates a bunch of images like the following:

image

Specifically, it creates all images like that with dimensions between 1 and 128 i.e. 1x128, 128x1, 128x128 and 64x48 are all part of the input set. For each image MxNI compute the hash and store the result into pixel (M,N) of a separate 128x128 output image. I use the color blue to indicate that the hash is zero and the color yellow to indicate non-zero. This is the result.

1

The upper blue region of the output image corresponds to input images with aspect ratio greater than 3.

2

The lower blue region of the output image corresponds to input images with aspect ratio lesser than 0.5.

3

The yellow region of the output image corresponds to input images with aspect ratio between 0.5 and 3, such as the 64x48 above whose aspect ratio is 4:3.

4

As you can see, this failure space looks like a cone, and is pretty regular, but, somewhat unexpectedly, the image with size 60x119 has hash zero, despite the aspect ratio being greater than 0.5.

6
5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants