In iOS, images are blurred in specified regions, while images in ios are blurred in specified regions.

Source: Internet
Author: User

In iOS, images are blurred in specified regions, while images in ios are blurred in specified regions.

In most image processing, we apply Gaussian blur to image processing, which is usually used to reduce image noise and reduce the level of detail. This article introduces the implementation of Gaussian blur and the blur of optional regions. [meitu xiuxiu-Background blur]

In the theory of Gaussian blur, it adjusts the pixel color value based on the Gaussian curve, and it is a selective fuzzy image. To put it bluntly, Gaussian Blur can calculate the pixel color values around a certain point based on the Gaussian curve and obtain the color value of this curve using the mathematical weighted average calculation method, at last, the outline of the character can be left, that is, the curve. this curve is generated when Adobe Photoshop applies the weighted average to pixels. In the middle of PS, you should know that all colors are numbers, and all kinds of fuzzy values are algorithms. Calculate the pixel color value to be blurred and use the weighted average calculation method (Gaussian function) to obtain the color value. blur the range and radius, which is roughly Gaussian blur. Gaussian fuzzy algorithm formula [using normal distribution] Two-Dimensional graphical representation OpenGL ES Algorithm Implementation
 1.0 / sqrt(2.0 * M_PI * pow(sigma, 2.0))) * exp(-pow(currentGaussianWeightIndex, 2.0) / (2.0 * pow(sigma, 2.0))

 

Appendix: GLSL built-in exponential function Diagram

In GPUImage, we can use GPUImageGaussianBlurFilter to implement Gaussian blur. (GPUImageGaussianBlurFilter can only blur a full image, but not partially)

TexelSpacingMultiplier indicates the Blur intensity. The greater the value, the more obvious the blur effect.

BlurRadiusInPixels is a pixel range used to calculate the average value.

Gaussian Blur Application

 1 + (UIImage *)applyGaussianBlur:(UIImage *)image 2 { 3     GPUImageGaussianBlurFilter *filter = [[GPUImageGaussianBlurFilter alloc] init]; 4 //    filter.texelSpacingMultiplier = 5.0; 5     filter.blurRadiusInPixels = 1.0; 6     [filter forceProcessingAtSize:image.size]; 7     GPUImagePicture *pic = [[GPUImagePicture alloc] initWithImage:image]; 8     [pic addTarget:filter]; 9     [pic processImage];10     [filter useNextFrameForImageCapture];11     return [filter imageFromCurrentFramebuffer];12 }

 

GPUImageGaussianSelectiveBlurFilter can be partially blurred, that is, out-of-selection fuzzy.

ExcludeCircleRadius is used to adjust the blur area.

+ (UIImage *) applyGaussianSelectiveBlur :( UIImage *) image

{

GPUImageGaussianSelectiveBlurFilter * filter = [[GPUImageGaussianSelectiveBlurFilter alloc] init];

// Filters. texelSpacingMultiplier = 5.0;

Filter. excludeCircleRadius = 120/320 .0;

[Filter forceProcessingAtSize: image. size];

GPUImagePicture * pic = [[GPUImagePicture alloc] initWithImage: image];

[Pic addTarget: filter];

[Pic processImage];

[Filter useNextFrameForImageCapture];

Return [filter imageFromCurrentFramebuffer];

}

 

 

 

 

 

 

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.