Here's how I explored your image data just-for-fun because I found it intersting and my solution to finding the number of colors represented in your image. I'm not an expert in image analysis. I suggest going through the entire answer and pay attention to the comments.
I'll address the color names at the end.
[I,cmap] = imread('image.png');
h = imshow(I);
RGB = double(I)./255;
RGBmat = reshape(RGB,,3);
[RGBunq, ~, RGBgroup] = unique(RGBmat,'rows');
nRGB = size(RGBunq,1);
From here we see that there are 13791 unique colors! Let's look at all of the colors that are represented.
[x,y] = meshgrid(1:ceil(sqrt(nRGB)), 1:ceil(sqrt(nRGB)));
ax = axes();
title('All colors in image file')
set(ax, 'XTick', , 'YTick', )
Why so many colors and why are does there appear to be near-duplicates? If you zoom into the orginal image, you'll see many smal pixels contain colors that aren't represented by the larger sections of the image. You also have RGB values that are very similar but not exactly alike.
There are several ways to deal with this. You could using image processing tools to remove the smaller "noisy" pixels. You could also choose the unique colors based on how often they appear in the image. Since your image largely consists of solid colors, I chose the latter approach. But it's not as robust as other methods. See the list of limitations to this method toward the end.
RGBcounts = histcounts(RGBgroup,[1:nRGB,inf]);
ax2 = axes();
xlabel('Ranked color index')
ylabel('Number of pixels')
title('RGB counts in the image')
As you can see, many colors are only represented by less than 100 pixels (out of 1,000,000 pixels!). If you want to ignore those colors, you can set a rule that for a color to be counted, it must consume a minimum number of pixels. This could easily be changed to a percentage of pixels. I chose 550 pixes as a minimum because that's where the frequency distribution starts to fall out. I added a horizontal line at y=550 using yline(550,'k:').
minPixCount = 550;
tooFewIdx = RGBcounts < minPixCount;
RGBunqTrim = RGBunq(~tooFewIdx,:);
nRGBtrim = size(RGBunqTrim,1);
Now there are 18 colors left (nRGBtrim = 18). Next we'll represent each remaining color and it's relative frequency in the image using a bar plot with 18 bars in order of frequency.
RGBcountsTrim = RGBcounts(~tooFewIdx);
[RGBcountTrim, sortIdx] = sort(RGBcountsTrim,'descend');
ax4 = axes();
bh = bar(RGBcountTrim,1);
bh.FaceColor = 'flat';
bh.CData = RGBunqTrim(sortIdx,:);
bh.EdgeColor = 'k';
ax4.YScale = 'log';
ylabel('Number of pixels')
title(sprintf('All colors with at least %d pixels\n(Bars show RGB color)',minPixCount))
White is the most frequent color followed by yellow, cyan, and orange.
The RGB values for each remaining color is presented in a table along with their ranking and number of pixels (out of 1,000,000).
T = array2table([(1:nRGBtrim)',RGBunqTrim(sortIdx,:),RGBcountsTrim(sortIdx)'], ...
Rank R G B nPixels
____ _______ _______ _______ _________
1 1 1 1 5.397e+05
2 1 1 0 49429
3 0 1 1 48123
4 1 0.5451 0 47655
5 0.29412 0 0.50588 47310
6 1 0.74902 0.79216 44757
7 0.64314 0.16471 0.16471 44104
8 1 0 0 41483
9 0 0.50196 0 38874
10 0 1 0 8379
11 1 0 1 8052
12 0 0 1 7982
13 0 0.50196 0.50196 5953
14 1 0.54118 0 1261
15 0.2902 0 0.50196 1076
16 1 0.7451 0.78824 970
17 0 0.49804 0 600
18 0.63922 0.16078 0.16078 551
Limitations to this method
- This method counts any pixel that matches the RGB value, even the smaller "noisy" pixels that happen to have the same color as the final selection.
- This method is not robust to precision issues. For example, [1, 1, 0.99991] is treated as a different color than [1, 1, 0.99992].
- Because of limitation #2, there could be a color with very small variation that is broken up into separate color groups which will underestimate the frequency of that closely-related color range.
There isn't a color name for every possible color but there are several functions on the file exchange that receive RGB values and return their closest matching colorname. Color names aren't typically useful during analysis and the RGB triplets are must more useful and informative. There are also eyedrop tools online that can sample a color and return a color name.