search
HomeWeb Front-endPS TutorialAlgorithm summary of Photoshop Gaussian blur filter

recently felt that some netizens' research on Gaussian blur filter is now summarized as follows. Gaussian blur is a kind of digital image template processing method. Its template is calculated based on a two-dimensional normal distribution (Gaussian distribution) function.
The normal distribution was first obtained by A. Demoivre in finding the asymptotic formula of the binomial distribution. C.F. Gauss derived it from another angle when studying measurement error. P.S. Laplace and Gauss studied its properties. Hence the name Gaussian blur.

Function definition of one-dimensional normal distribution:

Distribution of type random variables, the first parameter μ is the mean value of the random variable that follows the normal distribution , the second parameter σ2 is the variance of this random variable, so the normal distribution is recorded as N(μ, σ2). The probability rule of a random variable that follows a normal distribution is that the probability of taking a value near μ is high, and the probability of taking a value that is farther away from μ is smaller; the smaller σ, the more concentrated the distribution is near μ, and the larger σ, the smaller the distribution. dispersion. The characteristics of the density function of the normal distribution are: symmetric about μ, reaching a maximum value at μ, taking a value of 0 at positive (negative) infinity, and having an inflection point at μ±σ. Its shape is high in the middle and low on both sides, and the image is a bell-shaped curve above the x-axis. When μ = 0, σ2 = 1, it is called the standard normal distribution, recorded as N (0, 1). Algorithm summary of Photoshop Gaussian blur filter

The meaning of the two constants: μ-expectation, σ^2 variance.

Below we solve the first question: What is the radius in the Gaussian blur filter? The answer is that the Gaussian radius is σ in the formula.

                                                                                                                      ’ ’ s ’ ’ s ’ s ’ s ’                     ’ ’ ’ s ’ ’ s ’ ’ s ’ s ’ s ‐ ‐ ‐ ‑ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ​ ‐ ​ ​ ​ ​ ​# It can be seen that the Gaussian radius (σ) affects the shape of the curve. The smaller the σ, the higher and sharper the curve. The larger the σ, the lower and gentler the curve. For a two-dimensional image, it is a bell-shaped surface. The smaller the Gaussian radius, the higher, sharper, and steeper the surface; the larger the Gaussian radius, the lower and gentler the surface. Therefore, the smaller the Gaussian radius, the smaller the blur, and the larger the Gaussian radius, the greater the blur. We will see that ps defines the range of Gaussian radius as [0.1~250]. When the radius is 0.1, only the middle pixel of the Gaussian template is 1 after calculation, and the other pixels are all = 0 (actually just approaching 0), that is, the image will not change.

The second question is, what is the relationship between Gaussian template size and Gaussian radius? This is a misunderstanding that has always troubled us. Because our thinking has entered the misunderstanding of physical implementation. In the physical implementation, the Gaussian template is bounded, causing us to ignore the real answer to this question: the Gaussian template is logically unbounded. That is to say, the Gaussian template is essentially an approximation of a logically infinite extended surface. Therefore, the template size should be considered infinite. It's just that during calculation, because it approaches 0 in the distance, we no longer consider these values ​​below a certain threshold. This threshold is the template boundary.

Below, the formula of the two -dimensional Gaussian surface (x, y represents the template coordinates of pixels, the center position of the template is the origin):

Algorithm summary of Photoshop Gaussian blur filter

That is: g(x,y)= ( 1 / (2*pi*σ^2) ) * exp( -(x^2+y^2)/(2*σ^2 ) ) ;


Based on this formula, we can calculate the Gaussian templates under different radii. In fact, the templates are infinite, but they will approach 0 far away from the center. For example, we calculate r A normalized Gaussian template when =0.7:

高斯模板(guass radius=0.700000)
//guass radius=0.700000
0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   
0.000000   0.000000   0.000001   0.000012   0.000033   0.000012   0.000001   0.000000   0.000000   
0.000000   0.000001   0.000093   0.001976   0.005481   0.001976   0.000093   0.000001   0.000000   
0.000000   0.000012   0.001976   0.042189   0.117046   0.042189   0.001976   0.000012   0.000000   
0.000000   0.000033   0.005481   0.117046   0.324724   0.117046   0.005481   0.000033   0.000000   
0.000000   0.000012   0.001976   0.042189   0.117046   0.042189   0.001976   0.000012   0.000000   
0.000000   0.000001   0.000093   0.001976   0.005481   0.001976   0.000093   0.000001   0.000000   
0.000000   0.000000   0.000001   0.000012   0.000033   0.000012   0.000001   0.000000   0.000000   
0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000   0.000000  

 

         在网络上众所周知流传的高斯3*3模板实际上是对高斯曲面的一个整数除法形式的近似:

         1 2 1

         2 4 2    /16

         1 2 1

Actual verification, we found that this 3*3 template is actually an approximation of the Gaussian radius when it is about 0.849. When r=0.849, its 3*3 normalized template is (in MATLAB, enter h=fspecial('gaussian', 3, 0.849);You can get this template): 0.062467 0.125000 0.062467

0.125000 0.250131 0.125000

0.062467 0.125000 0.06246 7## Then we can use imfilter in Matlab to perform Gaussian blur processing on the image:


img = imread('c:\demo.bmp');
h = fspecial('gaussian', 3, 0.849);

img2 = imfilter(img, h) ;

subplot(121), imshow(img); title('Original image')

subplot(122), imshow(img2); title('After Gaussian blur')





# The effect is as follows:
We can use it in Matlab as follows Statement to draw Gaussian surface:

Matlab code for drawing Gaussian surface

