我有一个使用imread.0加载的2D灰度图像
我想给它上色。
使用numpy / skimage / python实现此目的的最佳方法是什么?
答案 0 :(得分:2)
这将取决于您输入的确切格式。但是基本过程应该很简单:
>>> import numpy as np
>>> from skimage import data, io
>>>
# an example grey scale image
>>> grey = data.coins()
# a helper for convenient channel (RGB) picking
>>> RGB = np.array((*"RGB",))
# the actual coloring can be written as an outer product
>>> red = np.multiply.outer(grey, RGB=='R')
# save for posterity
>>> io.imsave('red.png', red)
答案 1 :(得分:1)
如果这是一个单通道图像,则可以通过执行以下操作将其转换为“ redscale”图像:
zero_channel = np.zeros_like(greyscale_array)
redscale = np.stack([greyscale_array, zero_channel, zero_channel], axis=2)
在不完全了解数组形状的情况下,尽管很难回答
答案 2 :(得分:0)
import matplotlib.pyplot as plt
from skimage import color
from skimage import img_as_float
from PIL import Image
jpgfile = Image.open("pp.jpg")
grayscale_image = img_as_float(jpgfile)
image = color.gray2rgb(grayscale_image)
red_multiplier = [1, 0, 0]
fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(8, 4),
sharex=True, sharey=True)
ax1.imshow(red_multiplier * image)
plt.show()