KilianB / JImageHash

Perceptual image hashing library used to match similar images
MIT License
401 stars 81 forks source link

Unsupported Image Formats #19

Closed anatolyra closed 5 years ago

anatolyra commented 5 years ago

Hi,

I'm facing an issue with about ~4% of the images I'm trying to generate a hash value for are not supported. The majority of the errors I get are 'UnsupportedOperationException'. I get either: java.lang.UnsupportedOperationException: The image type is currently not supported: 10 at com.github.kilianB.graphics.FastPixel.create(FastPixel.java:38) at com.github.kilianB.hashAlgorithms.PerceptiveHash.hash(PerceptiveHash.java:44) at com.github.kilianB.hashAlgorithms.HashingAlgorithm.hash(HashingAlgorithm.java:122) Example of an image that gets this error: https://console.brax-cdn.com/creatives/b86bbc0b-1fab-4ae3-9b34-fef78c1a7488/5_1200x800_ee7df89490d518b2f6fb8c739cbbfa30.png

Or: java.lang.UnsupportedOperationException: The image type is currently not supported: 13 at com.github.kilianB.graphics.FastPixel.create(FastPixel.java:38) at com.github.kilianB.hashAlgorithms.PerceptiveHash.hash(PerceptiveHash.java:44) at com.github.kilianB.hashAlgorithms.HashingAlgorithm.hash(HashingAlgorithm.java:122) Example of an image that generated this error: http://scd.pt.rfi.fr/sites/portugues.filesrfi/dynimagecache/0/42/337/190/1024/578/sites/images.rfi.fr/files/aef_image/dog2.gif

Also, for a small percentage of images I get an 'IllegalArgumentException': java.lang.IllegalArgumentException: Unknown image type 0 at java.awt.image.BufferedImage.(BufferedImage.java:501) at com.github.kilianB.graphics.ImageUtil.getScaledInstance(ImageUtil.java:40) at com.github.kilianB.hashAlgorithms.PerceptiveHash.hash(PerceptiveHash.java:44) at com.github.kilianB.hashAlgorithms.HashingAlgorithm.hash(HashingAlgorithm.java:122) For example: https://ocdn.eu/pulscms-transforms/1/xkZktkpTURBXy9iZDgyYWY0YWNmNWRhY2NlZTA1OTZkYTVmNDcwYWUyNC5wbmeSlQMCAM0DTs0B3JMFzQNSzQG9

Is this an expected behavior and will not be fixed? Or is it a bug?

Thank you!

KilianB commented 5 years ago

It is an expected behavior, but certainly not desired. It appears due to https://github.com/KilianB/UtilityCode only supporting byte and int a/rgb image formats. -> monochromatic or ushort encoded images will throw an error. For a quick fix I can create a fallback to the default java readRgb methods which is much slower but acceptable for this instance (due to rescaling not many read operations take place anyways). I had an update scheduled for this week releasing a random forest image matcher which automatically chooses the correct algorithm and settings based on labeled test data, maybe I can sneak it into the patch. (Depending on how busy the Christmas days actually are)

If you can please provide the integer value returned by this method:

bImage.getType()

for the failing images so I see which encoding should be supported the next.

KilianB commented 5 years ago

Got around to quickly fix it today. Please try version 2.1.1

anatolyra commented 5 years ago

Thank you for the quick fix! It works perfectly.