色相饱和强度直方图

时间:2013-11-05 12:27:40

标签: numpy matplotlib scipy python-imaging-library

我使用的是Debian Linux Siduction。我有一个jpg格式的图像,我可以阅读并转换为arrray。但我想将图像从RGB颜色模型转换为HSI颜色模型,然后绘制HSI图像的饱和度和整数参数的直方图。我试图绘制intesity部分,但我不确定我的结果的准确性。我已经包含了代码。

import scipy
from scipy import ndimage
import matplotlib.pyplot as plt
import matplotlib.colors as colors
import numpy as np
from scipy import misc
import scipy.misc

img = scipy.misc.imread("/home/subhradeep/Desktop/ref.jpg")
array=np.asarray(img)
arr=(array.astype(float))/255.0
img_hsv = colors.rgb_to_hsv(arr[...,:3])

lu1=img_hsv[...,0].flatten()
plt.subplot(1,3,1)
plt.hist(lu1*360,bins=360,range=(0.0,360.0),histtype='stepfilled', color='r', label='Hue')
plt.title("Hue")
plt.xlabel("Value")
plt.ylabel("Frequency")
plt.legend()

lu2=img_hsv[...,1].flatten()
plt.subplot(1,3,2)                  
plt.hist(lu2,bins=100,range=(0.0,1.0),histtype='stepfilled', color='g', label='Saturation')
plt.title("Saturation")   
plt.xlabel("Value")    
plt.ylabel("Frequency")
plt.legend()

lu3=img_hsv[...,2].flatten()
plt.subplot(1,3,3)                  
plt.hist(lu3*255,bins=256,range=(0.0,255.0),histtype='stepfilled', color='b', label='Intesity')
plt.title("Intensity")   
plt.xlabel("Value")    
plt.ylabel("Frequency")
plt.legend()
plt.show()

这是我通过获取bin大小100得到的直方图但我不确定什么应该是我的数据的合适大小

enter image description here

1 个答案:

答案 0 :(得分:1)

img = scipy.misc.imread("/home/subhradeep/Desktop/test.jpg")
array=np.asarray(img)
# convert, but this is buggy 
im_hsv = matplotlib.colors.rgb_to_hsv(array[...,:3])
# pull out just the s channel
lu=img_hsv[...,1].flatten()
plt.hist(lu,256)
plt.show()
相关问题