我有一张100像素的图像。对于每个像素,我想用零填充(如果在边缘),使其位于中心,与相邻像素连接并生成新的10x10图像。因此,我想从原始图像生成100个图像,方法是沿着行滑动每个像素。e、 g.对于像素[0,0],我想在右侧添加4个零列,在顶部添加4个零行,在右侧添加相邻的5列像素,在底部添加相邻的5行像素。在
有人能指导我如何使用numpy对RGB图像进行处理吗?在
def unpickle_im(file, type):
import Image
im1 = Image.open(file)
im1p = np.asarray(im1, dtype=type)
return im1p
imc2p = unpickle_im('tmp/RGB-00000.png', 'float32')
##imc2p.shape = (10,10,3)
padded = np.zeros(10,10,3) ##Create a padded image filled with zeros
for i in xrange(im2cp.shape[0]):
for j in xrange(im2cp.shape[1]):
if(i < 5 or j < 5) :
new_im2cp = np.pad(im2cp[i:5, j:5], ((4-i,4-j),(0,0)))
else:
new_im2cp = np.pad(im2cp[i-4:i+5, j-4:j+5])
编辑:在@dabhaid的帖子后添加正确的片段:
^{pr2}$
我假设你有一个RGB图像(而不是RGBA)。根据评论,这是你想要的吗?在
这似乎是浪费,记忆明智。在
编辑以回答问题更新
不要有条件地填充新图像,而是填充原始图像,然后从中复制子图像:
^{pr2}$相关问题 更多 >
编程相关推荐