Contents

coreMLModel()

Filters an image with a Core ML model.

Declaration

class func coreMLModel() -> any CIFilter & CICoreMLModel

Return Value

The modified image.

Discussion

This method applies the Core ML model filter to an image. The effect filters the image using a trained Core ML model to produce the result. Specifying the head index allows you to produce a result from various components of a multiheaded coreML model.

The Core ML model filter uses the following properties:

inputImage

An image with the type CIImage.

headIndex

A float representing which output of a multihead Core ML model should be used for applying the effect to an image.

softmaxNormalization

A Boolean value representing the softmax normalization to be applied to the output image created by the model.

inputModel

The Core ML model to be used for applying effect on the image.

The following code creates a filter that results in the flowers appearing to be glass panes:

func coreML(inputImage: CIImage) -> CIImage {
    let coreMLFilter = CIFilter.coreMLModel()
    let model = GlassModel().model
    coreMLFilter.inputImage = inputImage
    coreMLFilter.headIndex = 0
    coreMLFilter.softmaxNormalization = false
    return coreMLFilter.outputImage!
}

[Image]

See Also

Filters