ImageBufAlgo::color_count() and oiiotool --colorcount
Both can be used to count how many pixels match a given color or colors.