1

I am trying to get an image to look like as if it had been scanned with a colour scanner). The the first image is what I have produced by using the filters below. The second image is what I would like my photo to look like. Can anyone suggest a CIFilter or combination of, to get this scanned effect?

Filters I am using:

let context = CIContext.init()

let sharpenCimage = self.sharpen(inputImage: ciimage, inputRadius: 2.5, inputIntensity: 1.0)
let colorControlCimage = self.colorControl(input: sharpenCimage!, contrast: 2.4, saturation: 0.6, brightness: 0.2)

    let CIColorMatrix = self.CIColorMatrix(inputImage: colorControlCimage!)


func colorControl(input: CIImage, contrast: Float, saturation: Float, brightness: Float) -> CIImage? {

    let filter = CIFilter(name: "CIColorControls")
    filter?.setValue(input, forKey: kCIInputImageKey)
    //filter?.setValue(contrast, forKey: kCIInputContrastKey)
    //filter?.setValue(saturation, forKey: kCIInputSaturationKey)
    //filter?.setValue(brightness, forKey: kCIInputBrightnessKey)
    filter?.setDefaults()
    return filter?.outputImage
}


func sharpen(inputImage: CIImage, inputRadius: Float, inputIntensity: Float) -> CIImage? {

    let filter = CIFilter(name: "CIUnsharpMask")
    filter?.setValue(inputImage, forKey: kCIInputImageKey)
    filter?.setValue(inputRadius, forKey: kCIInputRadiusKey)
    filter?.setValue(inputIntensity, forKey: kCIInputIntensityKey)
    return filter?.outputImage
}

func CIColorMatrix(inputImage: CIImage) -> CIImage? {

    let filter = CIFilter(name: "CIColorMatrix")
    filter?.setValue(inputImage, forKey: kCIInputImageKey)
    filter?.setDefaults()
    return filter?.outputImage
}

enter image description here

What I would like it to look like:

enter image description here

dean
  • 321
  • 3
  • 17
  • This isn't really a programming question, it's an image processing question. I suggest tinkering with the image in Photoshop. See if you can find a set of steps that produce the image you're after. Then you can figure out how to duplicate that effect using CI Filters. It looks to me like a levels adjustment and probably either a median adjustment or a gaussian blur. With a little googling I found a link that talks about how to simulate the Photoshop levels tool with a CIFilter: https://stackoverflow.com/questions/13765365/how-can-i-map-photoshops-level-adjustment-to-a-core-image-filter – Duncan C Sep 19 '18 at 18:17
  • @DuncanC thanks for the pointer. appreciate it. – dean Sep 19 '18 at 18:41
  • Possible duplicate https://stackoverflow.com/questions/46397367/how-to-adjust-a-color-image-like-a-scanned-image/46405697#46405697 – Joe Sep 20 '18 at 19:17
  • @Joe the above example only deals producing black and white 'scans'- I am also interested in colour scan? – dean Sep 21 '18 at 07:47
  • This might help you out. https://stackoverflow.com/questions/46397367/how-to-adjust-a-color-image-like-a-scanned-image – Lynneker Souza May 31 '19 at 15:52

0 Answers0