Algorithm summary of Photoshop Gaussian blur filter

Code highlighting produced by Actipro CodeHighlighter (freeware)

http:/ /www.php.cn/

-->%Draw a Gaussian blur surface!

#include
math.h>include
stdio.h>
define## N 3 3                       / * Template size: (2N+1) * (2N+1) */
void
main(){

double
a[2*N+1][2*N+1]; ​ /* Gaussian template*/                                                                                                                                                 /* Gaussian radius: [0.1, 250] */
double A=1/
(2
*##M_PI*r*r);   int i,j;     for(i=-
1*
N;i
N;i++)          for(j=-1 *N;j
N;j++)a[i
+N][j+N]=A *exp((-1)*(i*i+j*j)/ (2*r*r));
}

## At the same time, as a comparison, we give the code to generate a Gaussian template in Matlab (the code part of fspecial, where p3 is the third parameter That is Gaussian radius):

  case 'gaussian' % Gaussian filter

     siz   = (p2-1)/2;  %注:p2即模板边长,默认值为33
     std   = p3;        %注:p3即高斯半径,默认为为0.5
     
     [x,y] = meshgrid(-siz(2):siz(2),-siz(1):siz(1));
     arg   = -(x.*x + y.*y)/(2*std*std);

     h     = exp(arg);
     h(h<eps*max(h(:))) = 0;

     sumh = sum(h(:));  %注:模板归一化
     if sumh ~= 0,
       h  = h/sumh;
     end;

For more related articles on the algorithm summary of Photoshop Gaussian blur filter, please pay attention to the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Using Photoshop for Graphic Design: Branding and MoreUsing Photoshop for Graphic Design: Branding and MoreApr 16, 2025 am 12:02 AM

The steps to using Photoshop for brand design include: 1. Use the Pen tool to draw basic shapes, 2. Add shadows and highlights through layer styles, 3. Adjust colors and details, 4. Use smart objects and actions to automatically generate different versions of the design. Photoshop helps designers create and optimize brand elements with the flexibility of layers and masks, ensuring consistency and professionalism of designs, from simple logos to complex branding guides.

Photoshop's Subscription Model: What You Get for Your MoneyPhotoshop's Subscription Model: What You Get for Your MoneyApr 15, 2025 am 12:17 AM

Photoshop's subscription model is worth buying. 1) Users can access the latest version and use across devices at any time. 2) The subscription fee is low, and continuous updates and technical support are provided. 3) Advanced functions such as neural filters can be used for complex image processing. Despite the high long-term costs, its convenience and feature updates are valuable to professional users.

Photoshop: Investigating Free Trials and Discount OptionsPhotoshop: Investigating Free Trials and Discount OptionsApr 14, 2025 am 12:06 AM

You can get the access to Photoshop in the most economical way: 1. Experience the software features with a 7-day free trial; 2. Find student or teacher discounts, as well as seasonal promotions; 3. Use coupons on third-party websites; 4. Subscribe to Adobe CreativeCloud's monthly or annual plan.

Photoshop for Designers: Creating Visual ConceptsPhotoshop for Designers: Creating Visual ConceptsApr 13, 2025 am 12:09 AM

Creating visual concepts in Photoshop can be achieved through the following steps: 1. Create a new document, 2. Add a background layer, 3. Use the brush tool to draw basic shapes, 4. Adjust colors and brightness, 5. Add text and graphics, 6. Use masks for local editing, 7. Apply filter effects, these steps help designers build a complete visual work from scratch.

Is Photoshop Free? Understanding Subscription PlansIs Photoshop Free? Understanding Subscription PlansApr 12, 2025 am 12:11 AM

Photoshop is not free, but there are several ways to use it at low cost or free: 1. The free trial period is 7 days, and you can experience all functions during this period; 2. Student and teacher discounts can cut costs by half, and school proof is required; 3. The CreativeCloud package is suitable for professional users and includes a variety of Adobe tools; 4. PhotoshopElements and Lightroom are low-cost alternatives, with fewer functions but lower prices.

Photoshop's Value: Weighing the Cost Against Its FeaturesPhotoshop's Value: Weighing the Cost Against Its FeaturesApr 11, 2025 am 12:02 AM

Photoshop is worth the investment because it provides powerful features and a wide range of application scenarios. 1) Core functions include image editing, layer management, special effects production and color adjustment. 2) Suitable for professional designers and photographers, but amateurs may consider alternatives such as GIMP. 3) Subscribe to AdobeCreativeCloud can be used as needed to avoid high one-time spending.

The Core Purpose of Photoshop: Creative Image DesignThe Core Purpose of Photoshop: Creative Image DesignApr 10, 2025 am 09:29 AM

Photoshop’s core use in creative image design is its powerful functionality and flexibility. 1) It allows designers to transform creativity into visual reality through layers, masks and filters. 2) Basic usages include cropping, resizing and color correction. 3) Advanced usages such as layer styles, blend modes and smart objects can create complex effects. 4) Common mistakes include improper layer management and excessive use of filters, which can be solved by organizing layers and using filters reasonably. 5) Performance optimization and best practices include rational use of layers, regular saving of files, and using shortcut keys.

Photoshop for Web Design: Advanced Techniques for UI/UXPhotoshop for Web Design: Advanced Techniques for UI/UXApr 08, 2025 am 12:19 AM

Photoshop can be used in web design to create high-fidelity prototypes, design UI elements, and simulate user interactions. 1. Use layers, masks and smart objects for basic design. 2. Simulate user interaction through animation and timeline functions. 3. Use scripts to automate the design process and improve efficiency.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor