开发者

Image direct comparison vs hashing

开发者 https://www.devze.com 2023-01-05 22:40 出处:网络
I have a bunch of images to download, after their downloaded I\'d like to check them against one \"special\" image to see if the开发者_高级运维re exactly the same as this image. To do this I could jus

I have a bunch of images to download, after their downloaded I'd like to check them against one "special" image to see if the开发者_高级运维re exactly the same as this image. To do this I could just compare the arrays directly item by item or I could compute a hash and compare this.

I think in this case directly comparing will be quicker, as we only do one comparison, so the cost of hashing will be greater than saving of time spent on comparison. However, I'm not sure this reasoning is sound (which is why I'm asking). I can see that hashing comes into its own if you're doing multiple comparisons for each image but in this case I'm not.

Admittedly I could just implement both solutions and benchmark (but it's fun asking so questions).


Yep, just comparing the images pixel by pixel should be faster. But in boundary cases it may depends on the size of your image (and other contextual parameters) - for example, if your images are very large, you are better off computing a hash, cause memory accessing costs will start to peak.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号