Skip to content

Gaussian Filter Calculator: Kernel Generator and Online Image Blur Tool

Generate a normalized Gaussian kernel for any sigma, see exactly how its weights are computed, and apply it to a test image or your own photo. Add noise, measure the improvement in PSNR, find the best sigma, and compare the filter's frequency response with a box filter. Every calculation runs in your browser.

1-D & 2-D kernelsBlur your own imageOptimal-σ searchMatches SciPy
By Bimal Ghimire · Updated November 4, 2026

Key facts

  • 2-D Gaussian kernel: G(x, y) = exp(−(x² + y²)/(2σ²)) / (2πσ²); the discrete kernel samples it at integer offsets and divides by the sum so the weights add up to 1.
  • Kernel size: 2r + 1 with radius r ≈ 3σ to 4σ. SciPy's default is r = round(4σ); MATLAB's imgaussfilt uses 2⌈2σ⌉ + 1.
  • Separable: a 2-D Gaussian blur equals a row blur followed by a column blur, so it costs 2n instead of n² operations per pixel.
  • Width: FWHM = 2√(2 ln 2) σ ≈ 2.355σ; repeated blurs add in quadrature: σ = √(σ₁² + σ₂²).
  • Frequency response: H(f) = exp(−2π²σ²f²), a Gaussian with no ripples; −3 dB at f ≈ 0.1325/σ cycles per pixel.
  • Noise: white-noise standard deviation falls by about 0.282/σ (for σ ≥ 1 pixel).

Gaussian Filter Tool

Images never leave your device
Standard deviation of the kernel. Larger σ = stronger smoothing.
 
How pixels beyond the image edge are filled.
Presets:
2-D kernel heat map
2-D kernel weights
Noise is seeded, so results repeat exactly.
RGB filters each channel separately.
Swipe compares on top of each other.
Input
Gaussian filtered

Filters the noisy image with σ from 0.3 to 6 pixels and measures the peak signal-to-noise ratio against the clean image (greyscale). Too little smoothing leaves noise; too much destroys detail, so PSNR has a maximum. The best σ depends on the noise level and on how much fine detail the image has.

Uses the image and noise level from the "Filter an image" tab.

f is spatial frequency in cycles per pixel (0.5 = Nyquist, the finest pattern a pixel grid can hold: one pixel on, one pixel off). The box filter has the same variance as the Gaussian; its negative lobes flip the contrast of some fine patterns, which the Gaussian never does.

How to Use the Gaussian Filter Calculator

  1. Set σ. Type a value or drag the slider. σ is in pixels. If your scale is in metres (for example a 10 m satellite image and a 40 m smoothing scale), divide by the pixel size: σ = 40 / 10 = 4 pixels.
  2. Pick a size rule. The 3σ rule is a good default. Choose the SciPy or MATLAB rule to reproduce those libraries exactly, or a fixed size to see what truncation does.
  3. Read the kernel. The Kernel tab shows the 1-D weights, the 2-D matrix, an integer version and ready-to-paste NumPy code.
  4. Filter an image. Choose a test image or upload your own (it is resized to at most 512 pixels and processed locally). Add noise to see denoising, swipe to compare, and move the row slider to see the intensity profile.
  5. Optimize. The σ search finds the sigma with the highest PSNR for the current image and noise level.
  6. Understand it. The frequency tab shows which detail sizes survive; the step-by-step tab reproduces every number.

Gaussian Filter Formulas

