Created
August 1, 2022 05:31
-
-
Save NickSablukov/09901dfdd2859f69a00de9f97e7e4622 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type PixelColor [3]uint8 | |
func calculateModalAverageColour(img image.Image) PixelColor { | |
imgSize := img.Bounds().Size() | |
var redTotal, greenTotal, blueTotal, pixelsCount int64 | |
for x := 0; x < imgSize.X; x++ { | |
for y := 0; y < imgSize.Y; y++ { | |
cc := color.RGBAModel.Convert(img.At(x, y)).(color.RGBA) | |
redTotal += int64(cc.R) | |
greenTotal += int64(cc.G) | |
blueTotal += int64(cc.B) | |
pixelsCount++ | |
} | |
} | |
r := uint8(redTotal / pixelsCount) | |
g := uint8(greenTotal / pixelsCount) | |
b := uint8(blueTotal / pixelsCount) | |
return PixelColor{r, g, b} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment