Qu

imwarp

Builtin index · Images

result = imwarp(img, M, [method="bilinear"], [bbox="loose"], [fill=0])

Input: img, M, method, bbox, fill · Output: result

What it is

img is an Image; M is a 3x3 (or 2x3, auto-padded with [0,0,1]) affine Mat — from the affine_* builders above, a literal matrix, or any composition of the two via */matmul. method is an optional named string ("nearest"/"bilinear", default "bilinear"). bbox is an optional named string, "loose" (default, grows the canvas to fit) or "crop" (keeps the input's size). fill is an optional named number 0–255 (default 0) applied to all 3 channels for pixels that map outside the source image. Applies M to img in one resampling pass via inverse mapping.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = imwarp(img, M, [method="bilinear"], [bbox="loose"], [fill=0])
img Imageimg is an Image.
M Mat or matrixM is a 3x3 (or 2x3, auto-padded with [0,0,1]) affine Mat — from the affine_* builders above, a literal matrix, or any composition of the two via */matmul.
method string, optional (default "bilinear")method is an optional named string ("nearest"/"bilinear", default "bilinear").
bbox string, optional (default "loose")bbox is an optional named string, "loose" (default, grows the canvas to fit) or "crop" (keeps the input's size).
fill number, optional (default 0)fill is an optional named number 0–255 (default 0) applied to all 3 channels for pixels that map outside the source image.
result Image
Returns a new Image.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

img = load_image("sample.bmp")

# Rotate 30 degrees about the origin, then shift right/down by (50, 20).

M = affine_translate(50, 20) * affine_rotate(30)
out = imwarp(img, M, method="bilinear", bbox="loose", fill=255)
imshow(out)

from images

How it works

imwarp(img, M, [method="bilinear"], [bbox="loose"|"crop"], [fill=0]) — applies an arbitrary 3x3 (or 2x3, padded with a [0,0,1] bottom row) affine Value::Mat to img in ONE resampling pass via inverse mapping (Image::warp's doc including why forward mapping is deliberately not used and where the rayon parallelization lives). M may come from the builders above, direct literal construction, OR any composition of the two via Qu's own */matmul — this builtin doesn't care how M was built, only that it's a 3x3/2x3 real matrix.

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.