# Documentation

### This is machine translation

Translated by
Mouseover text to see original. Click the button below to return to the English verison of the page.

# im2col

Rearrange image blocks into columns

## Syntax

B = im2col(A,[m n],block_type)
B = im2col(A,'indexed',...)

## Description

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

'distinct'

Rearranges each distinct m-by-n block in the image A into a column of B. im2col pads A with 0's, if necessary, so its size is an integer multiple of m-by-n. If A = [A11 A12; A21 A22], where each Aij is m-by-n, then B = [A11(:) A12(:) A21(:) A22(:)].

{'sliding'}

Converts each sliding m-by-n block of A into a column of B, with no zero padding. B has m*n rows and contains as many columns as there are m-by-n neighborhoods of A. If the size of A is [mm nn], then the size of B is (m*n)-by-((mm-m+1)*(nn-n+1)).

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.

## Class Support

The input image A can be numeric or logical. The output matrix B is of the same class as the input image.

## Examples

collapse all

Create a matrix.

A = reshape(linspace(0,1,16),[4 4])'
A =

0    0.0667    0.1333    0.2000
0.2667    0.3333    0.4000    0.4667
0.5333    0.6000    0.6667    0.7333
0.8000    0.8667    0.9333    1.0000

Rearrange the values into a column-wise arrangement.

B = im2col(A,[2 2])
B =

Columns 1 through 7

0    0.2667    0.5333    0.0667    0.3333    0.6000    0.1333
0.2667    0.5333    0.8000    0.3333    0.6000    0.8667    0.4000
0.0667    0.3333    0.6000    0.1333    0.4000    0.6667    0.2000
0.3333    0.6000    0.8667    0.4000    0.6667    0.9333    0.4667

Columns 8 through 9

0.4000    0.6667
0.6667    0.9333
0.4667    0.7333
0.7333    1.0000

Calculate the mean.

M = mean(B)
M =

Columns 1 through 7

0.1667    0.4333    0.7000    0.2333    0.5000    0.7667    0.3000

Columns 8 through 9

0.5667    0.8333

Rearrange the values back into their original, row-wise orientation.

newA = col2im(M,[1 1],[3 3])
newA =

0.1667    0.2333    0.3000
0.4333    0.5000    0.5667
0.7000    0.7667    0.8333