Gaussian splats (2D) Open ↗
Code
% Three anisotropic Gaussians, the building block of Gaussian splatting.
[X, Y] = meshgrid(linspace(-3, 3, 160));
G = zeros(size(X));
mu = [-1.2 0.4; 0.8 -0.6; 1.3 1.1];
theta = [0.5 -0.9 1.6];
s = [0.9 0.3; 0.7 0.25; 0.5 0.4]; % standard deviations along/across
w = [1 0.8 0.6];
for k = 1:3
c = cos(theta(k)); sn = sin(theta(k));
dx = X - mu(k, 1); dy = Y - mu(k, 2);
u = ( c*dx + sn*dy) / s(k, 1);
v = (-sn*dx + c*dy) / s(k, 2);
G = G + w(k) * exp(-0.5 * (u.^2 + v.^2));
end
contourf(X, Y, G, 14)
colormap magma
axis equal
title('Σ wₖ · exp(−½ (x−μₖ)ᵀ Σₖ⁻¹ (x−μₖ))')
xlabel('x'), ylabel('y')