2014-03-19 2 views
3

목표는 순수한 빨간색 이미지를 색상환의 색상으로 변환하는 것입니다.scikit-image를 사용하여 HSV에서 색상 회전

  • 모노크롬 화상 먼저 RGB 적색 화상, 전 변환된다 original monochrome image
  • 후 HSV
  • 색조 성분 매치 휠 색상하는데 각도 값을 가산함으로써 수정 변환
  • 그러면 hsv 이미지가 rgb 색상 공간으로 다시 변환됩니다.

문제점은 녹색 또는 청색의 화상 (N o yellow for an angle~30° for example)을 수득 할 수있다 : Hue rotation

일부 ipython 세포에서 수행되는 코드 scikit 화상 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() 
+0

비 scikit 이미지 솔루션은 여기에 있습니다 :처럼 사용의 빠른 예 보일 수 있습니다 http://stackoverflow.com/questions/7274221/changing- image-hue-with-python-pil/7274986 # 7274986 –

+0

해결책은 여기에 있습니다. https://groups.google.com/forum/?hl=fr#!topic/scikit-image/U9SPUWNS1ZM –

답변

5

나는 이것을 메일 링리스트에서 대답했지만, 여기에서 해결책을 찾아서 찾기 쉽다. (그리고 형식이 더 예쁘다.)

기본적으로 색조 표현 방식 (0-180 대신 0-1), uint8 및 float 데이터 유형, 그리고 그레이 스케일 이미지가 RGB로 변환되는 방법에 대한 일부 문제가 있습니다. 주는

import numpy as np 
import matplotlib.pyplot as plt 
from skimage import color 
from skimage import data 


def colorize(image, hue): 
    """Return image tinted by the given hue based on a grayscale image.""" 
    hsv = color.rgb2hsv(color.gray2rgb(image)) 
    hsv[:, :, 0] = hue 
    hsv[:, :, 1] = 1 # Turn up the saturation; we want the color to pop! 
    return color.hsv2rgb(hsv) 


image = data.camera()[::2, ::2] 

hue_rotations = np.linspace(0, 1, 6) # 0--1 is equivalent to 0--180 
colorful_images = [colorize(image, hue) for hue in hue_rotations] 

fig, axes = plt.subplots(nrows=2, ncols=3) 

for ax, array in zip(axes.flat, colorful_images): 
    ax.imshow(array, vmin=0, vmax=1) 
    ax.set_axis_off() 

plt.show() 

:

colorized grayscale image