img = RemoveAlphaChannel@Import["https://i.sstatic.net/nmMA6.png"];
parts = ImagePartition[img, 200];
(* see the documentation here: https://wolfram.com/xid/0enzd2s6c-6u9yga *)
countColors[img_] := Module[{count = 0},
ImageScan[If[Mean[#] != 1, count++] &, img];
Return[count]
]
Map[countColors, parts, {2}] //Grid
16306 7574 24259 7669 16459
18185 25874 19051 26063 18207
22254 20128 17908 20212 22234
18035 25878 19046 26033 18066
16216 7063 24078 7175 16327
For colour frequencies per part, this will get you a matrix of associations that count the commonest colours appearing in each. An association contains colour name $\rightarrow$ frequency pairs. I've not used DominantColors
because it does clustering and may return inexact colours not present in the image. Instead I've used the 32 most common colours including white as the basis for counting:
cols = TakeLargestBy[Tally[Flatten[ImageData[img], 1]], Last, 32];
NearestColorName = ResourceFunction["NearestColorName"];
tallycols[img_] := Association[
(RGBColor[#] -> Count[ImageData[img], #, 2]) & /@ cols[[All, 1]]
]
partcols = Map[tallycols, parts, {2}];
You can then have a look at partcols[[2, 3]]
for example:
If you need to name them you should use NearestColorName
, use ColorData
, or use a custom mapping as in an answer to a previous question of yours.
I
as a variable name. $\endgroup$