标签:图像处理 算法 颜色空间 对比度调整 photoshop
前言:之前在公司做项目的用到photoshop颜色空间的一些相关方法,在此总结一下。下面原理部分是从我的总结文档里截取来的。需要复制的童鞋自己手写一下~
2、程序部分
1)Matlab实验程序
<span style="font-size:18px;">clc;clear;close all; Image=imread('Fotor_LomoOrg.bmp'); figure(1); imshow(Image); Image=double(Image); R=Image(:,:,1); G=Image(:,:,2); B=Image(:,:,3); Average=127; %调整参数[-100,100] Contrast=50; Contrast=Contrast/100*255; Percent=Contrast/255; if(Contrast>0) R = Average + (R - Average) * 1 / (1 - Percent) ; G = Average + (G - Average) * 1 / (1 - Percent) ; B = Average + (B - Average) * 1 / (1 - Percent) ; else R= Average + (R - Average) * (1 + Percent); G= Average + (G - Average) * (1 + Percent); B= Average + (B - Average) * (1 + Percent); end img(:,:,1)=R; img(:,:,2)=G; img(:,:,3)=B; figure(2); imshow(uint8(img));</span><strong style="font-size: 18px;"> </strong>
<span style="font-size:18px;">void ContrastAdjustRGB(unsigned char *pSrc, unsigned char *pDest, int nWidth, int nHeight,int nParameter) { //局部变量声明 int nAverage = 127; int i = 0; int nLength = nWidth * nHeight; double dTemp; //将参数范围由[-100,100]变换到[-1,1] double dPercent =static_cast<double>(nParameter) / 100; if(nParameter >= 0) { for(i = 0;i < 3 * nLength;i++) { dTemp=nAverage + (pSrc[i] - nAverage) * 1/(1 - dPercent); pDest[i] = CLIP8(static_cast<int>(dTemp)); } } else { for(i = 0;i < 3 * nLength;i++) { pDest[i] = nAverage + (pSrc[i] - nAverage) * (1 + dPercent); } } }</span>
图1 原图
图2
参数为50结果
图3
参数为-50结果
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:图像处理 算法 颜色空间 对比度调整 photoshop
原文地址:http://blog.csdn.net/xingyanxiao/article/details/48035237