Reputation: 101
I have a 2D grey scale image, loaded using imread.0
I want to colourise it.
whats the best way to use numpy/skimage/python to achieve this?
Upvotes: 1
Views: 1617
Reputation: 844
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()
Upvotes: 1
Reputation: 53039
It will depend a bit on the exact format of your input. But the basic procedure should be as simple as:
>>> 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)
Upvotes: 2
Reputation: 2939
if this is a single channel image you could convert it to a "redscale" image by doing something like this:
zero_channel = np.zeros_like(greyscale_array)
redscale = np.stack([greyscale_array, zero_channel, zero_channel], axis=2)
without fully understanding the shape of your array it's difficult to answer though
Upvotes: 1