Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-383

Splat Alpha Blending

Problem

Evaluate and composite a 2D Gaussian splat.

Given inverse covariance inv_cov = [[a, b], [b, c]] and pixel offset (dx, dy), the splat alpha is min(0.99, opacity * exp(-0.5 * (a * dx^2 + 2 * b * dx * dy + c * dy^2))). Blend over the background as alpha * color + (1 - alpha) * bg and return the result rounded to 4 decimal places.

Hint

The offset quadratic in the exponent is the Mahalanobis distance squared.

Test cases

case 1
in: [1,[[1,0],[0,1]],0,0,1,0]
expected: 0.99
case 2
in: [0.5,[[1,0],[0,1]],0,0,1,1]
expected: 1
case 3
in: [0.8,[[1,0],[0,1]],1,0,1,0]
expected: 0.4852
case 4
in: [1,[[1,0.5],[0.5,1]],1,1,1,0]
expected: 0.2231
Starter codePython
def splat_blend(opacity, inv_cov, dx, dy, color, bg):
    # Your code here
    pass

4 test cases · run your code against them in the editor