Main Content

Rearrange image blocks into columns

rearranges discrete image blocks of size
`B`

= im2col(`A`

,`[m n]`

,'distinct')`m`

-by-`n`

into columns, and returns the
concatenated columns in matrix `B`

. The `im2col`

function pads image `A`

, if necessary. For more information about
the padding value, see Tips.

The order of the columns in matrix `B`

is determined by
traversing the image `A`

in a column-wise manner. For example, if
`A`

consists of distinct blocks `Aij`

arranged as `A = [A11 A12; A21 A22]`

, then ```
B = [A11(:)
A21(:) A12(:) A22(:)]
```

.

For distinct block processing,

`im2col`

zero-pads`A`

, if necessary, so its size is an integer multiple of`m`

-by-`n`

. The padding value is`0`

when`A`

is data type`uint8`

,`uint16`

, or`logical`

. For other data types, the value of padding depends on whether`A`

is interpreted as an indexed image.The padding value is

`1`

when`A`

is interpreted as an indexed image.The padding value is

`0`

when`A`

is not interpreted as an indexed image.

`im2col`

orders the columns of`B`

so that they can be reshaped to form a matrix according to`reshape`

.For example, suppose you use a function, such as

`sum(B)`

, that returns a scalar for each column of`B`

. You can directly store the result in a matrix of size (`mm-m+1`

)-by-(`nn-n+1`

), using these calls.`B = im2col(A,[m n],'sliding'); C = reshape(sum(B),mm-m+1,nn-n+1);`