Documentation ¶
Overview ¶
Package prominentcolor finds the K most dominant/prominent colors in an image
Index ¶
Constants ¶
const ( // ArgumentDefault default settings ArgumentDefault int = 0 // ArgumentSeedRandom randomly pick initial values (instead of K-means++) ArgumentSeedRandom = 1 << iota // ArgumentAverageMean take the mean value when determining the centroid color (instead of median) ArgumentAverageMean // ArgumentNoCropping do not crop background that is considered "white" ArgumentNoCropping // ArgumentLAB (experimental, it seems to be buggy in some cases): uses LAB instead of RGB when measuring distance ArgumentLAB // ArgumentDebugImage saves a tmp file in /tmp/ where the area that has been cut away by the mask is marked pink // useful when figuring out what values to pick for the masks ArgumentDebugImage )
const ( // DefaultK is the k used as default DefaultK = 3 // DefaultSize is the default size images are re-sized to DefaultSize = 80 )
Variables ¶
var ( // MaskWhite "constant" for white mask (for ease of re-use for other mask arrays) MaskWhite = ColorBackgroundMask{R: true, G: true, B: true, Treshold: uint32(0xc000)} // MaskBlack "constant" for black mask (for ease of re-use for other mask arrays) MaskBlack = ColorBackgroundMask{R: false, G: false, B: false, Treshold: uint32(0x5000)} // MaskGreen "constant" for green mask (for ease of re-use for other mask arrays) MaskGreen = ColorBackgroundMask{R: false, G: true, B: false, PercDiff: 0.9} )
Functions ¶
func ProcessImg ¶
ProcessImg process the image and mark unwanted pixels transparent. It checks the corners, if not all of them match the mask, we conclude it's not a clipart/solid background and do nothing
func ProcessImgOutline ¶
func ProcessImgOutline(bgmask ColorBackgroundMask, imgDraw *draw.Image)
ProcessImgOutline follow the outline of the image and mark all "white" pixels as transparent
Types ¶
type ColorBackgroundMask ¶
type ColorBackgroundMask struct {
// Setting them all to true or all to false; Treshold is used, otherwise PercDiff
R, G, B bool
// Treshold is the lower limit to check against for each r,g,b value, when all R,G,B that has true set should be above to be ignored (upper if all set to false)
Treshold uint32
// PercDiff if any of R,G,B is true (but not all), any of the other colors divided by the color value that is true, must be below PercDiff
PercDiff float32
}
ColorBackgroundMask defines which color channels to look for color to ignore
func GetDefaultMasks ¶
func GetDefaultMasks() []ColorBackgroundMask
GetDefaultMasks returns the masks that are used for the default settings
type ColorItem ¶
ColorItem contains color and have many occurrences of this color found
func Kmeans ¶
Kmeans uses the default: k=3, Kmeans++, Median, crop center, resize to 80 pixels, mask out white/black/green backgrounds It returns an array of ColorItem which are three centroids, sorted according to dominance (most frequent first).
func KmeansWithAll ¶
func KmeansWithAll(k int, orgimg image.Image, arguments int, imageReSize uint, bgmasks []ColorBackgroundMask) ([]ColorItem, error)
KmeansWithAll takes additional arguments to define k, arguments (see constants Argument*), size to resize and masks to use
func KmeansWithArgs ¶
KmeansWithArgs takes arguments which consists of the bits, see constants Argument*