# Photoshop图像处理算法—对比度调整（老版功能）

xingyanxiao 分享于

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);

endimg(:,:,1)=R;img(:,:,2)=G;img(:,:,3)=B;figure(2);imshow(uint8(img));</span><strong sty

le="font-size: 18px;"></strong> 2）C程序，此处只贴上关键处理部分，已经把图像变成了数组来处理。 <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> 3、实验结果，同photoshop处理结果 图1 原图 图2 参数为50结果 图3 参数为-50结果

×
• 登录
• 注册

×