PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Thu Jul 18, 2019 9:35 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Mon Oct 17, 2005 11:02 am 
Offline
Admin
User avatar

Joined: Wed Aug 13, 2003 7:02 am
Posts: 4522
Location: York, UK
Hi,

I currently have a plan to build a stock photo library that is going to be an addon to our internal intranet.

One feature i would like to have is...when the image is uploaded...the image is somehow analyzed, and the dominant color is somehow determined and stored in the database.

Then, users can search for "bluey" images or "yellowy" images etc.

I have seen this done on a stock photo site, but i have no idea if this is possible with PHP and GD, and even how to go about it.

Any help appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 12:07 pm 
Offline
Forum Regular
User avatar

Joined: Sat Mar 12, 2005 8:13 pm
Posts: 703
Location: US
Ok, set up variables as a point system. Something like..
$blue = 0;
$red = 0;
$green = 0;
...
Then analyze each pixel in the image. Only including red, blue and green, you'd just see which has the highest value, then give the appropriate value a 'point.' To check for light/dark, you'd just add the three up and see if it's above/below a certain number.

As long as you can look at individual pixels and see their color value, it's possible.

Seems a lot to do, though. You sure the site you're looking at doesn't just use keywords?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 2:16 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 3:19 pm 
Offline
Admin
User avatar

Joined: Wed Aug 13, 2003 7:02 am
Posts: 4522
Location: York, UK
Mate, your a legend! Image

Thanks, looks like just what i need!!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 6:04 pm 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 6:46 pm 
Offline
Neighborhood Spidermoddy
User avatar

Joined: Mon Mar 29, 2004 4:24 pm
Posts: 31559
Location: Bothell, Washington, USA
grrrraphics. ;)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 17, 2005 7:28 pm 
Offline
Breakbeat Nuttzer
User avatar

Joined: Wed Mar 24, 2004 8:57 am
Posts: 13098
Location: Melbourne, Australia


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 18, 2005 3:48 am 
Offline
Admin
User avatar

Joined: Wed Aug 13, 2003 7:02 am
Posts: 4522
Location: York, UK


Top
 Profile  
 
PostPosted: Sat Apr 19, 2008 5:52 am 
Offline
Forum Newbie

Joined: Wed Jun 15, 2005 9:47 am
Posts: 2
I haven't been to York for ages....

Back on topic. This is almost what I'm looking for. I found this class: , which extracts the colours from an image as hex values, in descending order of frequency.

What I want to do is this;
- find the most dominant colours in an image
- maintain a finite list of colours in the database, that people can search against (probably around 15)

So as I see it, there are several things I need to do;

(I hope the following is relatively coherent - I'm just writing down what's going on in my head!!)

1. from the list extracted, work out which ones are dominant / frequent enough to warrant being stored against the image
2. given a search colour from a limited set, work out which ones are close enough to provide a match

Now presumably, from the number of pixels in the image and the frequency of a particular colour, I can work out a percentage, then skim off the most dominant colours accordingly. Question is, what on earth should the cut-off point be? Should it be a pre-determined threshold (e.g. 25%)? Should I simply take the x (e.g. 3,4) most frequent colours?

Then of course, I need to either:
- only store the colours that provide a reasonable match to one of my searchable colours, or
- only flag a match when a colour stored against an image is close enough to the colour being searched for

It's starting to sound like I need to come up with some pre-determined, hard-coded values; e.g., a colour is relevant if it comprises more than 25% of an image, and a colour is a match if ABS(".$r."-rVal)+ABS(".$g."-gVal)+ABS(".$b."-bVal) is less than delta.

Anyone got any thoughts as to how I do this, or indeed how I go about choosing these values?


Top
 Profile  
 
PostPosted: Sat Apr 19, 2008 6:36 am 
Offline
Jedi Mod
User avatar

Joined: Tue Dec 21, 2004 6:03 pm
Posts: 5263
Location: usrlab.com
You shouldn't really bump a three year old thread..

What you've suggested there is the right approach anyway.


Top
 Profile  
 
PostPosted: Thu Jan 13, 2011 8:57 pm 
Offline
Forum Newbie

Joined: Thu Jan 13, 2011 8:55 pm
Posts: 1
I hate to re-bump a thread that is yet again over 2 years old since the last comment but Im looking for this solution as well.

Did you come up with the solution? If so, would you mind posting it so others (like me) can see how its done?

Thanks,
S


Top
 Profile  
 
PostPosted: Tue Jan 17, 2012 2:57 am 
Offline
Forum Newbie

Joined: Tue Jan 17, 2012 2:54 am
Posts: 1
I tried the above code, but I do get an error message:
Parse error: syntax error, unexpected '&' in /home/webrage/public_html/foto/test/out.php on line 8

Removing the line, the script works perfect. What is wrong with the section:
Syntax: [ Download ] [ Hide ]
$g   = ($rgb >>  & 0xFF;


Thanks


Top
 Profile  
 
PostPosted: Tue Jan 17, 2012 3:07 am 
Offline
Admin
User avatar

Joined: Wed Aug 13, 2003 7:02 am
Posts: 4522
Location: York, UK


Top
 Profile  
 
PostPosted: Tue Jan 17, 2012 3:41 pm 
Offline
Forum Newbie

Joined: Tue Jan 17, 2012 3:26 pm
Posts: 1


Top
 Profile  
 
 Post subject: Re:
PostPosted: Wed Jan 09, 2013 2:15 am 
Offline
Forum Newbie

Joined: Wed Jan 09, 2013 2:06 am
Posts: 1


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group