Signal Processing Toolbox | ![]() ![]() |
Syntax
C=
conv2(A,
B) C=
conv2(A,B,'shape
')
Description
C
computes the two-dimensional convolution of matrices =
conv2(A,B)
A
and B
. If one of these matrices describes a two-dimensional FIR filter, the other matrix is filtered in two dimensions.
Each dimension of the output matrix C
is equal in size to one less than the sum of the corresponding dimensions of the input matrices. When [ma,na]
= size(A)
and [mb,nb]
= size(B)
,
size(C) = [ma+mb-1,na+nb-1]
C
returns a subsection of the two-dimensional convolution with size specified by =
conv2(A,B,'shape
')
'
shape
'
, where:
'full'
returns the full two-dimensional convolution (default)'same'
returns the central part of the convolution that is the same size as A
'valid'
returns only those parts of the convolution that are computed without the zero-padded edges. Using this option, size(C) = [ma-mb+1,na-nb+1]
when size(A)
> size(B)
conv2
executes most quickly when size(A)
> size(B)
.
The conv2
function is part of the standard MATLAB language.
Examples
In image processing, the Sobel edge-finding operation is a two-dimensional convolution of an input array with the special matrix
s =
[1 2 1; 0 0 0; -1 -2 -1];
Given any image, the following code extracts the horizontal edges.
h =
conv2(I,s);
The following code extracts the vertical edges first, and then extracts both horizontal and vertical edges combined.
v=
conv2(I,s'); v2=
(sqrt(h.^2 + v.^2))
See Also
|
Convolution and polynomial multiplication. |
|
N-dimensional convolution (see the MATLAB documentation). |
|
Deconvolution and polynomial division. |
|
Apply a two-dimensional filter to data. |
|
Cross-correlation function estimate. |
|
Two-dimensional cross-correlation. |
![]() | conv | convmtx | ![]() |