PHP Historgram Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

PHP Historgram Question

Post by rubberjohn »

I have some php code that analyses an image and returns all of the image info, for example the 'Red', 'Green', 'Blue', values for each pixel and from this I have the mean 'Red', 'Green', 'Blue', values and other averages of the image.

I want to use this information to search for similar images.

This is how I want it to work:
Basically a user uploads an image into a directory, the path and all of the histogram info is then entered into a database. Then these values are used to 'match' the image to other similar images.

Basically what I want to know is what is the best way to do the comparison, what is the best way to use the information I have gathered to find other similar images?

Thanks

RJ
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

I'd suggest a FULL TEXT index. Making an index of each of your average values, will let you search that column and get results returned back in order of relevancy. Look at the MySQL documentation for more info.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

I had previously thought of that but i thought that doing a search like that would only return an image if the values were exactly the same. Ive never coded any search stuff before, so it would be a search that would find similar values. All i would have to do is define the tolerance of the search say return an image if the Red, Green and Blue values were within 10, 20 or 50 units of each other. Is that right?

Just as a side thought, if i was to try and do some kind of pattern matching to find images that had similar content and not just colours, would it be possible to put all of the actual values (and not just the averages) into a multi-dimensional array or matrix and then do a comparison? This isnt important to my project, just for an idea.

Cheers
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's probably best to store the individual parts seperately, unless they are rarely used. a search could return false positives, or the data could easily be mangled if it turns out a tad too long.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Hmm, you could do a search kind of like this:

Code: Select all

SELECT
    *
FROM
    pictures
WHERE
    blue <= 40 AND
    blue >= 0 AND
    green <= 75 AND
    green >= 35 AND
    red <= 20 AND
    red >= 0
The RGB values could be figured out separately, and inserted.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

OnionMosaic, my PHP photomosaic software uses:

Code: Select all

&quote;select * from mos_sourceimage order by abs(&quote;.$r.&quote;-rVal)+abs(&quote;.$g.&quote;-gVal)+abs(&quote;.$b.&quote;-bVal) limit 1
That will get the nearest colour to an input colour.. Obviously $r, $g, and $b are the values of the colour you're after, and rVal, gVal, and bVal are the colour value fields in the database.

EDIT: the forum software is converting my red variable to $are. No idea why, its stupid.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

feyd - what do you mean 'the separate parts' ?

pickle - cheers that all seems to make sense

onion2k - im new at all this and dont really understand that piece of code - ill give it a go and see if i can get my head round it -- 'mos_sourceimage ' is just the table in the DB that contains the pictures but still confused about $r, $b, $g and the rVal, gVal and bVal stuff


thanks for your help
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I suggested what pickle posted about.
rubberjohn
Forum Contributor
Posts: 193
Joined: Fri Feb 25, 2005 4:03 am

Post by rubberjohn »

ok cheers ill work thru all of that
Post Reply