1-D and 2-D Gaussian
$$G_\sigma(x)=\frac{1}{\sqrt{2\pi}\,\sigma}\,e^{-x^2/(2\sigma^2)},\qquad G_\sigma(x,y)=\frac{1}{2\pi\sigma^2}\,e^{-(x^2+y^2)/(2\sigma^2)}=G_\sigma(x)\,G_\sigma(y)$$
σ is the standard deviation in pixels. The 2-D function is the product of two 1-D functions, which is what makes the filter separable.
Discrete, normalized kernel of radius r
$$w_i=\frac{e^{-i^2/(2\sigma^2)}}{\sum_{j=-r}^{r}e^{-j^2/(2\sigma^2)}},\qquad i=-r,\dots,r,\qquad \sum_i w_i=1$$
The constant 1/(√(2π)σ) cancels in the normalization, so only the exponentials matter. The 2-D kernel is the outer product wij = wiwj.
Filtering (convolution)
$$g(x,y)=\sum_{i=-r}^{r}\sum_{j=-r}^{r}w_{i}\,w_{j}\,f(x+j,\;y+i)=\sum_{i}w_i\Big[\sum_j w_j\,f(x+j,\,y+i)\Big]$$
Because the kernel is symmetric, correlation and convolution give the same result. The bracket is the row pass; the outer sum is the column pass.
Width, frequency response and cascading
$$\text{FWHM}=2\sqrt{2\ln 2}\,\sigma\approx2.355\,\sigma,\qquad H(f)=e^{-2\pi^2\sigma^2 f^2},\qquad G_{\sigma_1}*G_{\sigma_2}=G_{\sqrt{\sigma_1^2+\sigma_2^2}}$$
H(f) is the Fourier transform of the normalized kernel (f in cycles per pixel). Its −3 dB point is fc = √(ln 2)/(2πσ) ≈ 0.1325/σ.
Noise reduction for white noise
$$\sigma_{\text{out}}=\sigma_{\text{in}}\sqrt{\textstyle\sum_{i,j}w_{ij}^2}=\sigma_{\text{in}}\sum_i w_i^2\;\approx\;\frac{\sigma_{\text{in}}}{2\sqrt{\pi}\,\sigma}\qquad(\sigma\gtrsim1)$$
For a separable kernel Σwij² = (Σwi²)². The approximation uses ∫G²dx = 1/(2√π σ).

Choosing Sigma and Kernel Size

Choose σ from the physical size of what you want to keep or remove; the kernel size then follows from σ. The table gives starting values; use the σ search tab to tune them on your own data.

TaskTypical σ (pixels)Why
Light denoising of photos or sensor images0.8 – 1.5Removes pixel-level noise; detail larger than ~6–10 px survives.
Pre-smoothing before gradients, Canny or the Laplacian1 – 2Derivatives amplify noise; a small blur makes them stable.
Anti-aliasing before downsampling by a factor d≈ (d − 1)/2Default in scikit-image resize; removes detail the coarser grid cannot hold.
Matching a sharper sensor to a blurrier one√(σtarget² − σsource²)Gaussian blurs add in quadrature (assuming Gaussian point spread functions).
Background or trend removal (high-pass = image − blur)5 – 50Large σ keeps only slow variations such as illumination.
Scale-space and feature detection (SIFT, blobs)σ₀·kn, k = 21/sA geometric ladder of scales.
Radius1-D weight kept2-D (square) weight keptUsed by
r = 2σ95.45%91.11%MATLAB imgaussfilt (size 2⌈2σ⌉+1)
r = 3σ99.73%99.46%Common rule of thumb; OpenCV for 8-bit images
r = 4σ99.994%99.987%SciPy (truncate = 4.0); OpenCV for float images

Percentages are the share of the continuous Gaussian inside ±r (erf(r/(σ√2)) in 1-D, its square for the square 2-D window). After normalization the truncated kernel still sums to exactly 1; what is lost is a little of the bell's tail, which slightly lowers the effective σ.

Boundary Modes in SciPy, OpenCV and MATLAB

Near the border the kernel extends past the image, so the missing pixels must be invented. The choice only affects a band about r pixels wide, but it matters for small images, tiles of a large raster, and quantitative work.

This toolPadding (edge row a b c d)SciPy modeOpenCV borderTypeMATLAB
Reflectd c b a | a b c d'reflect' (default)BORDER_REFLECT'symmetric'
Mirrord c b | a b c d'mirror'BORDER_REFLECT_101 (default)–
Nearesta a a | a b c d'nearest'BORDER_REPLICATE'replicate' (imgaussfilt default)
Wrapb c d | a b c d'wrap'not accepted by GaussianBlur; pad with copyMakeBorder(BORDER_WRAP)'circular'
Constant 00 0 0 | a b c d'constant'BORDER_CONSTANT0 (numeric)
Constant zero darkens the edges: part of the kernel averages in black pixels. Use it only when the outside really is zero, for example a masked region or a padded FFT.

Worked Examples

Example 1: The 5-tap kernel for σ = 1

With r = 2, the unnormalized weights are e−i²/2: e0 = 1, e−0.5 = 0.606531 and e−2 = 0.135335. Their sum is 1 + 2(0.606531) + 2(0.135335) = 2.483732. Dividing gives

$$w=[\,0.054489,\;0.244201,\;0.402620,\;0.244201,\;0.054489\,]$$
The 2-D centre weight is 0.402620² = 0.162103. Set σ = 1 and "Fixed size 5" in the tool to see the same numbers. The familiar integer kernel [1 4 6 4 1]/16 is the binomial approximation of a Gaussian with the same variance (σ = 1).

