GaussKern2D(width,height,s)
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
Platform Compatibility
Windows macOS LinuxCategories
Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.