2-3 1次関数による濃淡調整「折れ線トーンカーブ処理」
img_src = cv2.imread("data/Mandrill.png")
#ルックアップテーブルの設定
a = 1.1 #傾き
b = 50 #切片
look_up_table = np.zeros((256, 1), dtype = 'uint8')
for i in range(256):
p = a * i + b
if p > 255:
p = 255
if p < 0:
p = 0
look_up_table[i][0] = p
img_dst = cv2.LUT(img_src, look_up_table)
#描画する
cv2.imshow("img_src",img_src)
cv2.imshow("img_dst",img_dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
#ヒストグラム
fig = plt.figure()
ax1 = fig.add_subplot(311) #総行数,総列数、サブプロット番号
ax2 = fig.add_subplot(312)
ax3 = fig.add_subplot(313)
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)
ax1.set_ylim(0,600)
for i,j in enumerate(color_list):
hist = cv2.calcHist([img_dst],[i],None,[256],[0,256])
ax2.plot(hist,color = j)
ax2.set_ylim(0,600)
x = [x for x in range(256)]
ax3.plot(x,look_up_table)
ax3.set_ylim(0,260)