首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >python numpy 图片 pad 参数详解

python numpy 图片 pad 参数详解

原创
作者头像
不被定义的云
发布2022-05-15 20:08:36
发布2022-05-15 20:08:36
54500
举报
文章被收录于专栏:不被定义的云不被定义的云
运行总次数:0

python numpy 图片 pad 参数详解

'constant', 'edge', 'linear_ramp', 'maximum', 'mean', 'median', 'minimum', 'reflect', 'symmetric', 'wrap', 'empty'  

光看文档不太好理解,因为在网上找不到详细的例子,所以我就自己动手做了一个例子。  

为了更好的演示,我剪裁了原图右边和下边的留白区域。  

```  

mode : str or function, optional

    One of the following string values or a user supplied function.

    'constant' (default)

        Pads with a constant value.

    'edge'

        Pads with the edge values of array.

    'linear_ramp'

        Pads with the linear ramp between end_value and the array edge value.

    'maximum'

        Pads with the maximum value of all or part of the vector along each axis.

    'mean'

        Pads with the mean value of all or part of the vector along each axis.

    'median'

        Pads with the median value of all or part of the vector along each axis.

    'minimum'

        Pads with the minimum value of all or part of the vector along each axis.

    'reflect'

        Pads with the reflection of the vector mirrored on the first and last values of the vector along each axis.

    'symmetric'

        Pads with the reflection of the vector mirrored along the edge of the array.

    'wrap'

        Pads with the wrap of the vector along the axis. The first values are used to pad the end and the end values are used to pad the beginning.

    'empty'

        Pads with undefined values.

```  

代码语言:javascript
代码运行次数:0
运行
复制
modes = ['constant', 'edge', 'linear_ramp', 'maximum', 'mean', 'median', 'minimum', 'reflect', 'symmetric', 'wrap', 'empty' ]
pic = cv2.imread('D:/share/QRcode/taobao.jpg') 
pic = cv2.cvtColor(pic, cv2.COLOR_BGR2RGB)
plt.figure(figsize=(500,120))
plt.subplot(12,1,1)
plt.title('Raw(Cut right and down side)')
plt.imshow(pic)
for index, mode in enumerate(modes):
    plt.subplot(12,1,index+2)
    pic_pad = np.pad(pic, ((100,100), (100,100), (0,0)) , mode)
    plt.title(mode)
    plt.imshow(pic_pad)

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • python numpy 图片 pad 参数详解
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档