ImageOps.pad()函数解析

1、PIL.ImageOps.pad(image, size, method=3, color=None, centering=0.5, 0.5)​
返回图像的大小和填充版本,展开以填充请求的纵横比和大小。

参数:

  1. image – 要调整大小和裁剪的图像。
  2. size – 请求的输出大小(以像素为单位),以(宽度、高度)元组的形式给出。
  3. method – 使用什么样的重采样方法。默认是 PIL.Image.BICUBIC . 见过滤器 :https://www.w3cschool.cn/pillow_course/filter.html
  4. color – 填充图像的背景色。
  5. centering – 控制原始图像在填充版本中的位置。(0.5,0.5)将使图像居中(0,0)将使图像与左上角对齐(1,1)将使图像与右下角对齐

返回:
一个Image

2、Demo展示:

from PIL import Image,ImageOps
import cv2
import numpy as np

img = Image.open(r'C:\Users\demo.jpg')
print (img)
for i in range(6):
    img2 = ImageOps.pad(img,(224,224),method=i,color=(0),centering=(0.5,0.5))
    dst = np.array(img2)
    cv2.imshow(f'dst:{i}',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=65x202 at 0x10545C80608>
在这里插入图片描述


参考链接:https://www.w3cschool.cn/pillow_course/pillow_course-aqx33ipy.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值