imscale
result = imscale(img, sx, [sy], [method=], [bbox="loose"], [fill=0])
Input: img, sx, sy, method, bbox, fill · Output: result
What it is
img is an Image; sx is a number, the scale factor (imscale(img, 2) doubles both dimensions); sy is an optional number, the vertical scale factor, defaulting to sx (uniform scale) when omitted. method/fill as in imtranslate. bbox is an optional named string, defaulting to "loose" so the output canvas grows/shrinks to fit the scaled content — the opposite default from imtranslate. Implemented as imwarp + affine_scale. Different from resize, which takes absolute output dimensions rather than a factor.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = imscale(img, sx, [sy], [method=], [bbox="loose"], [fill=0]) | img Imageimg is an Image.sx numbersx is a number, the scale factor (imscale(img, 2) doubles both dimensions).sy number, optionalsy is an optional number, the vertical scale factor, defaulting to sx (uniform scale) when omitted.method optionalmethod/fill as in imtranslate.bbox string, optional (default "loose")bbox is an optional named string, defaulting to "loose" so the output canvas grows/shrinks to fit the scaled content — the opposite default from imtranslate.fill optional (default 0)method/fill as in imtranslate. | 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)
20 30 [2, 0.4, 0; 0, 1.5, 0; 0, 0, 1]
from images
How it works
imscale(img, sx, [sy], [method=]) — pure scale via imwarp + affine_scale. Different from resize(img, width, height): resize takes absolute output dimensions, imscale takes a scale FACTOR (imscale(img, 2) doubles both dimensions; resize(img, 2*img.width, 2*img.height) is the resize-flavored way to say the same thing). Defaults to bbox="loose" (the output canvas grows/shrinks to fit the scaled content, matching resize/MATLAB imresize's own "output IS the new size" semantics) — the sensible default here, unlike imtranslate's "crop".
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.