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

ImageColorAt out of bounds #3

Closed
TransLucida opened this issue Jan 22, 2020 · 15 comments
Closed

ImageColorAt out of bounds #3

TransLucida opened this issue Jan 22, 2020 · 15 comments

Comments

@TransLucida
Copy link

TransLucida commented Jan 22, 2020

I can see a closed issue on the same topic, the person who opened it said it had something to do with image size, but I don't think that's the case. I've been trying for the best part of an hour different types, sizes and formats and even pixel formats, and I'm getting that error a lot. Is there a way to debug this, or maybe load the image in a different way?

I also noticed in phash.php, line 193 if($width != $scale || $height !== scale) the second "scale" coming without the dollar sign. Is that supposed to be like that?

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

OMG, thank you @amandamq #Fixed.

@xwiz xwiz closed this as completed Jan 22, 2020
@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

Just to confirm, are you saying you still had issues using properly sized images? Also this was just a hobby project that gained more interest than expected. With AI libraries now, there are fast better ways to achieve face matching or similar.

@xwiz xwiz reopened this Jan 22, 2020
@TransLucida
Copy link
Author

True, I'm actually looking into using DLIB later on. I have a cache of over 32000 photos scraped from a dating website and there are a lot of repeats in it. It seems most solutions are in Python, which sadly isn't my forte. Your script worked like a charm with some photos but didn't like others.

@TransLucida
Copy link
Author

I think I figured the type of images that cause trouble and I'm very surprised I didn't notice it before: it's portrait images! For some reason it doesn't like them. It has no problem with square or landscape images, but portrait ones will always throw and out of bounds error. Any ideas? Thanks

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

Oh I see, well I once did a solution using both, basically the website is built in PHP but it calls a local python matching script via websocket and runs pretty fast. You could see a demo here: https://facematch.sci.ng/

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

Can you send me two samples of the image so I can take a look

@TransLucida
Copy link
Author

Right, I think I was a bit too fast. It is not about portrait versus landscape. In the dating site container there were many faces and inappropriate content, so I tried my iCloud folder instead and I noticed a different pattern of behaviour. Photos taken by me the ten I tried worked. Screenshots in the other hand didn't. Please take a look... https://drive.google.com/open?id=1Tft8KpAIhum-DIPMtKH168Kpnl35eEDJ

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

Well that's a bit confusing to me as they are not similar at all, unless you mean that the ones that are in DontWork produce errors with phash.

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

This is a sample of how FaceMatch demo works:

image

If you also want to compare only pictures that are actual faces, you can.

@TransLucida
Copy link
Author

TransLucida commented Jan 22, 2020

No, sorry, I should've been more clear... I don't even get to the point of comparing them with other photos. The moment the ones in the "Don't Work" folder are loaded, the script throws the "out of bounds" error. At first I thought it had something to do with pixel formats as some are RGB24 others YUV-something... then I thought it had something to do with aspect ratio. I thought that because the portrait ones were giving more errors. Then I realised it doesn't matter if it's PNG or JPG, nor RGB, YUV, it's something else. The only thing that seems bulletproof right now is that the images taken with my phone camera are read just fine, but screenshots, images downloaded from the internet... These ones throw errors.

TL;DR: it's not as much about faces as it is removing similar photos, regardless. the script loads photos taken with the phone's camera but it won't take any other type of images such as screenshots or downloaded images and throw the out of bounds error.

@xwiz
Copy link
Owner

xwiz commented Jan 22, 2020

It works fine from my own end. I tested all the images you said don't work with each other and they are not throwing errors. Have you actually used the updated/fixed code?

@TransLucida
Copy link
Author

TransLucida commented Jan 23, 2020

I did, yeah. Tried on 3 separate machines and got the exact same error on all of them. The machines are an Ubuntu Server 18.04, an Ubuntu desktop 18.04 (vm) and through CLI on my Windows 10 workstation.

D:\Phash\Samples\DontWork\d84eddc1-c501-4b05-a935-86219f768c9b.jpg
PHP Notice: imagecolorat(): 6,0 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,0 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,0 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,0 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,1 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,1 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,1 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,1 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,2 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,2 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,2 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,2 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,3 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,3 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,3 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,3 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,4 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,4 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,4 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,4 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,5 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,5 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,5 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,5 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,6 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,6 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,6 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,6 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 6,7 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 6,7 is out of bounds in D:\Phash\phash.php on line 205
PHP Notice: imagecolorat(): 7,7 is out of bounds in D:\Phash\phash.php on line 205
Notice: imagecolorat(): 7,7 is out of bounds in D:\Phash\phash.php on line 205

@xwiz
Copy link
Owner

xwiz commented Jan 23, 2020

Well there must be something missing. I don't have an image with that guid above so I can't say what's going on but the ones in the link you sent work fine. It might help to check if the images you are testing are at least 64 x 64px

@TransLucida
Copy link
Author

TransLucida commented Jan 23, 2020

Well, I've managed to get it to work but I had to change the code. In the getHash function, around line 165, instead of using file_get_contents and imagecreatefromstring, I catch the image's extension with pathinfo and depending on whether it's jpg or png I use either imagecreatefromjpeg() or imagecreatefrompng() to load the image. I'll just have to make sure the files fed into the script are only in these formats and their extensions are correct. It's not a very elegant solution and I'm sure there are better ways to do it, but it'll do for now. Thanks anyway, mate.

@xwiz
Copy link
Owner

xwiz commented Jan 23, 2020

Weird, imagecreatefromstring automatically reads correct MIME from stream unless your PHP is not configured correctly. Thanks for your contribution nevertheless.

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