有没有更简单,更快速的方法?
maxr, maxc = im_out.shape[:2]
for col in range(maxc):
for row in range(maxr):
if im_gray[row,col,0] != 255 and im_gray[row,col,1] != 255 and im_gray[row,col,2] != 255:
im_out[row, col] = im_gray[row, col]
最佳答案
遵循以下方法应该可以解决问题:
# I think it's axis 2, might have to play around there
mask = (im_gray != 255).all(axis=2)
im_out[mask] = im_gray[mask]
关于python - 这种NumPy列表理解的捷径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30437547/