I need to extract all relevant data from a simple pie char image which data changes from time to time.
There's an example of the simple pie chart:

How can I define a Python function to get something like: green=26, grey=15, red=4?
Thanks in advance for your support.
I dont have a clue how to do this.
The quickest, easiest way, if you are not used to image processing is as follows:
For the sake of speed, I'll show you how to do it with ImageMagick then we can work on a Python version afterwards.
First make your swatch:
Enlarged version of
swatch.png:You can choose the colours using names, or using
rgb()triplets if you prefer, e.g.:Now remap the colours in your pie chart to the swatch and suppress dithering:
I am remapping to a known colour palette because your JPEG is compressed and has thousands of colours all with slight variations, whereas we want the colours all binned into the colours in your pie chart.
Now check the histogram:
Now you can see there are 52,565 green pixels out of 90,848 non-white pixels (52565+31115+7168) making 57%. There are 31,115 light grey pixels out of 90,848 making 34% and 7,168 salmon pixels making 8%.
If you want to do the same thing with Python, you could use PIL/Pillow like this:
Output
The fourth line is telling you how many pixels there are of each colour, so 67,000 white pixels, 52,578 green pixels and so on.