我需要从图像中获取Teeth SegmentationMatte,并为其添加一些过滤器,然后将其保存到新图像或原始图像中。
这是我当前的代码:
func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
if let pickedImage = info[UIImagePickerController.InfoKey.originalImage] as? UIImage {
pictureImageView.image = pickedImage
picture = pickedImage
if #available(iOS 13.0, *) {
let base = CIImage(cgImage: picture.cgImage!)
let maxcomp = CIFilter.maximumComponent()
maxcomp.inputImage = base
let makeup = maxcomp.outputImage
guard let pictureCgImage = picture.cgImage else { return }
let matte = CIImage(cgImage: pictureCgImage, options: [.auxiliarySemanticSegmentationTeethMatte : true,
.auxiliarySemanticSegmentationSkinMatte : false,
.auxiliarySemanticSegmentationHairMatte : false])
let blend = CIFilter.blendWithMask()
blend.backgroundImage = base
blend.inputImage = makeup
blend.maskImage = matte
let result = blend.outputImage
let context = CIContext()
guard let filteredImage = result,
let perceptualColorSpace = CGColorSpace(name: CGColorSpace.sRGB),
let imageData = context.heifRepresentation(of: filteredImage, format: .RGBA8, colorSpace: perceptualColorSpace, options: [.semanticSegmentationTeethMatteImage: filteredImage]) else { return }
let neededImage = CIImage(data: imageData) // our image with filtered teeth
}
}
dismiss(animated: true, completion: nil)
}
因此,我希望原始图像的牙齿经过过滤。但是我得到的图像是在整个图片中添加了滤镜,而不仅仅是牙齿磨砂。