The C++ interface for resize. More...

array resize (const float scale, const array &image, const char method='L')
 Resize an image based on a scaling factor (uniform) More...
 
array resize (const float scale_x, const float scale_y, const array &image, const char method='L')
 Resize an image based on two scale factors (non-uniform) More...
 
array resize (const unsigned height, const unsigned width, const array &image, const char method='L')
 Resize an image to a specified width and height in pixels. More...
 

Detailed Description

The C++ interface for resize.

The resize function scales an image up or down based on a constant scaling factor or an explicit new size. resize provides two methods for this operation, nearest neighbor interpolation and bilinear interpolation.

The following examples illustrate the difference between the two types of interpolation:

float h_in[] = {1, 2, 3, 4};
array in(2, 2, h_in);
// in = 1 3
// 2 4
array out = resize(2.0f, in, 'N');
// out = 1 1 3 3
// 1 1 3 3
// 2 2 4 4
// 2 2 4 4
array bi_out = resize(2.0f, in, 'L');
// out = 1.00 1.50 2.50 3.00
// 1.25 1.75 2.75 3.25
// 1.75 2.25 3.25 3.75
// 2.00 2.50 3.50 4.00

Function Documentation

array af::resize ( const float  scale,
const array &  image,
const char  method = 'L' 
)

Resize an image based on a scaling factor (uniform)

// resize an image to half size along each dimension
// (downsize to 1/4 of area)
// retains original aspect ratio
array img_out = resize(0.5f, img_in);
Parameters
[in]scaleuniform scale factor (e.g. "1.1" scales image up 10%, 0.6 scales image down to 60%). Height and width scaled uniformly.
[in]imagethe image to resize
[in]methodinterpolation type ('N' Nearest | 'L' bilinear)
Returns
resized image
array af::resize ( const float  scale_x,
const float  scale_y,
const array &  image,
const char  method = 'L' 
)

Resize an image based on two scale factors (non-uniform)

// Resize an image using two scaling factors
// (does not retain original aspect ratio)
array img_out = resize(0.33, 0.66, img_in);
Parameters
[in]scale_xscale factor for first dimension (>= 0)
[in]scale_yscale factor for second dimension (>= 0)
[in]imagethe image to resize
[in]methodinterpolation type ('N' Nearest Neighbor | 'L' linear)
Returns
resized image
array af::resize ( const unsigned  height,
const unsigned  width,
const array &  image,
const char  method = 'L' 
)

Resize an image to a specified width and height in pixels.

// Resize an image to a specific size, ignoring original aspect ratio
array img_out = resize(480, 640, img_in);
Parameters
[in]heightoutput height in pixels
[in]widthoutput width in pixels
[in]imagethe image to resize
[in]methodinterpolation type ('N' Nearest | 'L' bilinear)
Returns
resized image