日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python gamma函数_python gamma矫正

發(fā)布時間:2025/3/12 python 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python gamma函数_python gamma矫正 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

這個函數(shù),主要用來做對比度調(diào)整,利用 gamma 曲線 或者 log 函數(shù)曲線,

gamma 函數(shù)的表達式:? y=xγ, 其中,?x?是輸入的像素值,取值范圍為?[0?1],?y?是輸出的像素值,通過調(diào)整γ?值,改變圖像的像素值的分布,進而改變圖像的對比度。? log 函數(shù)的表達式:? y=alog(1+x),?a?是一個放大系數(shù),x?同樣是輸入的像素值,取值范圍為?[0?1],?y?是輸出的像素值。? inverse log 的表達式:? y=a(2x?1), 這些變換都是從?[0?1]?變到?[0?1]?。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88""" ================================= Gamma and log contrast adjustment ================================= This example adjusts image contrast by performing a Gamma and a Logarithmic correction on the input image. """

import matplotlib

import matplotlib.pyplot as plt

import numpy as np

from skimage import data, img_as_float

from skimage import exposure

matplotlib.rcParams['font.size'] = 8

def plot_img_and_hist(img, axes, bins=256):

"""Plot an image along with its histogram and cumulative histogram. """

img = img_as_float(img)

ax_img, ax_hist = axes

ax_cdf = ax_hist.twinx()

# Display image

ax_img.imshow(img, cmap=plt.cm.gray)

ax_img.set_axis_off()

# Display histogram

ax_hist.hist(img.ravel(), bins=bins, histtype='step', color='black')

ax_hist.ticklabel_format(axis='y', style='scientific', scilimits=(0, 0))

ax_hist.set_xlabel('Pixel intensity')

ax_hist.set_xlim(0, 1)

ax_hist.set_yticks([])

# Display cumulative distribution

img_cdf, bins = exposure.cumulative_distribution(img, bins)

ax_cdf.plot(bins, img_cdf, 'r')

ax_cdf.set_yticks([])

return ax_img, ax_hist, ax_cdf

# Load an example image

img = data.moon()

# Gamma

gamma_corrected = exposure.adjust_gamma(img, 2)

# Logarithmic

logarithmic_corrected = exposure.adjust_log(img, 1)

# Display results

fig = plt.figure(figsize=(8, 5))

axes = np.zeros((2, 3), dtype=np.object)

axes[0, 0] = plt.subplot(2, 3, 1, adjustable='box-forced')

axes[0, 1] = plt.subplot(2, 3, 2, sharex=axes[0, 0], sharey=axes[0, 0],

adjustable='box-forced')

axes[0, 2] = plt.subplot(2, 3, 3, sharex=axes[0, 0], sharey=axes[0, 0],

adjustable='box-forced')

axes[1, 0] = plt.subplot(2, 3, 4)

axes[1, 1] = plt.subplot(2, 3, 5)

axes[1, 2] = plt.subplot(2, 3, 6)

ax_img, ax_hist, ax_cdf = plot_img_and_hist(img, axes[:, 0])

ax_img.set_title('Low contrast image')

y_min, y_max = ax_hist.get_ylim()

ax_hist.set_ylabel('Number of pixels')

ax_hist.set_yticks(np.linspace(0, y_max, 5))

ax_img, ax_hist, ax_cdf = plot_img_and_hist(gamma_corrected, axes[:, 1])

ax_img.set_title('Gamma correction')

ax_img, ax_hist, ax_cdf = plot_img_and_hist(logarithmic_corrected, axes[:, 2])

ax_img.set_title('Logarithmic correction')

ax_cdf.set_ylabel('Fraction of total intensity')

ax_cdf.set_yticks(np.linspace(0, 1, 5))

# prevent overlap of y-axis labels

fig.tight_layout()

plt.show()

總結(jié)

以上是生活随笔為你收集整理的python gamma函数_python gamma矫正的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。