# CV预备(二): im2col与col2im

• 前言
• im2col
• col2im
• 最后

## 前言

Matlab矩阵处理的函数真的是太多了, 这里来看两个矩阵重排的函数im2colcol2im.

## im2col

• B = im2col(A, [m n])
• B = im2col(A, [m n], 'sliding')
• B = im2col(A, [m n], 'distinct')

B = im2col(A, [m n])B = im2col(A, [m n], 'sliding') 是等价的. 所以先从它开始说吧:

### B = im2col(A, [m n], 'sliding')

```A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
B = im2col(A, [2 2])```

```A =

1     2     3     4
5     6     7     8
9    10    11    12
13    14    15    16

B =

1     5     9     2     6    10     3     7    11
5     9    13     6    10    14     7    11    15
2     6    10     3     7    11     4     8    12
6    10    14     7    11    15     8    12    16```

## col2im

col2im就是im2col的逆过程. col2im有3中形式, 如下:

• A = col2im(B, [m n], [M N])
• A = col2im(B, [m n], [M N], 'sliding')
• A = col2im(B, [m n], [M N], 'distinct')

### A = col2im(B, [m n], [M N], 'sliding')

```B = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
A = col2im(B, [1 1], [2, 8], 'sliding')```

```B =

1     2     3     4
5     6     7     8
9    10    11    12
13    14    15    16

A =

1     9     2    10     3    11     4    12
5    13     6    14     7    15     8    16```

### A = col2im(B, [m n], [M N], 'distinct')

```B = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]
A = col2im(A, [2 2], [2 8], 'distinct')```

```B =

1     2     3     4
5     6     7     8
9    10    11    12
13    14    15    16

A =

1     9     2    10     3    11     4    12
5    13     6    14     7    15     8    16```

67 篇文章30 人订阅

0 条评论