【发布时间】:2019-01-23 05:55:25
【问题描述】:
我在一个区域中有一个带有掩码值的方阵(图像)。掩码对应于靠近边界的区域中的缺失值(总是)。我想创建一个新图像,其中掩蔽值替换为实际图像值存在的值的反射填充。我怎么能在python中这样做?
在下面的示例中,我想用中间面板的反射图像替换(左侧面板)黄色区域,其中存在数据。结果应该类似于右面板图像(这里的填充不是我所追求的适当反射填充,因为我只是使用了简单的配方right_image = np.where(temp.mask,middle_image[::-1,::-1],middle_image))
编辑:我尝试将图像逐行横向,并使用numpy反射填充,代码如下,但它不起作用:
# Row Reflect
# Here out_image is the original image, where -2 is no data value
xx = []
for i in range(6000): # Number of rows
temp1 = np.ma.array(out_image[0,i,:],mask= out_image[0,i,:]==-2) # Create mask per row, -2 is the masked value
edges = ma.flatnotmasked_edges(temp1) # Find edges
#if edges is not None:
xx += [np.expand_dims(np.pad(temp1.data[edges[0]:edges[1]],((edges[0],temp1.shape[0]-edges[1])),mode='reflect'),0)]
out = np.concatenate(xx)
#out = out.reshape(2000,2000)
【问题讨论】:
标签: python python-3.x numpy data-science