Finding the percentage of a specific colored pixel in an image

Hi. I am very new to Grasshopper and I’m trying to do something that I think Grasshopper can simply do. But I need some help.

I want to find the percentage of each color (key) represented in this image.
Is there a way I can do this with Grasshopper?

Your image is upscaled. Each pixel was transformed in 5x5 pixels (or more) and blurred with neighbors, losing accuracy of colors and such.
Do you have the original image? (always in .png )

no I do not have the original image. This was a screenshot :frowning:
Is there any way without a high res image?

after getting a very clear image as Riccardo suggested, you can Brute Force this thing using standard components, like getting the color of a given pixel by using the Image Sampler component, or equivalent components from other plugins such as Firefly

after getting the -huge- list of colors (one RGB value for each pixel) with the Member Index component you can search for the occourence of each color you are interested in

Colour (1.6 MB)

of course there might be more optimized methods using custom scripts to get faster results


consider that in my example I have just plugged in your original image, so it’s kind of blurred, and I am analyzing the original image comprehensive of the color-legend on the top left (you want to create a copy of the image to be analyzed, that does not contain the legend, otherwise also those pixel colors will be counted)

Many talking abt brute force what that

Thanks so much. I’ll try this!

yes, you are right, brute force is not the right term here

I just wanted to underline that, for the solution I proposed, the calculation time is directly related to the number of pixel, in a kind of “process them all” way, no shortcuts of any kind

1 Like