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

首頁 > 編程 > Python > 正文

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

2020-01-04 16:08:25
字體:
來源:轉載
供稿:網友

本文實例講述了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('m.survivalescaperooms.com')plt.imshow(img/255.0)plt.axis('off')plt.figure(2)plt.title('m.survivalescaperooms.com')plt.imshow(img_out)plt.axis('off')plt.show()

運行效果圖

Python,PS,圖像調整,對比度調整

Python,PS,圖像調整,對比度調整

 

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


注:相關教程知識閱讀請移步到python教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 资兴市| 四平市| 黄山市| 子长县| 麦盖提县| 沂南县| 五大连池市| 潞城市| 新绛县| 朔州市| 志丹县| 镇雄县| 津市市| 阳高县| 南陵县| 锦州市| 尚义县| 察隅县| 巨野县| 宁安市| 江口县| 伊金霍洛旗| 富蕴县| 临海市| 荥经县| 会宁县| 峨眉山市| 五华县| 塔城市| 墨玉县| 泰顺县| 高尔夫| 双辽市| 合水县| 屏东县| 宿松县| 义乌市| 岳阳县| 清远市| 长寿区| 仁布县|