Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Gaussian Blur an image [closed]

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?

like image 668
Dan Moldovan Avatar asked Nov 20 '14 17:11

Dan Moldovan


People also ask

How do you blur an image in Swift?

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.

What is the difference between Gaussian blur and box blur?

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.

Which operation leads to the blurring of an image?

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.

How does Gaussian blur work?

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.


2 Answers

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

  }
like image 88
bpolat Avatar answered Oct 24 '22 03:10

bpolat


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.

like image 5
Judson Douglas Avatar answered Oct 24 '22 03:10

Judson Douglas