Contents

palettize()

Replaces colors with colors from a palette image.

Declaration

class func palettize() -> any CIFilter & CIPalettize

Return Value

The modified image.

Discussion

This method applies the palette filter to an image. The effect uses the palette image that is K x 1 pixels in size containing a set of colors, replacing the image colors.

The palettize filter uses the following properties:

inputImage

An image with the type CIImage.

paletteImage

An image with the dimensions of N x 1 where N represents the colors to add to 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 replaces the colors of the input image with the specified colors found in the palette image:

func palettize(inputImage: CIImage, paletteImage: CIImage) -> CIImage {
    let palettizeFilter = CIFilter.palettize()
    palettizeFilter.inputImage = inputImage
    palettizeFilter.paletteImage = paletteImage
    palettizeFilter.perceptual = true
    return palettizeFilter.outputImage!
}

[Image]

See Also

Color Effect Filters