I've been developing an app for quite a while now and am soon to finish. I have been blurring some images using the UIImage+ImageEffects.h
library, but now I want to switch to Gaussian blurring an UIImage
Is there any library or something similar that would allow me to gaussian blur an image in my app?
The function works by taking two arguments. The first argument will be the UIImage that you want to blur and the second argument will be the blur radius amount. Inside the function the first thing that I do is I convert the UIImage into a CIImage so that we can use CIFilter on it.
The central difference, depending on algorithm, is that Gaussian blur takes a weighted average around the pixel, while “normal” blur just averages all the pixels in the radius of the single pixel together (I believe). I think this latter “normal” blur is called box blur.
Convolution is a common image-processing technique that changes the value of a pixel according to the values of its surrounding pixels. Many common image filters, such as blurring, detecting edges, sharpening, and embossing, derive from convolution. Kernels form the basis of convolution operations.
In a Gaussian blur, the pixels nearest the centre of the kernel are given more weight than those far away from the centre. This averaging is done on a channel-by-channel basis, and the average channel values become the new value for the pixel in the filtered image.
I use following in my app.
func applyBlurEffect(image: UIImage){
var imageToBlur = CIImage(image: image)
var blurfilter = CIFilter(name: "CIGaussianBlur")
blurfilter.setValue(imageToBlur, forKey: "inputImage")
var resultImage = blurfilter.valueForKey("outputImage") as CIImage
var blurredImage = UIImage(CIImage: resultImage)
self.blurImageView.image = blurredImage
}
I think UIBlurEffect is what you want, if you want to avoid the delay. The second half of this tutorial on Gaussian blur techniques in iOS 8 walks you through adding a UIBlurEffect
to a UIImage
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With