Simon Filter is the right approach to achieve the desired effect, however you need to change a couple of things.
First of all, change the order of imageLuma and thresholdLuma , since we want the black letters to remain black, and not vice versa. In addition, you must add a constant (I selected 0.01 ) to remove noise.
var thresholdKernel = CIColorKernel(string: "kernel vec4 thresholdFilter(__sample image, __sample threshold)" + "{" + " float imageLuma = dot(image.rgb, vec3(0.2126, 0.7152, 0.0722));" + " float thresholdLuma = dot(threshold.rgb, vec3(0.2126, 0.7152, 0.0722));" + " return vec4(vec3(step(thresholdLuma, imageLuma+0.001)), 1);" "}" override var outputImage: CIImage! { guard let inputImage = inputImage, let thresholdKernel = thresholdKernel else { return nil } let blurred = inputImage.applyingFilter("CIBoxBlur", withInputParameters: [kCIInputRadiusKey: 5])
And this is what you get Only using Apple Core Image, without the need to install any external libraries :)

Of course, you can play around a bit with the constant and block size values.
source share