Image comparison with php + gd

后端 未结 4 1715
眼角桃花
眼角桃花 2020-12-28 21:15

What\'s the best approach to comparing two images with php and the Graphic Draw (GD) Library?

This is the scenario:

I have an image, and I want to

相关标签:
4条回答
  • 2020-12-28 21:54

    I would suggest, like middaparka, that you do not downsample to a 1 pixel only image, because you loose all the spatial information. Downsampling to 16x16 (or 32x32, etc.) would certainly provide better results.

    Then it also depends on whether color information is important or not to you. From what I understand you could actually do without it and compute a gray-level image starting from your color image (e.g. luma) and compute the cross-correlation. If, like you said, there is a couple of images that matches exactly (except for color information) this should give you a pretty good reliability.

    0 讨论(0)
  • 2020-12-28 21:55

    I used the ideas of scaling, downsampling and gray-level mentioned in the question and answers, to apply a Mean Squared Error between the pixels channels values for 2 images, using GD Library.

    The code is in this answer, including a test with those ideas.

    Also I did some benckmarking and I think the downsampling could be not needed in those little images, cause the method is fast (being PHP), just a fraction of a second.

    0 讨论(0)
  • 2020-12-28 22:00

    Using middparka's methods, you can transform each image into a sequence of numeric values and then use the Levenshtein algorithm to find the closest match.

    0 讨论(0)
  • 2020-12-28 22:13

    I'd have thought your approach seems reasonable, but reducing an entire image to 1x1 pixel in size is probably a step too far.

    However, if you converted each image to the same size and then computed the average colour in each 16x16 (or 32x32, 64x64, etc. depending on how much processing time/power you wish to use) cell you should be able to form some kind of sensible(-ish) comparison.

    0 讨论(0)
提交回复
热议问题