Interface2017年05月号新画像処理101を読む

3-2 画像の明るさ強度を示す「Y画像」(YIQフォーマット)

img_src = cv2.imread("data/img_3-2.bmp")

img_gray = img_src[:,:,0] * 0.114478 + img_src[:,:,1] * 0.586611 + img_src[:,:,2] * 0.298912 

#img_srcと同じ大きさのゼロ配列を作成してimg_dstを構成
img_dst = np.zeros_like(img_src)

#グレイ画像の明度を調整
img_dst [:,:,0] = img_gray
img_dst [:,:,1] = img_gray
img_dst [:,:,2] = img_gray

#描画する
cv2.imshow("img_src",img_src)
cv2.imshow("img_dst",img_dst)
cv2.waitKey(0)
cv2.destroyAllWindows()


#ヒストグラム
fig = plt.figure()
ax1 = fig.add_subplot(211) #総行数,総列数、サブプロット番号
ax2 = fig.add_subplot(212)

color_list = ["blue","green","red"]
for i,j in enumerate(color_list):
    hist = cv2.calcHist([img_src],[i],None,[256],[0,256])
    ax1.plot(hist,color = j)
color_list = ["gray"]
for i,j in enumerate(color_list):
    hist = cv2.calcHist([img_dst],[i],None,[256],[0,256])
    ax2.plot(hist,color = j)

f:id:bitop:20180203081129p:plain

f:id:bitop:20180203081154p:plain

f:id:bitop:20180203081230p:plain