Qu

imtranslate

Builtin index · Images

result = imtranslate(img, dx, dy, [method=], [bbox="crop"], [fill=0])

Input: img, dx, dy, method, bbox, fill · Output: result

What it is

img is an Image; dx/dy are numbers, the horizontal/vertical pixel shift (positive = right/down). method is an optional named string ("nearest"/"bilinear") controlling resampling. bbox is an optional named string, defaulting to "crop" (output stays the same size as the input, matching MATLAB imtranslate's 'OutputView','same') — the opposite default from imwarp/imscale. fill is an optional named number 0–255 (default 0), the byte value used on all 3 channels for pixels that map outside the source. Implemented as imwarp + affine_translate.

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = imtranslate(img, dx, dy, [method=], [bbox="crop"], [fill=0])
img Imageimg is an Image.
dx numberdx/dy are numbers, the horizontal/vertical pixel shift (positive = right/down).
dy numberdx/dy are numbers, the horizontal/vertical pixel shift (positive = right/down).
method string, optionalmethod is an optional named string ("nearest"/"bilinear") controlling resampling.
bbox string, optional (default "crop")bbox is an optional named string, defaulting to "crop" (output stays the same size as the input, matching MATLAB imtranslate's 'OutputView','same') — the opposite default from imwarp/imscale.
fill number, optional (default 0)fill is an optional named number 0–255 (default 0), the byte value used on all 3 channels for pixels that map outside the source.
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 = image_new(20, 20, r=0, g=0, b=0)

shifted = imtranslate(img, 5, 3, fill=255)
scaled = imscale(img, 1.5, fill=0)
imshow(shifted)

M = affine_scale(2, 1.5) * affine_shear(0.2, 0) * affine_identity()
print(shifted.width, scaled.width, M)
output
20 30 [2, 0.4, 0; 0, 1.5, 0; 0, 0, 1]
a synthetic field with one bright patch

from images

How it works

imtranslate(img, dx, dy, [fill=0]) — pure translation via imwarp + affine_translate. Defaults to bbox="crop" (the output stays the input's own size, matching MATLAB imtranslate's default 'OutputView','same') rather than imwarp's own "loose" default — a translation's "natural" canvas is the same one it started with, unlike a rotation or scale, which genuinely change the content's footprint.

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