Example 2: Smoothing a spike

Filter the 1-D signal [10, 10, 10, 80, 10, 10, 10] with the kernel above. The output at the spike is 10 + 70 × 0.402620 = 38.18, and its neighbours become 10 + 70 × 0.244201 = 27.09 and 10 + 70 × 0.054489 = 13.81. The total excess (70) is conserved, but it is spread over five samples: [10, 13.81, 27.09, 38.18, 27.09, 13.81, 10]. This is why blurring reduces impulse noise but cannot remove it completely; a median filter would.

Example 3: A 3 × 3 kernel on an edge

The 3 × 3 binomial kernel [1 2 1; 2 4 2; 1 2 1]/16 (a Gaussian with σ ≈ 0.71) applied to columns of values 20, 20, 20, 80, 80 gives 20, 20, 35, 65, 80 across the row: the sharp step from 20 to 80 becomes a ramp three pixels wide. Wider σ gives a wider ramp, which is the visible "softening" of edges.

Example 4: How much noise does σ = 2 remove?

For σ = 2 with r = 8, Σwi² = 0.14105, almost equal to the approximation 1/(2√π × 2) = 0.14105. White noise with a standard deviation of 20 grey levels is therefore reduced to 20 × 0.141 = 2.8 grey levels, a factor of 7.1 or 17 dB. Detail with a period shorter than 7.55σ ≈ 15 pixels is attenuated by more than 3 dB, so the gain in PSNR is always smaller than 17 dB on a real image.

Example 5: Matching two satellite sensors

Suppose a 10 m image has a point spread function (PSF) with σ = 0.5 pixels and you want it to look like a coarser sensor whose PSF, expressed on the same 10 m grid, has σ = 1.5 pixels. Assuming both are Gaussian, the extra blur is σ = √(1.5² − 0.5²) = 1.41 pixels. Apply it, then resample to the coarser grid. Real sensor PSFs are only approximately Gaussian, so use the published modulation transfer function when accuracy matters.

Gaussian Filter in Python, OpenCV and MATLAB

All three lines below blur an image with σ = 2. They differ in kernel size and boundary handling, which is why their outputs differ slightly near the edges.

# SciPy: radius = round(truncate * sigma), default truncate=4.0, mode='reflect'
from scipy import ndimage
smooth = ndimage.gaussian_filter(img.astype(float), sigma=2, mode='reflect', truncate=4.0)
# colour image: do not blur across channels
smooth_rgb = ndimage.gaussian_filter(rgb.astype(float), sigma=(2, 2, 0))

# OpenCV: ksize=(0, 0) lets OpenCV choose the size from sigma; default border = REFLECT_101
import cv2
smooth = cv2.GaussianBlur(img, ksize=(0, 0), sigmaX=2, borderType=cv2.BORDER_REFLECT_101)

# scikit-image
from skimage.filters import gaussian
smooth = gaussian(img, sigma=2, preserve_range=True)
% MATLAB: default FilterSize = 2*ceil(2*sigma)+1, default Padding = 'replicate'
J = imgaussfilt(I, 2);
J = imgaussfilt(I, 2, 'FilterSize', 2*ceil(3*2)+1, 'Padding', 'symmetric');

To build the kernel yourself:

import numpy as np
def gaussian_kernel(sigma, truncate=3.0):
    r = int(truncate * sigma + 0.5)
    x = np.arange(-r, r + 1)
    w = np.exp(-x**2 / (2 * sigma**2))
    w /= w.sum()                 # normalize: weights sum to 1
    return w, np.outer(w, w)     # 1-D and 2-D kernels
Check: this tool's filter was tested against scipy.ndimage.gaussian_filter for σ from 0.5 to 6, all five boundary modes and truncate 3 and 4; the largest difference was below 10⁻⁴ grey levels (single-precision rounding).

Assumptions and Limitations

  • It blurs edges as much as noise. A Gaussian filter is linear and the same everywhere. If edges must stay sharp, use a bilateral filter, anisotropic diffusion, non-local means or a median filter.
  • Wrong noise model. The Gaussian is a good choice for additive, roughly Gaussian noise. Salt-and-pepper noise needs a median filter; the multiplicative speckle of radar (SAR) images needs speckle filters such as Lee, Frost or Gamma-MAP.
  • Very small σ. Below about 0.8 pixels a sampled Gaussian is a poor approximation (most of the weight is on the centre pixel and its effective σ differs from the nominal one). Lindeberg's discrete Gaussian kernel, based on modified Bessel functions, is the exact discrete alternative.
  • Large σ. Direct convolution costs O(σ) per pixel per pass. For very large σ use FFT convolution or recursive (IIR) approximations such as Young–van Vliet or Deriche.
  • Colour and gamma. Most images are stored in gamma-encoded sRGB. A physically correct blur (one that mimics optical defocus) should be done in linear light; blurring sRGB values directly, as most software does, makes bright-dark boundaries look slightly darker.
  • In this tool uploaded images are resized to a maximum of 512 pixels on the long side and processed as 8-bit sRGB in your browser; σ is limited to 20 pixels on the slider and 40 in the box.

