from skimage import data,exposure,img_as_float
from PIL import Image,ImageFilter
使用pillow.Image加载图片之后需要转换格式才能应用函数:
figure=Image.open(path) #读取图片
image=img_as_float(figure) #转换成指定格式
exposure.adjust_gamma(image,系数) 当系数大于一是图像变暗,图像小于一时图像变亮
image=img_as_float(figure)
figure_adjust_low=exposure.adjust_gamma(image,2) #图片调暗
figure_adjust_high=exposure.adjust_gamma(image,0.5) #图片调亮
plt.figure()
plt.subplot(311)
plt.imshow(figure_adjust_low)
plt.subplot(312)
plt.imshow(figure_adjust_high)
plt.subplot(313)
plt.imshow(figure)
plt.show()
效果如下所示:
import cv2
figure=Image.open(path)
figure=np.array(figure) #opencv无法处理Image的格式需要转换为numpy格式
figure_pre=cv2.cvtColor(figure,cv2.COLOR_RGB2HSV)
效果如下:
figure=Image.open(path)
figure=np.array(figure)
figure_pre=cv2.cvtColor(figure,cv2.COLOR_RGB2HLS)
plt.figure()
plt.subplot(211)
plt.imshow(figure)
plt.subplot(212)
plt.imshow(figure_pre)
plt.show()
效果如下:
figure=Image.open(path)
figure=np.array(figure)
figure_pre=cv2.cvtColor(figure,cv2.COLOR_RGB2LUV)
效果如下:
其中colorspace可以是下述其中之一
['hsv', 'xyz', 'rgb cie', 'yiq', 'ydbdr', 'rgb', 'yuv', 'ypbpr', 'ycbcr']
image=np.array(figure)
figure_adjust=color.convert_colorspace(image,'RGB','HSV') #其中RGB为初始图像空间,HSV为需
#要转换的空间 如:HSV,GREY,LAB
plt.figure()
plt.subplot(211)
plt.imshow(figure_adjust)
plt.subplot(212)
plt.imshow(figure)
plt.show()
效果如下:
from skimage import color
image=np.array(figure)
figure_adjust=color.rgb2gray(image) #转换函数
plt.figure()
plt.subplot(211)
plt.imshow(figure_adjust)
plt.subplot(212)
plt.imshow(figure)
plt.show()
效果如下:
image=np.array(figure)
figure_adjust=color.rgb2hsv(image) #转换公式
plt.figure()
plt.subplot(211)
plt.imshow(figure_adjust)
plt.subplot(212)
plt.imshow(figure)
plt.show()
image=np.array(figure)
figure_adjust=color.rgb2lab(image) #转换公式
plt.figure()
plt.subplot(211)
plt.imshow(figure_adjust)
plt.subplot(212)
plt.imshow(figure)
plt.show()
效果如下: