Function File: imresize (im, scale)
Function File: imresize (im, [M N])
Function File: imresize (…, method)
Function File: imresize (…, …, property, value, …)

Resize image with interpolation

Scales the image im by a factor scale or into the size M rows by N columns. For example:

imresize (im, 1);    # return the same image as input
imresize (im, 1.5);  # return image 1.5 times larger
imresize (im, 0.5);  # return image with half the size
imresize (im, 2);    # return image with the double size
imresize (im, [512 610]); # return image of size 512x610

If M or N is NaN, it will be determined automatically so as to preserve aspect ratio.

The optional argument method defines the interpolation method to be used. The following methods are available, see below for custom methods.

"nearest", "box"

Nearest neighbor method. Only the nearest pixel is used. This gives hard edges.

"linear", "bilinear", "triangle"

Bilinear interpolation method using the four neighbor pixels.

"cubic", "bicubic" (default)

Bicubic interpolation method using the 16 neighbor pixels. At the borders symmetric padding is used. This is the default method.

By default, the cubic method is used.

For custom interpolation kernels, specify a two-element cell array for method: {kernel, size}. kernel must be an interpolation kernel function that can handle vector input. It must be zero outside -size/2 <= x <= size/2. The following example does a bilinear interpolation, just as using "bilinear":

im = magic(6);
lin = @(x) (1 - abs(x)) .* (abs(x) < 1);
size = 2;
imresize(im, 0.5, {lin, size});

Note that also for custom kernels anti-aliasing is applied by default.

Additionally the following optional property-value-pairs can be used:

"Antialiasing"

If this is set to true and the scale factor in horizontal or vertical direction is less than 1, anti-aliasing will used for that direction. This means the interpolation kernel is broadened by 1/scale to reduce the frequency components that cause aliasing effects. Hence more neighbors than described above are used, e. g. "bilinear" with a scale of 0.5 in both directions uses 16 neighbors. The default value is true, except for the method "nearest" / "box".

"Method"

The interpolation method as string or a custom interpolation kernel, see above.

"OutputSize"

Specify the output size M rows by N columns as vector [M N], see above.

"Scale"

Either a scalar to use the same scale factor for both direction or a vector [scale_rows scale_columns] to use different scaling factors.

Note: Currently there is no special support for categorical images or images with indexed colors.

See also: imremap, imrotate, interp2.

Package: image