目的是将纯红色图像转换为色轮的任何色调。
- 单色图像首先转换为 RGB 红色图像,例如:
- 然后转化为 HSV
- 通过添加一个应该与轮子颜色匹配的角度值来修改色调分量
- 然后将 hsv 图像转换回 rgb 颜色空间。
问题是只能获得绿色或蓝色图像(例如角度约 30° 时没有黄色):
在一些 ipython 单元中执行的代码依赖于 scikit-image 0.10dev:
from skimage import io
from skimage import color
from scipy import ndimage as nd
import numpy as np
from matplotlib import pyplot as plt
import os
cy55 = io.imread('/home/jeanpat/MFISH/PSI/P07/01/Cy5/P070109C.tif')
zero = np.zeros(cy55.shape,dtype=np.uint8)
rgb0 = np.dstack([cy55, zero,zero])
hue_rotations = [18, 36,72,90,108]
images = {}
images[0] = rgb0
hsv0 = color.rgb2hsv(rgb0)
print hsv0[:,:,0].dtype
for hue in hue_rotations:
hsv = np.copy(hsv0)
hsv[:,:,0] = hsv[:,:,0]+ hue
rgb = color.hsv2rgb(hsv)
images[hue] = rgb
i = 1
plt.figure(num=None, figsize=(15, 5), facecolor='w', edgecolor='k')
for hue in np.sort(images.keys()):
plt.subplot(1,6,i,xticks=[],yticks=[])
plt.title('hue='+str(hue))
plt.imshow(images[hue])
i = i +1
plt.show()