Search code examples
iosswiftcore-imagecifilter

Swift core image apply sharpen to image without CIFilter


in core image we can use some filters and adding this filters to sharpen but when I want to apply only sharpen to image we need a filter. How can I use this without using CIFilter.

Here is the code sample for apply sharpen with CIFilter:

    let filter = CIFilter(name: "CIPhotoEffectChrome")
    filter.setValue(beginImage, forKey: kCIInputImageKey)
    filter.setValue(1, forKey: kCICategorySharpen)
    let outputImage = filter.outputImage

Solution

  • I'm afraid your code does not really sharpen the input. It's just "applying a "Chrome" style effect to an image" (from the docs). The CIPhotoEffectChrome filter does not have a parameter for sharpening the input.

    You rather need to pick one of the filters from the CICategorySharpen, e.g.:

    let filter = CIFilter(name: "CIUnsharpMask")
    filter.setValue(beginImage, forKey: kCIInputImageKey)
    filter.setValue(2.0, forKey: "inputIntensity")
    filter.setValue(1.0, forKey: "inputRadius")
    let outputImage = filter.outputImage
    

    But why don't you want to use Core Image? It should be the best tool for the job.