Skip to content
DeepForgeby svx
All problems
HardComputer Visioncv-033

Bilinear Interpolation

Problem

Bilinearly interpolate a pixel value at fractional coordinates (y, x).

Clamp y and x to the valid ranges [0, H - 1] and [0, W - 1], then blend the four surrounding pixels using the fractional offsets. Round the result to 4 decimal places.

Hint

Blend with (1 - dy), (1 - dx) weights and clamp coordinates at the borders.

Test cases

case 1
in: [[[1,2],[3,4]],0.5,0.5]
expected: 2.5
case 2
in: [[[1,2],[3,4]],0,0]
expected: 1
case 3
in: [[[1,2],[3,4]],0.25,0.75]
expected: 2.25
case 4
in: [[[1,2],[3,4]],1.5,-0.5]
expected: 3
case 5
in: [[[1,2,3],[4,5,6],[7,8,9]],1.5,0.5]
expected: 6
Starter codePython
def bilinear_interpolate(image, y, x):
    # Your code here
    pass

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