python图像处理:对比度与亮度调整

上传人:博****1 文档编号:507929845 上传时间:2023-08-10 格式:DOC 页数:3 大小:135KB
返回 下载 相关 举报
python图像处理:对比度与亮度调整_第1页
第1页 / 共3页
python图像处理:对比度与亮度调整_第2页
第2页 / 共3页
python图像处理:对比度与亮度调整_第3页
第3页 / 共3页
亲,该文档总共3页,全部预览完了,如果喜欢就下载吧!
资源描述

《python图像处理:对比度与亮度调整》由会员分享,可在线阅读,更多相关《python图像处理:对比度与亮度调整(3页珍藏版)》请在金锄头文库上搜索。

1、python图像处理(7):对比度与亮度调整图像亮度与对比度的调整,是放在skimage包的exposure模块里面1、gamma调整原理:I=I对原图像的像素,进行幂运算,得到新的像素值。公式中的g就是gamma值。如果gamma1,新图像比原图像暗如果gamma1,新图像比原图像亮函数格式为:posure.imaadgej,guasmtm_ag=a1)fromskimiamgpoerdtata,exposure,impormtatplotli.pyplotaspltfloat(data.moonexposure.adjust_调暗exposure.adjust调亮plt.figaudrje

2、u(st_gamma参数默认为1,原像不发生变化。oat这个刚好和gamma相反romskimiamgpoerdttpompormtatplotli.pyplotaspltfloat(data.moon(po对数调整plt.figaudrjeu(st_plt.su1bp2l)1ot(plt.ti0nplt.imshow(implt.cm.grayplt.axoi)fsf(plt.su1bp2l)2ot(plt.tilt)oeg(plt.imshow(gam1,plt.cm.gray)原理:l=log(l)oatplpppt.t.t.t.totlrxoi)fp3l)1hoot(in)ige,pl

3、t.c.graypt.p3l)ot(pt.tgtlpt.ho1,plt.cmgray)pt.xoi)fpt.p3l)ot(pt.tgtlpt.ho2,plt.cmgray)pt.xoi)fplt.hoplt.axis(off)plt.show()originimagelog3、判断图像对比度是否偏低函数:is_low_contrast(img)返回一个bool型值fromskimageimportdata,exposureimage=data.moon()result=exposure.is_low_contrast(image)print(result)输出为False4、调整强度函数:sk

4、image.exposure.rescale_intensity(image,in_range=imageout_range=dtype)in_range表示输入图片的强度范围,默认为image,表示用图像的最大/最小像素值作为范围out_range表示输出图片的强度范围,默认为dype,表示用图像的类型的最大/最小值作为范围默认情况下,输入图片的min,max范围被拉伸到dtype.min,dtype.max,如果dtype=uint8,那么dtype.min=O,dtype.max=255importnumpyasnpfromskimageimportexposureimage=np.ar

5、ray(51,102,153,dtype=np.uint8)mat=exposure.rescale_intensity(image)print(mat)输出为0127255即像素最小值由51变为0,最大值曲53变为255,整体进行了拉伸,但是数据类型没有变,还是nt8前面我们讲过,可以通过mg_as_float()函数将unit8类型转换为float型,实际上还有更简单的方法,就是乘以.0importnumpyasnpimage=np.array(51,102,153,dtype=np.uint8)print(image*1.0)即由51,102,153变成了51.102.153.而floa

6、t类型的范围是0,1,因此对float进行rescale_intensity调整后,范围变为0,1而不是0,255importnumpyasnpfromskimageimportexposureimage=np.array(51,102,153,dtype=np.uint8)tmp=image*1.0mat=exposure.rescale_intensity(tmp)print(mat)结果为0.0.51.如果原始像素值不想被拉伸,只是等比例缩小,就使用grange参数,如:importnumpyasnpfromskimageimportexposureimage=np.array(51,1

7、02,153,dtype=np.uint8)tmp=image*1.0mat=exposure.rescale_intensity(tmp,in_range=(0,255)print(mat)输出为:0.20.40.6,即原像素值除以255如果参数n_range的main,max范围要比原始像素值的范围min,max大或者小,那就进行裁剪,女如mat=exposure.rescale_intensity(tmp,in_range=(0,10)2)print(mat)输出0.51.1.,即原像素值除以102,超出1的变为1如果一个数组里面有负数,现在想调整到正数,就使Jt_range参数。如:importnumpyasnpfromskimageimportexposureimage=np.array(-10,0,10,dtype=np.int8)mat=exposure.rescale_intensity(image,out_range=(0,127)print(mat)输出063127

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 解决方案

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号