For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > November 2005 > Image colours









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Image colours
Jeff Paffett

2005-11-10, 6:56 pm

Hi,

I'm working on a photo site and I want to put in a search by major
colours of the images. Can anybody point me at some useful information
for extracting this information about image files?

Jeff
Siv Hansen

2005-11-10, 6:56 pm

Jeff Paffett wrote:
> Hi,
>
> I'm working on a photo site and I want to put in a search by major
> colours of the images. Can anybody point me at some useful information
> for extracting this information about image files?
>
> Jeff

This is an issue for research, and this feature is not implemented in
all dmbs'. In Oracle (and possibly others, like Db2) you can do
this.(not mysql) How you should implement this depends on how the users
form their queries.
Jeff Paffett

2005-11-10, 6:56 pm

I maybe didn't express myself too well. I want to extract the color
information from the image file, using PHP/GD.

Siv Hansen wrote:
>
> Jeff Paffett wrote:
>
>
> This is an issue for research, and this feature is not implemented in
> all dmbs'. In Oracle (and possibly others, like Db2) you can do
> this.(not mysql) How you should implement this depends on how the users
> form their queries.

Geoff Berrow

2005-11-10, 6:56 pm

Message-ID: <1131536758.437017@athnrd02> from Jeff Paffett contained the
following:

>I maybe didn't express myself too well. I want to extract the color
>information from the image file, using PHP/GD.


I think you'd have to decide what you were looking for. Say you divided
the spectrum into black, white, red, green, blue, cyan, magenta, and
yellow.
It would be possible to look at each pixel and determine which colour it
was closest and then rank the colours in order of frequency. Whether
that would help or not, I don't know.

--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
Jeff Paffett

2005-11-10, 6:56 pm

From my reading today, it looks like I somehow need to group the pixels
by colour areas and store them in ranges of colours in the database
record for the image. These can then be searched on by percentage, to
show good colour matches. I'm just hoping that someone 'out there' has
already done this and will share their findings.

Geoff Berrow wrote:
> Message-ID: <1131536758.437017@athnrd02> from Jeff Paffett contained the
> following:
>
>
>
>
> I think you'd have to decide what you were looking for. Say you divided
> the spectrum into black, white, red, green, blue, cyan, magenta, and
> yellow.
> It would be possible to look at each pixel and determine which colour it
> was closest and then rank the colours in order of frequency. Whether
> that would help or not, I don't know.
>

Oli Filth

2005-11-10, 6:56 pm


Geoff Berrow wrote:
> Message-ID: <1131536758.437017@athnrd02> from Jeff Paffett contained the
> following:
>
>
> I think you'd have to decide what you were looking for. Say you divided
> the spectrum into black, white, red, green, blue, cyan, magenta, and
> yellow.
> It would be possible to look at each pixel and determine which colour it
> was closest and then rank the colours in order of frequency. Whether
> that would help or not, I don't know.
>


You could do this process with GD, but it'd be incredibly slow, as
you'd basically have to call imagecolorat() for every pixel. For a
typical image, e.g. 400 x 300, that's 120,000 pixels. 120,000 API
calls (and the associated data processing) in PHP is *not* going to be
fast.

This is the sort of signal processing is the sort of thing that you'd
really need to write in a fast, compiled language, and make an external
call to from PHP.

--
Oli

Geoff Berrow

2005-11-10, 6:56 pm

Message-ID: <1131548950.243505.307270@g49g2000cwa.googlegroups.com> from
Oli Filth contained the following:

>
>You could do this process with GD, but it'd be incredibly slow, as
>you'd basically have to call imagecolorat() for every pixel. For a
>typical image, e.g. 400 x 300, that's 120,000 pixels. 120,000 API
>calls (and the associated data processing) in PHP is *not* going to be
>fast.


It's not. I use this method in my watermark script. if anyone wants to
see the kind of speeds we are talking about.

www.ckdog.co.uk/watermark


--
Geoff Berrow 0110001001101100010000000110
0011011010110110010001101111011001110010
11
1001100011011011110010111001110101011010
11
Jeff Paffett

2005-11-10, 6:56 pm

Reading up on this, I'm probably going to reduce the image size before
running the process, as this will simplify the colour range anyway,
which is probably a good thing for the application I want.

I agree with Geoff that processing time will not be too bad,
particularly if I do the indexing at upload time, then store it in the
database. I was playing with a script yesterday that created the three
RGB histograms and that was working fairly fast on 2.5 meg images.

Jeff

Oli Filth wrote:
>
> Geoff Berrow wrote:
>
>
>
> You could do this process with GD, but it'd be incredibly slow, as
> you'd basically have to call imagecolorat() for every pixel. For a
> typical image, e.g. 400 x 300, that's 120,000 pixels. 120,000 API
> calls (and the associated data processing) in PHP is *not* going to be
> fast.
>
> This is the sort of signal processing is the sort of thing that you'd
> really need to write in a fast, compiled language, and make an external
> call to from PHP.
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com