Resize a two-dimensional grid with corner-aligned bilinear interpolation. Map each output coordinate to the source grid:
y=iHnew−1H−1 x=jWnew−1W−1Use source coordinate zero when the corresponding output dimension is one. Let y0=⌊y⌋, x0=⌊x⌋, dy=y−y0, and dx=x−x0. Clamp y1=y0+1 and x1=x0+1 to the source boundary. Then compute:
V0=Iy0,x0(1−dx)+Iy0,x1dx V1=Iy1,x0(1−dx)+Iy1,x1dx Oi,j=V0(1−dy)+V1dyReturn the resized two-dimensional list.
Input: image = [[0, 10], [20, 30]], new_h = 3, new_w = 3
Output: [[0, 5, 10], [10, 15, 20], [20, 25, 30]]
Explanation: Corners remain fixed and every middle value is the linear blend of neighboring pixels.
Input: image = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], new_h = 2, new_w = 2
Output: [[0, 3], [12, 15]]
Compute source coordinates before taking their floor and fractional parts.
Interpolate horizontally twice, then interpolate those two values vertically.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number
Resize a two-dimensional grid with corner-aligned bilinear interpolation. Map each output coordinate to the source grid:
y=iHnew−1H−1 x=jWnew−1W−1Use source coordinate zero when the corresponding output dimension is one. Let y0=⌊y⌋, x0=⌊x⌋, dy=y−y0, and dx=x−x0. Clamp y1=y0+1 and x1=x0+1 to the source boundary. Then compute:
V0=Iy0,x0(1−dx)+Iy0,x1dx V1=Iy1,x0(1−dx)+Iy1,x1dx Oi,j=V0(1−dy)+V1dyReturn the resized two-dimensional list.
Input: image = [[0, 10], [20, 30]], new_h = 3, new_w = 3
Output: [[0, 5, 10], [10, 15, 20], [20, 25, 30]]
Explanation: Corners remain fixed and every middle value is the linear blend of neighboring pixels.
Input: image = [[0, 1, 2, 3], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], new_h = 2, new_w = 2
Output: [[0, 3], [12, 15]]
Compute source coordinates before taking their floor and fractional parts.
Interpolate horizontally twice, then interpolate those two values vertically.
Sign in to take notes on this problem
Accepts: array
Accepts: number
Accepts: number