<!--
{
  "availability" : [
    "iOS: 13.0.0 -",
    "iPadOS: 13.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.15.0 -",
    "tvOS: 13.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreImage",
  "identifier" : "/documentation/CoreImage/CIFilter-swift.class/palettize()",
  "metadataVersion" : "0.1.0",
  "role" : "Type Method",
  "symbol" : {
    "kind" : "Type Method",
    "modules" : [
      "Core Image",
      "CoreImage"
    ],
    "preciseIdentifier" : "c:objc(cs)CIFilter(cm)palettizeFilter"
  },
  "title" : "palettize()"
}
-->

# palettize()

Replaces colors with colors from a palette image.

```
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`](/documentation/CoreImage/CIImage).
- `paletteImage`: An image with the dimensions of *N* x 1 where *N* represents the colors to add to the image, with type [`CIImage`](/documentation/CoreImage/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:

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

![One photograph on the left above a gradient image, and a second photograph on the right. The photograph on the left shows a pink flower surrounded by foliage. The image below it is a gradient image displaying a gradual color shift from a dark purple to a light pink. The photo on the right shows the same picture of the pink flower with a palettize filter applied. The photograph displays brightness of the flower image with only the colors provided in the color palette image.](images/com.apple.coreimage/media-3558713@2x.png)

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)