Contents

paletteCentroid()

Calculates the location of an image’s colors.

Declaration

class func paletteCentroid() -> any CIFilter & CIPaletteCentroid

Return Value

The modified image.

Discussion

This method applies the palette centroid filter to an image. The filter locates colors in the input image that the palette image defines and outputImage.extent provides the location of the colors of the image. You can combine with other filters to create more sophisticated images.

The palette centroid filter uses the following properties:

inputImage

An image with the type CIImage.

paletteImage

An image that has the dimensions of N x 1 where N represents the amount of colors in the image, with type CIImage.

perceptual

A Boolean value that specifies if the filter applies the color palette in a perceptual color space.

The following code creates a filter that calculates the extent of the palette color:

func paletteCentroid(inputImage: CIImage, paletteImage: CIImage) -> CIImage {
    let paletteCentroidFilter = CIFilter.paletteCentroid()
    paletteCentroidFilter.inputImage = inputImage
    paletteCentroidFilter.paletteImage = paletteImage
    paletteCentroidFilter.perceptual = false
    return paletteCentroidFilter.outputImage!
}

See Also

Color Effect Filters