Page 1 of 1
PHP Historgram Question
Posted: Fri Mar 11, 2005 3:58 am
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
Posted: Fri Mar 11, 2005 9:53 am
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.
Posted: Sun Mar 13, 2005 9:13 am
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
Posted: Sun Mar 13, 2005 10:17 am
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.
Posted: Mon Mar 14, 2005 9:57 am
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.
Posted: Tue Mar 15, 2005 8:22 am
by onion2k
OnionMosaic, my PHP photomosaic software uses:
Code: Select all
"e;select * from mos_sourceimage order by abs("e;.$r."e;-rVal)+abs("e;.$g."e;-gVal)+abs("e;.$b."e;-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.
Posted: Wed Mar 16, 2005 4:57 am
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
Posted: Wed Mar 16, 2005 9:46 am
by feyd
I suggested what pickle posted about.
Posted: Wed Mar 23, 2005 8:20 am
by rubberjohn
ok cheers ill work thru all of that