GaussKern2D(width,h​eight,s)

Fast 2-dimensional Gaussian kernel generator
102 Downloads
Updated 15 Oct 2015

View License

Quickly generate 2-D Gaussian kernel given a covariance matrix and window size.
width = half-width of kernel window (integer)
height = half-height of kernel window (integer)
s = 2x2 covariance matrix
Yes, this supports anisotropic and rotated Gaussians (major axis does not have to be x- or y-axis).
This code is designed to be fast, therefore it is not built out with lots of features. I have expanded and vectorized all of the computations. It runs on the order of 0.1ms.

Cite As

Nils Persson (2025). GaussKern2D(width,height,s) (https://www.mathworks.com/matlabcentral/fileexchange/53536-gausskern2d-width-height-s), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2015a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Biomedical Imaging in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.12.0.0

Had this useless extra inverse calculation I forgot to delete.

1.11.0.0

added a pretty picture

1.1.0.0

Using analytical formula for 2x2 inverse now.

1.0.0.0

Added a description.