Get Dominant Color from imageData

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
qberty1337
Posts: 35
Joined: Sun Sep 09, 2012 1:09 pm

Get Dominant Color from imageData

Post by qberty1337 » Thu Nov 29, 2012 2:05 pm

Hey there,

I don't normally ask for help, so I could be doing this wrong, but what would be the most efficient way to find the most dominant color in an image using it's imageData?

The best I could come up with is going through every pixel and grabbing it's RGB and getting an average? Or maybe compiling a list of RGB values that are similar?

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: Get Dominant Color from imageData

Post by jmburnod » Thu Nov 29, 2012 5:15 pm

Hi qberty1337
I think the stack in attachment does a part of the job.
It is an adaptation of a Bernd's script "replace white with blue" I named it "GetColorsImages"
The button write a list of the colors RGB and sort it by the last item (the num of occurences)
Best regards
Jean-Marc
Attachments
GetColorsImageLeg24.livecode.zip
(157.03 KiB) Downloaded 308 times
https://alternatic.ch

qberty1337
Posts: 35
Joined: Sun Sep 09, 2012 1:09 pm

Re: Get Dominant Color from imageData

Post by qberty1337 » Mon Dec 24, 2012 2:26 pm

Wow, thanks for making a demo stack like that.

The only thing I hate is that it takes soo long for LC to grab those values of a small image like that.

I just wish there was a quicker way to get the most seen colour from an image.

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: Get Dominant Color from imageData

Post by Mark » Mon Dec 24, 2012 5:16 pm

Hi,

Resize the image object to make it fit 100x100 px and get the imageData. That should speed it up, although it will be less accurate.

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

qberty1337
Posts: 35
Joined: Sun Sep 09, 2012 1:09 pm

Re: Get Dominant Color from imageData

Post by qberty1337 » Tue Dec 25, 2012 2:09 pm

I was thinking of doing that. But if I had a complicated image like Album Cover Art for music files, then derezzing' it would make my dominant colour completely inaccurate. :(

Post Reply