Related Tools and Guides

Frequently Asked Questions

What is a Gaussian filter?

A Gaussian filter is a linear smoothing filter whose weights follow the Gaussian (normal) function G(x, y) = exp(−(x² + y²)/(2σ²))/(2πσ²). Each output pixel is a weighted average of its neighbours, with weights that fall off smoothly with distance. It reduces noise and fine detail while, unlike a box filter, adding no ringing or new structure.

How do I choose the kernel size for a given sigma?

Choose the radius from sigma, not the other way round. A radius of 3σ keeps 99.7% of the 1-D Gaussian weight; SciPy uses radius = round(4σ) by default (truncate = 4.0), MATLAB imgaussfilt uses a size of 2⌈2σ⌉ + 1, and OpenCV picks about ±3σ for 8-bit images and ±4σ for floating-point images when ksize is (0, 0). The kernel size is then 2r + 1.

Why must a Gaussian kernel sum to 1?

A kernel whose weights sum to 1 leaves a uniform region unchanged, so the mean brightness of the image is preserved. Sampling the Gaussian at integer points and truncating it never gives exactly 1, so the sampled weights are divided by their sum. Without normalization the filtered image becomes darker or brighter.

What does sigma mean in pixels and in frequency?

Sigma is the standard deviation of the kernel in pixels. The full width at half maximum is 2√(2 ln 2) σ ≈ 2.355σ. In frequency the Gaussian stays Gaussian: H(f) = exp(−2π²σ²f²), with a −3 dB cutoff at f ≈ 0.1325/σ cycles per pixel, so detail with a period shorter than about 7.5σ pixels is strongly attenuated.

Why is the Gaussian filter separable and why does it matter?

exp(−(x² + y²)/2σ²) = exp(−x²/2σ²) · exp(−y²/2σ²), so a 2-D Gaussian blur equals a 1-D blur along the rows followed by a 1-D blur along the columns. For a kernel of size n this costs 2n multiplications per pixel instead of n², for example 50 instead of 625 for a 25 × 25 kernel.

Gaussian filter vs mean filter vs median filter: which should I use?

Use a Gaussian filter for Gaussian-like sensor noise and as a pre-smoothing step before derivatives, because it is smooth in both space and frequency. A mean (box) filter is faster but has ripples in its frequency response. A median filter is nonlinear and is better for salt-and-pepper (impulse) noise because it preserves edges.

How much does a Gaussian filter reduce noise?

For independent (white) noise the output variance is the input variance times the sum of squared weights. For a 2-D Gaussian with σ of 1 pixel or more, the noise standard deviation is reduced by a factor of about 1/(2√π σ) ≈ 0.282/σ: σ = 2 reduces noise to about 14% of its original level.

References

Gonzalez, R. C., & Woods, R. E. (2018). Digital Image Processing (4th ed.), Chapter 3: Intensity Transformations and Spatial Filtering, and Chapter 4: Filtering in the Frequency Domain. Pearson.

Lindeberg, T. (1990). Scale-space for discrete signals. IEEE Transactions on Pattern Analysis and Machine Intelligence, 12(3), 234–254.

Getreuer, P. (2013). A survey of Gaussian convolution algorithms. Image Processing On Line, 3, 286–310. doi.org/10.5201/ipol.2013.87

Young, I. T., & van Vliet, L. J. (1995). Recursive implementation of the Gaussian filter. Signal Processing, 44(2), 139–151.

Schowengerdt, R. A. (2007). Remote Sensing: Models and Methods for Image Processing (3rd ed.), Chapters 3 and 6 (sensor PSF and spatial filtering). Academic Press.

SciPy documentation: scipy.ndimage.gaussian_filter. OpenCV documentation: Image Filtering (GaussianBlur, getGaussianKernel).

Cite this tool: Ghimire, B. (2026). Gaussian Filter Calculator: Kernel Generator & Image Blur Tool. Engineers Views. https://engineersviews.com/tools/gaussian-filter-calculator/