Rearrange image blocks into columns

`B = im2col(A,[m n],block_type)`

B = im2col(A,'indexed',...)

`B = im2col(A,[m n],block_type)`

rearranges
image blocks into columns. `block_type`

is a character
vector that can have one of the following values. The default value
is enclosed in braces (`{}`

).

Value | Description |
---|---|

| Rearranges each |

| Converts each |

For the sliding block case, each column of `B`

contains
the neighborhoods of `A`

reshaped as `NHOOD(:)`

where `NHOOD`

is
a matrix containing an `m`

-by-`n`

neighborhood
of `A`

. `im2col`

orders the columns
of `B`

so that they can be reshaped to form a matrix
in the normal way. For Examples, 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);

`B = im2col(A,'indexed',...)`

processes `A`

as
an indexed image, padding with 0's if the class of `A`

is `uint8`

or `uint16`

,
or 1's if the class of `A`

is `double`

.

The input image `A`

can be numeric or logical.
The output matrix `B`

is of the same class as the
input image.

Calculate the local mean using a `[2 2]`

neighborhood
with zero padding:

A = reshape(linspace(0,1,16),[4 4])' B = im2col(A,[2 2]) M = mean(B) newA = col2im(M,[1 1],[3 3])

The output appears like this:

newA = 0.1667 0.2333 0.3000 0.4333 0.5000 0.5667 0.7000 0.7667 0.8333

Was this topic helpful?