, , RGB-. , .
R, G B. .
.
int Red = 0;
int Green = 0;
int Blue = 0;
foreach (Pixels as aPixel) {
Red += aPixel.getRed();
Green += aPixel.getGreen();
Blue += aPixel.getBlue();
}
, .
, .
(, ), RGB.
.
Map ColorCounts = new();
foreach (Pixels as aPixel) {
const aRGB = aPixel.getRGB();
var aCount = ColorCounts.get(aRGB);
aCount++;
ColorCounts.put(aRGB, aCount);
}
Then look which one is bigger. You can also reduce the color resolution since regular RGB dyeing will give you up to 6.7 million colors.
This can be done easily by setting RGB color ranges. For example, let's say RGB has 8 steps, not 256.
Pseudocode
function Reduce(Color) {
return (Color/32)*32;
}
function ReduceRGB(RGB) {
return new RGB(Reduce(RGB.getRed()),Reduce(RGB.getGreen() Reduce(RGB.getBlue()));
}
Map ColorCounts = new();
foreach (Pixels as aPixel) {
const aRGB = ReduceRGB(aPixel.getRGB());
var aCount = ColorCounts.get(aRGB);
aCount++;
ColorCounts.put(aRGB, aCount);
}
Then you can see which range has the most.
I hope this technique makes sense to you.
source
share