iOS implementation image specified area blur

Source: Internet
Author: User
<span id="Label3"></p><p><p>In most image processing, we apply it to Gaussian blur images, which are often used to reduce image noise and reduce the level of Detail. In this paper, the realization of Gaussian blur and the fuzzy "beauty 美图秀秀-background blur" of the optional region are Introduced.</p></p>In the Gaussian Blur principle, it is based on a Gaussian curve that adjusts like a plain fabric value, which is selectively blurred by the Image. To put it bluntly, it is Gaussian blur can be a certain point around the image of the color of the Gaussian curve statistics, using the mathematical weighted average calculation method to get the value of the curve, and finally can leave the contour of the figure, that is, the Curve. is the bell-shaped curve that is generated when Adobe Photoshop applies a weighted average to pixels. In the middle of ps, you should know all the colors but all the numbers, all kinds of fuzzy but are algorithms.  In order to blur the value of the Color-like plain, The mathematical method of weighted average (gaussian function) to get the value, the range, radius, etc. are blurred, is roughly Gaussian blur. Gaussian fuzzy algorithm formula [using normal distribution] two-dimensional graphical representation OpenGL ES algorithm implementation<pre><pre><span style="font-size: 14px;"><strong><span style="color: #ff0000;">1.0/SQRT (2.0 * m_pi * POW (sigma, 2.0)) * Exp (-pow (currentgaussianweightindex, 2.0)/(2.0 * POW (sigma, 2.0))</span></strong></span></pre></pre><p><p></p></p><p><p>Attached: GLSL built-in exponential function description diagram</p></p><p><p></p></p><p><p><strong><span style="color: #ff0000;">In Gpuimage we can use Gpuimagegaussianblurfilter to achieve Gaussian blur. (<strong>Gpuimagegaussianblurfilter can only be blurred by the whole image, not partially blurred)</strong></span></strong></p></p><p><p>Texelspacingmultiplier is a fuzzy intensity, the greater the value, the more obvious the blur effect</p></p><p><p>The blurradiusinpixels is the pixel range used to calculate the Average.</p></p><p><p>Gaussian Blur Application</p></p><pre><span style="color: #008080;"><span style="color: #008080;">1</span></span>+ (UIImage *) applygaussianblur: (UIImage *<span style="color: #000000;"><span style="color: #000000;">) Image</span></span><span style="color: #008080;"><span style="color: #008080;">2</span></span> <span style="color: #000000;"><span style="color: #000000;">{</span></span><span style="color: #008080;"><span style="color: #008080;">3</span></span>Gpuimagegaussianblurfilter *filter =<span style="color: #000000;"><span style="color: #000000;">[[gpuimagegaussianblurfilter alloc] init];</span></span><span style="color: #008080;"><span style="color: #008080;">4</span></span> <span style="color: #008000;"><span style="color: #008000;">//</span></span><span style="color: #008000;"><span style="color: #008000;">filter.texelspacingmultiplier = 5.0;</span></span><span style="color: #008080;"><span style="color: #008080;">5</span></span>Filter.blurradiusinpixels =<span style="color: #800080;"><span style="color: #800080;">1.0</span></span><span style="color: #000000;"><span style="color: #000000;">;</span></span><span style="color: #008080;"><span style="color: #008080;">6</span></span> <span style="color: #000000;"><span style="color: #000000;">[filter forceProcessingAtSize:image.size];</span></span><span style="color: #008080;"><span style="color: #008080;">7</span></span>Gpuimagepicture *pic =<span style="color: #000000;"><span style="color: #000000;">[[gpuimagepicture alloc] initwithimage:image];</span></span><span style="color: #008080;"><span style="color: #008080;">8</span></span> <span style="color: #000000;"><span style="color: #000000;">[pic addtarget:filter];</span></span><span style="color: #008080;"><span style="color: #008080;">9</span></span> <span style="color: #000000;"><span style="color: #000000;">[pic processimage];</span></span><span style="color: #008080;"><span style="color: #008080;">Ten</span></span> <span style="color: #000000;"><span style="color: #000000;">[filter usenextframeforimagecapture];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> one</span> <span style="color: #0000ff;"><span style="color: #0000ff;">return</span></span><span style="color: #000000;"><span style="color: #000000;">[filter imagefromcurrentframebuffer];</span></span><span style="color: #008080;"><span style="color: #008080;"></span> a</span>}</pre><p><p></p></p><p><p></p></p><p><p>Gpuimagegaussianselectiveblurfilter can be partially blurred, that is, out-of-selection Blur</p></p><p><p>Excludecircleradius used to adjust the blur area</p></p><p><p>+ (UIImage *) applygaussianselectiveblur: (UIImage *) image</p></p><p><p>{</p></p><p><p>Gpuimagegaussianselectiveblurfilter *filter = [[gpuimagegaussianselectiveblurfilter alloc] init];</p></p><p><p>Filter.texelspacingmultiplier = 5.0;</p></p><p><p>Filter.excludecircleradius = 120/320.0;</p></p><p><p>[filter forceProcessingAtSize:image.size];</p></p><p><p>Gpuimagepicture *pic = [[gpuimagepicture alloc] initwithimage:image];</p></p><p><p>[pic addtarget:filter];</p></p><p><p>[pic processimage];</p></p><p><p>[filter usenextframeforimagecapture];</p></p><p><p>return [filter imagefromcurrentframebuffer];</p></p><p><p>}</p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p></p></p><p><p>iOS implementation image specified area blur</p></p></span>
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.