国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實現PS圖像調整之對比度調整功能示例

2020-02-22 23:00:40
字體:
來源:轉載
供稿:網友

本文實例講述了Python實現PS圖像調整之對比度調整功能。分享給大家供大家參考,具體如下:

這里用 Python 實現 PS 里的圖像調整–對比度調整。具體的算法原理如下:

(1)、nRGB = RGB + (RGB - Threshold) * Contrast / 255

公式中,nRGB表示圖像像素新的R、G、B分量,RGB表示圖像像素R、G、B分量,Threshold為給定的閾值,Contrast為處理過的對比度增量。

Photoshop對于對比度增量,是按給定值的正負分別處理的:

當增量等于-255時,是圖像對比度的下端極限,此時,圖像RGB各分量都等于閾值,圖像呈全灰色,灰度圖上只有1條線,即閾值灰度;

當增量大于-255且小于0時,直接用上面的公式計算圖像像素各分量;

當增量等于255時,是圖像對比度的上端極限,實際等于設置圖像閾值,圖像由最多八種顏色組成,灰度圖上最多8條線,即紅、黃、綠、青、藍、紫及黑與白;

當增量大于0且小于255時,則先按下面公式(2)處理增量,然后再按上面公式(1)計算對比度:

(2)、nContrast = 255 * 255 / (255 - Contrast) - 255
公式中的nContrast為處理后的對比度增量,Contrast為給定的對比度增量。

# -*- coding: utf-8 -*-#! python3import matplotlib.pyplot as pltfrom skimage import iofile_name='D:/Visual Effects/PS Algorithm/4.jpg';img=io.imread(file_name)img = img * 1.0thre = img.mean()# -100 - 100contrast = -55.0img_out = img * 1.0if contrast <= -255.0:  img_out = (img_out >= 0) + thre -1elif contrast > -255.0 and contrast < 0:  img_out = img + (img - thre) * contrast / 255.0elif contrast < 255.0 and contrast > 0:  new_con = 255.0 *255.0 / (256.0-contrast) - 255.0  img_out = img + (img - thre) * new_con / 255.0else:  mask_1 = img > thre  img_out = mask_1 * 255.0img_out = img_out / 255.0# 飽和處理mask_1 = img_out < 0mask_2 = img_out > 1img_out = img_out * (1-mask_1)img_out = img_out * (1-mask_2) + mask_2plt.figure()plt.title('www.jb51.net')plt.imshow(img/255.0)plt.axis('off')plt.figure(2)plt.title('www.jb51.net')plt.imshow(img_out)plt.axis('off')plt.show()

運行效果圖

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python圖片操作技巧總結》、《Python數據結構與算法教程》、《Python Socket編程技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》、《Python入門與進階經典教程》及《Python文件與目錄操作技巧匯總》

希望本文所述對大家Python程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 怀安县| 富源县| 农安县| 宁城县| 海兴县| 游戏| 阿瓦提县| 庄浪县| 宣化县| 丰镇市| 克东县| 福建省| 鄂尔多斯市| 和静县| 博罗县| 青冈县| 阜康市| 昭觉县| 德化县| 蒙自县| 封开县| 阳新县| 嫩江县| 措勤县| 正镶白旗| 达州市| 富源县| 稻城县| 泸溪县| 青河县| 沁源县| 化隆| 汉沽区| 屏东县| 从化市| 眉山市| 孟村| 博湖县| 黎平县| 顺义区| 海城市|