解决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")
最终的效果图: