Image Processing Toolbox | ![]() ![]() |
Syntax
Description
B = padarray(A,
padsize,method,direction)
pads array A
with padsize
number of elements along each dimension, using specified method
and direction
. The N
-th element of the padsize
vector specifies the padding size for the N
-th dimension of the array, A
.
method
can be a numeric scalar, in which case it specifies the value for all padding elements, or one of the following strings which specify other methods used to determine pad values. By default, METHOD
sets the pad value to the 0
.
Value |
Meaning |
'circular' |
Pad with circular repetition of elements within the dimension. |
'replicate' |
Pad by repeating border elements of array. |
'symmetric' |
Pad array with mirror reflections of itself. |
direction
specifies where to pad the array along each dimension. By default, direction
is 'post'
.
Class Support
When padding with a constant value, A
can be numeric or logical. When padding using the 'circular'
, 'replicate'
, or 'symmetric'
methods, A
can be of any class. B
is of the same class as A
.
Example
Add three elements of padding to the beginning of a vector. The padding elements contain mirror copies of the array.
Add three elements of padding to the end of the first dimension of the array and two elements of padding to the end of the second dimension. Use the value of the last array element as the padding value.
Add three elements of padding to each dimension of a three-dimensional array. Each pad element contains the value 0
.
A = [ 1 2; 3 4]; B = [ 5 6; 7 8]; C = cat(3,A,B) C(:,:,1) = 1 2 3 4 C(:,:,2) = 5 6 7 8 D = padarray(C,[3 3],0,'both') D(:,:,1) = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 0 3 4 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 D(:,:,2) = 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 6 0 0 0 0 0 0 7 8 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
See Also
![]() | otf2psf | phantom | ![]() |