Multivariate Gaussian kernel in any derivative order
NDGAUSS: create ND gaussian kernel in any derivative order.
g = ndgauss(hsize,sigma);
[g,xi,yi,..] = ndgauss(hsize,sigma);
Inputs:
- hsize is N-length of kernel size.
- sigma is N-length of standard deviations (gaussian widths).
Outputs:
- g is the kernel. The size of g is hsize(1) x hsize(2) x ... hsize(n).
- [xi,yi,..] is the grid to create the kernel.
Options:
1. 'der', <gaussian_derivatives>. Default is 0.
The option must be in N-length array. Each defines which derivative
order.
Example:
a. to create d^2G(x,y) / dxdy, then 'der' = [1 1].
b. to create d^2G(x,y) / dy^2, then 'der' = [0 2].
2. 'normalize', 1 | 0. Default is 0.
If this option is set to 1, the kernel will be divided by its sum that
makes the sum of kernel is 1.
Warning: gaussian derivative kernel may not be sum to 1, e.g.,
dG(x,y)/dxdy.
NOTE: a hermite function is needed. See the requirement below for the link to this function.
Examples:
1. To create 33x33 2D gaussian kernel with different sigma:
zi = ndgauss([33 33],[2*sqrt(2) 1.2]);
imagesc(zi); colormap(gray); axis image;
2. To create several 1D gaussian kernel in different derivative orders:
leg = cell(1,5);
for i=0:4
yi(:,i+1) = ndgauss(33,2*sqrt(2),'der',i);
leg{i+1} = sprintf('g%d(x)',i);
end
plot(yi);
legend(leg);
3. To create 15x15 Laplacian of Gaussian of width 2:
Lg = ndgauss([15 15],[2 2],'der',[2 0]) + ...
ndgauss([15 15],[2 2],'der',[0 2]);
figure; colormap(gray);
subplot(1,2,1); imagesc(Lg); axis image;
subplot(1,2,2); surf(Lg); axis vis3d;
Authors:
Avan Suinesiaputra - avan dot sp at gmail dot com.
Fadillah Z Tala - fadil dot tala at gmail dot com.
Cite As
Avan Suinesiaputra (2024). Multivariate Gaussian kernel in any derivative order (https://www.mathworks.com/matlabcentral/fileexchange/27763-multivariate-gaussian-kernel-in-any-derivative-order), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxTags
Acknowledgements
Inspired by: Hermite polynomials
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.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0.0 |