Main Content

col2im

Rearrange matrix columns into blocks

Description

A = col2im(B,[m n],[M N]) or

A = col2im(B,[m n],[M N],'sliding') rearranges the row vector B into neighborhoods of size m-by-n to create the matrix A of size (M-m+1)-by-(N-n+1).

The row vector B is usually the result of processing the output of im2col(...,'sliding') using a column compression function, such as sum.

example

A = col2im(B,[m n],[M N],'distinct') rearranges each column of matrix B into a distinct m-by-n block to create the matrix A of size M-by-N.

For example, if B consists of column vectors Bi(:) with length m*n, arranged as B = [B1(:) B2(:) B3(:) B4(:)], then A = [B1 B3; B2 B4] where each block Bi has size m-by-n.

Examples

collapse all

Create a matrix.

B = reshape(uint8(1:25),[5 5])'
B = 5x5 uint8 matrix

    1    2    3    4    5
    6    7    8    9   10
   11   12   13   14   15
   16   17   18   19   20
   21   22   23   24   25

Rearrange the values in the matrix into a column-wise arrangement.

C = im2col(B,[1 5])
C = 5x5 uint8 matrix

    1    6   11   16   21
    2    7   12   17   22
    3    8   13   18   23
    4    9   14   19   24
    5   10   15   20   25

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

A = col2im(C,[1 5],[5 5],'distinct')
A = 5x5 uint8 matrix

    1    2    3    4    5
    6    7    8    9   10
   11   12   13   14   15
   16   17   18   19   20
   21   22   23   24   25

Input Arguments

collapse all

Image blocks, specified as one of the following.

  • For distinct block processing, B is a numeric or logical matrix with m*n rows. Each column corresponds to one block.

  • For sliding neighborhood processing, B is a numeric or logical row vector of size 1-by-(M-m+1)*(N-n+1).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

Block size, specified as a 2-element vector of positive integers. m is the number of rows and n is the number of columns in each block. m*n must be equal to the number of rows of B.

Data Types: double

Image size, specified as a 2-element vector of positive integers. M is the number of rows and N is the number of columns in the image.

Data Types: double

Output Arguments

collapse all

Reconstructed image, returned as a numeric matrix of size M-by-N for distinct block processing, or (M-m+1)-by-(N-n+1) for sliding block processing. A has the same data type as B.

Version History

Introduced before R2006a