您可以使用更简单、更自然的方法。如果在一个通道上应用的偏移不一致,那么什么是颜色过滤器?我通常只使用
np.power
img
是图像的3D RGB矩阵:
img = np.power(img,[1.5, 1.0, 1.0]) # shift the reds
img = np.power(img,[1.0, 1.5, 1.0]) # shift the greens
img = np.power(img,[1.2, 1.2, 1.0]) # orange type? (I suck at color mixing, you'll find out the one you need to shift) (since all your colors are made from a combination of these three basic ones)
我刚刚停止使用openCV和PIL(顺便说一句,这是不推荐使用的),看看
skimage
要仅在屏蔽部分应用过滤器,可以执行以下操作:
mask = numpy.expand_dims(mask, 2)
mask = numpy.repeat(mask, 3, axis=2) # give the mask the same shape as your image
colors = {"red": [0.1,0.,0.], "blue": [0.,0.,0.1]} # a dictionary for your colors, experiment with the values
colored_mask = numpy.multiply(mask, colors["red"]) # broadcast multiplication (thanks to the multiplication by 0, you'll end up with values different from 0 only on the relevant channels and the right regions)
img = img+colored_mask # element-wise sum (sinc img and mask have the same shape)