前言:之前在公司做项目的用到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>
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结果
版权声明:本文为博主原创文章,未经博主允许不得转载。
时间: 2024-12-28 17:11:11