Matlab padarray函数详解

在MATLAB中可以很方便的使用padarray函数进行图像的填充。
padarray函数可以有两个至四个参数,以下是官方文档介绍

    B = padarray(A,PADSIZE) pads array A with PADSIZE(k) number of zeros
    along the k-th dimension of A.  PADSIZE should be a vector of
    nonnegative integers.

    B = padarray(A,PADSIZE,PADVAL) pads array A with PADVAL (a scalar)
    instead of with zeros.

    B = padarray(A,PADSIZE,PADVAL,DIRECTION) pads A in the direction
    specified by the string DIRECTION.  DIRECTION can be one of the
    following strings.

        String values for DIRECTION
        'pre'         Pads before the first array element along each
                      dimension .
        'post'        Pads after the last array element along each
                      dimension.
        'both'        Pads before the first array element and after the
                      last array element along each dimension.

    By default, DIRECTION is 'both'.

    B = padarray(A,PADSIZE,METHOD,DIRECTION) pads array A using the
    specified METHOD.  METHOD can be one of these strings:

        String values for METHOD
        'circular'    Pads with circular repetition of elements.
        'replicate'   Repeats border elements of A.
        'symmetric'   Pads array with mirror reflections of itself.

padsize给出了给出了填充的行数和列数,通常用[r c]来表示

padval表示填充方法。它的具体值和描述如下
 padval: ‘symmetric’表示图像大小通过围绕边界进行镜像反射来扩展;
‘replicate’表示图像大小通过复制外边界中的值来扩展;
‘circular’图像大小通过将图像看成是一个二维周期函数的一个周期来进行扩展。

direction表示填充的方向。它的具体值和描述如下:
direction : ‘pre’表示在每一维的第一个元素前填充;
‘post’表示在每一维的最后一个元素后填充;
‘both’表示在每一维的第一个元素前和最后一个元素后填充,此项为默认值。

下面举个栗子:

>>f=[1 2;3 4];
>> fp=padarray(f,[3 2],'replicate','post');
>> fp

结果为
fp =

 1     2     2     2
 3     4     4     4
 3     4     4     4
 3     4     4     4
 3     4     4     4

一.更改direction

1.把’post’换成’pre’

>>f=[1 2;3 4];
>> fp=padarray(f,[3 2],'replicate','pre');
>> fp

结果为
fp =

 1     1     1     2
 1     1     1     2
 1     1     1     2
 1     1     1     2
 3     3     3     4

2.再换成’both’

fp =

 1     1     1     2     2     2
 1     1     1     2     2     2
 1     1     1     2     2     2
 1     1     1     2     2     2
 3     3     3     4     4     4
 3     3     3     4     4     4
 3     3     3     4     4     4
 3     3     3     4     4     4

二,更改padval
1.把’replicate’改为’symmetric’
结果为

fp =

 1     2     2     1
 3     4     4     3
 3     4     4     3
 1     2     2     1
 1     2     2     1

2.改为’circular’
结果为
fp =

 1     2     1     2
 3     4     3     4
 1     2     1     2
 3     4     3     4
 1     2     1     2
  • 5
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值