Grasshopper

algorithmic modeling for Rhino

# Limit Color Count

Dear Forum,

Been struggling with ways to limit number of colors (RGB) from Image Sampler.

Possible ways I've tried are:

1.  Rounding individual R,G,B values (0 to 1) to specific increments.  The problem with this is that when I bring the RGB values back together with Color RGB(f), the combinations create more colors than intended.

2.  Using the the RGB values as XYZ values, and using closest point.  The problem with this is that I can't figure out how to get multiple averages.  Easy to get one with Average component, but more than one??

Feedback appreciated..

Cheers,

Ognek

Views: 1236

### Replies to This Discussion

Hi Ognek,

the number of colours is limited already (there's only 16777216 different colours). You're clearly looking to project this RGB colour space onto a smaller set. But how do you define this set?

To compute multiple averages, you need to add all values together, then divide by the number of values. You should be able to get there with Mass Addition, List Length and Divide.

--

David Rutten

david@mcneel.com

David,

Thank you very much.

For the color thing:  I'd like to limit the colors with a user input.  Let's say "no more than 10 colors" means it would take all the colors from Image Sampler, and interpolate what those 10 would be based on how similar those colors are.  Thats why I thought I could find multiple averages in XYZ, and use closest point tool, then convert it back to RGB.

Does this make sense?

Ognek

Ah, I see. So you have N colours and are looking to generate a set of X different colours (where X is smaller than N) that approximate N as best as possible? This is called Color Quantization (http://en.wikipedia.org/wiki/Color_quantization#Algorithms) and it's not particularly easy.

I'll have a dig around GDI bitmap color palette functions, see if there's anything already available.

--

David Rutten

david@mcneel.com

Exactly.

That link you sent was cool.  There was a diagram that illustrates what I was trying to do changing RGB to XYZ, finding multiple averages, closest points, and converting to RGB again.  I'll try making Voronoi regions as shown in the illustration and see how that works.

Cheers David,

Ognek

Well your colours will be three-dimensional (R, G and B) so you'll need 3D voronoi diagrams.

I'm typing on this now but I think the job is far too big. I couldn't find a decent quantisizer in the .NET framework.

--

David Rutten

david@mcneel.com

baHahahahahahahaha!

u could limit the colors by posterizing them......

In case anybody is interested, here's an example of how to dither object colors based on attractors. (Grasshopper 0.9.0056)

Attachments:

• View All