當前位置:成語大全網 - 書法字典 - 平方和伽瑪校正-OpenCV &;計算機編程語言

導入cv2

將numpy作為np導入

將matplotlib.pyplot作為plt導入

從mpl_toolkits.mplot3d導入Axes3D

img _ path = ' C:/Users/wz chan/Desktop/'

img = cv2 . im read(img _

平方和伽瑪校正-OpenCV &;計算機編程語言

導入cv2

將numpy作為np導入

將matplotlib.pyplot作為plt導入

從mpl_toolkits.mplot3d導入Axes3D

img _ path = ' C:/Users/wz chan/Desktop/'

img = cv2 . im read(img _

平方和伽瑪校正-OpenCV &;計算機編程語言

導入cv2

將numpy作為np導入

將matplotlib.pyplot作為plt導入

從mpl_toolkits.mplot3d導入Axes3D

img _ path = ' C:/Users/wz chan/Desktop/'

img = cv2 . im read(img _ path+' test _ 600 x350 _ im write . jpg ')

hist_b = cv2.calcHist([img],[0],None,[256],[0,256])

hist_g = cv2.calcHist([img],[0],None,[256],[0,256])

hist_r = cv2.calcHist([img],[0],None,[256],[0,256])

定義伽瑪轉換(img,伽瑪):

gamma_table = [np.power(x / 255.0,gamma)*範圍(256)中x的255.0]

γ_ table = NP . round(NP . array(γ_ table))。astype(np.uint8)

img_corrected = gamma_trans(img,0.5)

cv2 . im write(img _ path+' gamma _ corrected . jpg ',img_corrected)

hist _ b _ corrected = cv2 . calchist([img _ corrected],[0],None,[256],[0,256])

hist _ g _ corrected = cv2 . calchist([img _ corrected],[0],None,[256],[0,256])

hist _ r _ corrected = cv2 . calchist([img _ corrected],[0],None,[256],[0,256])

圖= plt.figure()

pix_hists = [

[歷史b,歷史g,歷史r],

[歷史_ b _校正,歷史_ g _校正,歷史_ r _校正]

]

pix_vals =範圍(256)

對於sub_plt,zip中的pix_hists([121,122],pix _ hists):

ax = fig.add_subplot(sub_plt,projection = '3d ')

對於c,z,channel_hist in zip(['b ',' g ',' r'],[20,10,0],pix_hists):

cs = [c] * 256

ax.bar(pix_vals,channel_hist,zs=z,zdir='y ',color=cs,alpha=0.618,edgecolor='none ',lw=0)

ax.set_xlabel('像素值')

ax.set_xlim([0,256])

ax.set_ylabel('計數')

ax.set_zlabel('通道')

plt.show()