prominentcolor: github.com/EdlinOrg/prominentcolor Index | Files | Directories

package prominentcolor

import "github.com/EdlinOrg/prominentcolor"

Package prominentcolor finds the K most dominant/prominent colors in an image

Index

Package Files

imgprep.go kmeans.go

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}
)

func IsBitSet Uses

func IsBitSet(bitset int, lookingfor int) bool

IsBitSet check if "lookingfor" is set in "bitset"

func ProcessImg Uses

func ProcessImg(arguments int, bgmasks []ColorBackgroundMask, img image.Image) draw.Image

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 Uses

func ProcessImgOutline(bgmask ColorBackgroundMask, imgDraw *draw.Image)

ProcessImgOutline follow the outline of the image and mark all "white" pixels as transparent

type ColorBackgroundMask Uses

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 Uses

func GetDefaultMasks() []ColorBackgroundMask

GetDefaultMasks returns the masks that are used for the default settings

type ColorItem Uses

type ColorItem struct {
    Color ColorRGB
    Cnt   int
}

ColorItem contains color and have many occurrences of this color found

func Kmeans Uses

func Kmeans(orgimg image.Image) (centroids []ColorItem, err error)

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 Uses

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 Uses

func KmeansWithArgs(arguments int, orgimg image.Image) (centroids []ColorItem, err error)

KmeansWithArgs takes arguments which consists of the bits, see constants Argument*

func (*ColorItem) AsString Uses

func (c *ColorItem) AsString() string

AsString gives back the color in hex as 6 character string

type ColorRGB Uses

type ColorRGB struct {
    R, G, B uint32
}

ColorRGB contains the color values

Directories

PathSynopsis
example
example2

Package prominentcolor imports 13 packages (graph) and is imported by 4 packages. Updated 2020-04-13. Refresh now. Tools for package owners.