To resize an image you must decide what value each output pixel should have, but the output pixel generally maps to a fractional location in the input. Bilinear interpolation estimates the value there from the four surrounding input pixels, weighting each by how close it is: first interpolate horizontally along the two rows, then vertically between those results. A subtle detail decides whether your resize matches the libraries: the convention for where a pixel's coordinate sits. Treating a pixel as a unit square whose center is at index + 0.5 gives the mapping src = (dst + 0.5) * (in_size / out_size) - 0.5, which keeps the image centered when scaling.
Implement bilinear_resize.
img has shape (H, W). bilinear_resize(img, out_h, out_w) returns shape (out_h, out_w).(i, j) the source coordinates are y = (i + 0.5) * H / out_h - 0.5 and x = (j + 0.5) * W / out_w - 0.5, clipped to [0, H - 1] and [0, W - 1].y0 = floor(y), y1 = min(y0 + 1, H - 1) and wy = y - y0 (same for x), the value is the bilinear blend of the four neighbours with those weights.Compute the coordinate arrays once for rows and columns, then use np.ix_-style broadcasting (y0[:, None], x0[None, :]) to gather the four neighbours.
Clipping before taking the floor makes the edges replicate rather than extrapolate.
No results yet
Run your code to check it against the examples, or submit to run every test.