Generate an array with image windows as columns. More...

Functions

AFAPI array unwrap (const array &in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px=0, const dim_t py=0, const bool is_column=true)
 C++ Interface wrapper for unwrap. More...
 
AFAPI af_err af_unwrap (af_array *out, const af_array in, const dim_t wx, const dim_t wy, const dim_t sx, const dim_t sy, const dim_t px, const dim_t py, const bool is_column)
 C Interface wrapper for unwrap. More...
 

Detailed Description

Generate an array with image windows as columns.

unwrap takes in an input image along with the window sizes wx and wy, strides sx and sy, and padding px and py. This function then generates a matrix where each windows is an independent column.

The number of columns (rows if is_column is true) in the output array are govenered by the number of windows that can be fit along x and y directions. Padding is applied along all 4 sides of the matrix with px defining the height of the padding along dim 0 and py defining the width of the padding along dim 1.

The first column window is always at the top left corner of the input including padding. If a window cannot fit before the end of the matrix + padding, it is skipped from the generated matrix.

Padding can take a maximum value of window - 1 repectively for x and y.

For multiple channels (3rd and 4th dimension), the generated matrix contains the same number of channels as the input matrix. Each channel of the output matrix corresponds to the same channel of the input.

So the dimensions of the output matrix are:

[(wx * wy), // Column height
(No. of windows along dim 0 of input * No. of windows along dim 1 of input), // No. of columns per channel
input.dims()[2], // Channels
input.dims()[3]] // Volumns

When strides are 1, the operation is sliding window. When strides are equal to the respective window sizes, the option is distinct window. Other stride values are also allowed.

A [5 5 1 1]
10 15 20 25 30
11 16 21 26 31
12 17 22 27 32
13 18 23 28 33
14 19 24 29 34
// Window 3x3, strides 1x1, padding 0x0
unwrap(A, 3, 3, 1, 1, 0, 0) [9 9 1 1]
10 11 12 15 16 17 20 21 22
11 12 13 16 17 18 21 22 23
12 13 14 17 18 19 22 23 24
15 16 17 20 21 22 25 26 27
16 17 18 21 22 23 26 27 28
17 18 19 22 23 24 27 28 29
20 21 22 25 26 27 30 31 32
21 22 23 26 27 28 31 32 33
22 23 24 27 28 29 32 33 34
// Window 3x3, strides 1x1, padding 1x1
unwrap(A, 3, 3, 1, 1, 1, 1) [9 25 1 1]
0 0 0 0 0 0 10 11 12 13 0 15 16 17 18 0 20 21 22 23 0 25 26 27 28
0 0 0 0 0 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
0 0 0 0 0 11 12 13 14 0 16 17 18 19 0 21 22 23 24 0 26 27 28 29 0
0 10 11 12 13 0 15 16 17 18 0 20 21 22 23 0 25 26 27 28 0 30 31 32 33
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
11 12 13 14 0 16 17 18 19 0 21 22 23 24 0 26 27 28 29 0 31 32 33 34 0
0 15 16 17 18 0 20 21 22 23 0 25 26 27 28 0 30 31 32 33 0 0 0 0 0
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 0 0 0 0 0
16 17 18 19 0 21 22 23 24 0 26 27 28 29 0 31 32 33 34 0 0 0 0 0 0
// Window 3x3, strides 3x3 ("distinct"), padding 0x0
unwrap(A, 3, 3, 3, 3, 0, 0) [9 1 1 1]
10
11
12
15
16
17
20
21
22
// Window 3x3, strides 3x3 ("distinct"), padding 2x2
unwrap(A, 3, 3, 3, 3, 2, 2) [9 9 1 1]
0 0 0 0 16 19 0 31 34
0 0 0 0 17 0 0 32 0
0 0 0 15 18 0 30 33 0
0 0 0 0 21 24 0 0 0
0 0 0 0 22 0 0 0 0
0 0 0 20 23 0 0 0 0
0 11 14 0 26 29 0 0 0
0 12 0 0 27 0 0 0 0
10 13 0 25 28 0 0 0 0

Function Documentation

AFAPI af_err af_unwrap ( af_array out,
const af_array  in,
const dim_t  wx,
const dim_t  wy,
const dim_t  sx,
const dim_t  sy,
const dim_t  px,
const dim_t  py,
const bool  is_column 
)

C Interface wrapper for unwrap.

Parameters
[out]outis an array with image blocks as rows or columns.
[in]inis the input image (or set of images)
[in]wxis the block window size along 0th-dimension between [1, input.dims[0] + px]
[in]wyis the block window size along 1st-dimension between [1, input.dims[1] + py]
[in]sxis the stride along 0th-dimension
[in]syis the stride along 1st-dimension
[in]pxis the padding along 0th-dimension between [0, wx). Padding is applied both before and after.
[in]pyis the padding along 1st-dimension between [0, wy). Padding is applied both before and after.
[in]is_columnspecifies the layout for the unwrapped patch. If is_column is false, the unrapped patch is laid out as a row.
Returns
AF_SUCCESS if the color transformation is successful, otherwise an appropriate error code is returned.
AFAPI array af::unwrap ( const array in,
const dim_t  wx,
const dim_t  wy,
const dim_t  sx,
const dim_t  sy,
const dim_t  px = 0,
const dim_t  py = 0,
const bool  is_column = true 
)

C++ Interface wrapper for unwrap.

Parameters
[in]inis the input image (or set of images)
[in]wxis the block window size along 0th-dimension between [1, input.dims[0] + px]
[in]wyis the block window size along 1st-dimension between [1, input.dims[1] + py]
[in]sxis the stride along 0th-dimension
[in]syis the stride along 1st-dimension
[in]pxis the padding along 0th-dimension between [0, wx). Padding is applied both before and after.
[in]pyis the padding along 1st-dimension between [0, wy). Padding is applied both before and after.
[in]is_columnspecifies the layout for the unwrapped patch. If is_column is false, the unrapped patch is laid out as a row.
Returns
an array with the image blocks as rows or columns