CIImage でフィルタリング

extension CIImage {
    func invert() -> CIImage? {
        guard let invertFilter = CIFilter(name: "CIColorInvert") else {return nil}

        invertFilter.setValue(self, forKey: kCIInputImageKey)

        return  invertFilter.outputImage
    }

    func convert(saturation: Double, bright: Double, contrast: Double) -> CIImage? {
        guard let filter1 = CIFilter(name: "CIColorControls") else {return nil}

        filter1.setValue(self, forKey: kCIInputImageKey)
        filter1.setValue(saturation, forKey: "inputSaturation")
        filter1.setValue(bright, forKey: "inputBrightness")
        filter1.setValue(contrast, forKey: "inputContrast")

        return filter1.outputImage
        }
    
    func temperatureAndTint(inTemp: CGFloat, outTemp: CGFloat) -> CIImage? {
        guard let filter = CIFilter(name: "CITemperatureAndTint") else {return nil}
        filter.setValue(self, forKey: kCIInputImageKey)
        filter.setValue(CIVector(x: inTemp, y: 0), forKey: "inputNeutral")
        filter.setValue(CIVector(x: outTemp, y: 0), forKey: "inputTargetNeutral")
        return filter.outputImage
    }
    
    func rgbaMatrix() -> CIImage?
    {
        guard let filter = CIFilter(name: "CIColorMatrix") else {return nil}
        let ciImage = self
        filter.setValue(ciImage, forKey: kCIInputImageKey)
        filter.setValue(CIVector(x: 1.0, y: 0, z: 0, w: 0.0), forKey: "inputRVector")
        filter.setValue(CIVector(x: 0, y: 1.0, z: 0, w: 0.0), forKey: "inputGVector")
        filter.setValue(CIVector(x: 0, y: 0, z: 1.0, w: 0.0), forKey: "inputBVector")
        filter.setValue(CIVector(x: 0, y: 0, z: 0, w: 1), forKey: "inputAVector")
        filter.setValue(CIVector(x: 0, y: 0, z: 0, w: 0), forKey: "inputBiasVector")
        return filter.outputImage
    }
}