/    Sign up×
Community /Pin to ProfileBookmark

Tough GD/colours question

Hi all

I wonder if anyone’s ever come across a way to do the following, tricky function:

Basically, I need to analyse an image for its colours. That’s no proble, but I really just want to return the main colours used, and not all the anti-alias colours used to smooth it out visually. For example, if you had an image with essentially just green and red in it, I wouldn’t want all the sub greens and reds returned (which are only there for the anti-alising). All I’d want returned are the main green and red colours as used by whoever made the image.

Surely people have come across this need before, but at the moment I can’t think how you’d do it. Perhaps you’d identify one red, then unset any subsequent reds idenfitied by colourmatchclosest()?

Thanks in advance.

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@DaiWelshNov 14.2003 — If I understand anti-aliasing correctly and if it is really just two colours then looking for the highest and lowest red value, green value and blue value would probably be a good set to start with - if you are really lucky that will actually just be the two 'base' colours. If there are more base colours than that in the image I think it will be very tricky, but you could try writing a 'between' function that returns true if each of R,G and B for colour X is between the corresponding values for colours Y and Z. Then you would loop through the colours looking for any that were 'between' any other two and eliminating them. This might work for a few different colours, but I dont think it would be 100% reliable, after all it is entirely possible that one of the 'base' colours used could be a legitimate anti-alias colour for two of the others as well ?

The only way I think you could make it more powerful is if you knew the algorithm used for the anti-aliasing and could then assess candidates more accurately.

Last idea would only work if the anti-aliasing was a small proportion of the image, then you can simply work on colours with largest number of pixels (if that is possible through GD, I tend to use it to write images not read so I am not sure).

Hope some of that helped,

Dai
Copy linkTweet thisAlerts:
@mityaauthorNov 14.2003 — Thanks for that- some good ideas. The one about counting the ocurrances of each colour in the image, by how many pixels it occupies, seems to be the best option and the most 'do-able'. So I'll give that a go and might upload it somewhere it if it turns out successful ?

Cheers.
×

Success!

Help @mitya spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...