解决RGB模式下图片的padding(补边框)问题(含代码实现)

更新时间:2023-05-25 21:17:14 阅读: 评论:0

解决RGB模式下图⽚的padding(补边框)问题(含代码实
现)
⾸先,说到图⽚的padding问题,我们知道对于灰度图(channel=1)的图⽚我们可以之间将其转化为numpy.array,然后利⽤
饮水机功率
江苏分数线np.pad(image,((up,down),(left,right)),'constant', constant_values=(255,255))对图像填充边框,⽽对于RGB模式(channel=3)下的图⽚,则⽆法采⽤该⽅法进⾏填充。但有了之前的基础,我们可以采⽤相同的原理进⾏填充。即将RGB模式的图⽚转化为⼀个三维的数组,然后利⽤分⽚技术,分别提取出每⼀维的数组进⾏填充。最后再利⽤numpy.array的深度矩阵拼接函数将三个⼆维的数组合成⼀个三维的数组。然后再将其转换为RGB格式的图⽚。
其代码实现如下所⽰:
武夷山北站⾸先先贴上原图:
代码部分:
import numpy as np
幼儿线条画from PIL import Image
import matplotlib.pyplot as plt
image = Image.open("Dr.Strange.jpg")
水晶方法
image = np.array(image)
#打印原来的图⽚
plt.imshow(image,cmap = ay())
plt.show()
channel_one = image[:,:,0]
channel_two = image[:,:,1]
channel_three = image[:,:,2]
channel_one = np.pad(channel_one, ((10, 10),(10, 10) ),  'constant', constant_values=(0,0))五年级下册科学
channel_two = np.pad(channel_two, ((10, 10),(10, 10) ),  'constant', constant_values=(0,0))
channel_three = np.pad(channel_three, ((10, 10),(10, 10) ),  'constant', constant_values=(0,0))
image = np.dstack((channel_one,channel_two,channel_three))
什么的秋天
#打印处理完的图⽚
plt.imshow(image,cmap = ay())
plt.show()
image = Image.fromarray(image)
特别虐的小说
image.save("Dr.Strange.jpg")
最终的效果图:

本文发布于:2023-05-25 21:17:14,感谢您对本站的认可!

本文链接:https://www.wtabcd.cn/fanwen/fan/82/775590.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:填充   模式   代码   问题   边框   知道
相关文章
留言与评论(共有 0 条评论)
   
验证码:
推荐文章
排行榜
Copyright ©2019-2022 Comsenz Inc.Powered by © 专利检索| 网站地图