# python数字图像处理（8）：对比度与亮度调整

1、gamma调整

gamma参数默认为1，原像不发生变化 。

from skimage import data, exposure, img_as_float
import matplotlib.pyplot as plt
image = img_as_float(data.moon())

plt.subplot(131)
plt.title('origin image')
plt.imshow(image,plt.cm.gray)
plt.axis('off')

plt.subplot(132)
plt.title('gamma=2')
plt.imshow(gam1,plt.cm.gray)
plt.axis('off')

plt.subplot(133)
plt.title('gamma=0.5')
plt.imshow(gam2,plt.cm.gray)
plt.axis('off')

plt.show()

2、log对数调整

from skimage import data, exposure, img_as_float
import matplotlib.pyplot as plt
image = img_as_float(data.moon())

plt.subplot(121)
plt.title('origin image')
plt.imshow(image,plt.cm.gray)
plt.axis('off')

plt.subplot(122)
plt.title('log')
plt.imshow(gam1,plt.cm.gray)
plt.axis('off')

plt.show()

3、判断图像对比度是否偏低

from skimage import data, exposure
image =data.moon()
result=exposure.is_low_contrast(image)
print(result)

4、调整强度

in_range 表示输入图片的强度范围，默认为'image', 表示用图像的最大/最小像素值作为范围

out_range 表示输出图片的强度范围，默认为'dype', 表示用图像的类型的最大/最小值作为范围

import numpy as np
from skimage import exposure
image = np.array([51, 102, 153], dtype=np.uint8)
mat=exposure.rescale_intensity(image)
print(mat)

import numpy as np
image = np.array([51, 102, 153], dtype=np.uint8)
print(image*1.0)

import numpy as np
from skimage import exposure
image = np.array([51, 102, 153], dtype=np.uint8)
tmp=image*1.0
mat=exposure.rescale_intensity(tmp)
print(mat)

import numpy as np
from skimage import exposure
image = np.array([51, 102, 153], dtype=np.uint8)
tmp=image*1.0
mat=exposure.rescale_intensity(tmp,in_range=(0,255))
print(mat)

mat=exposure.rescale_intensity(tmp,in_range=(0,102))
print(mat)

import numpy as np
from skimage import exposure
image = np.array([-10, 0, 10], dtype=np.int8)
mat=exposure.rescale_intensity(image, out_range=(0, 127))
print(mat)


posted @ 2016-01-12 15:12 denny402 阅读(...) 评论(...) 编辑 收藏