标签:photoshop 图像处理 算法 颜色空间 色阶调整
前言:之前在公司做项目的用到photoshop颜色空间的一些相关方法,在此总结一下。下面原理部分是从我的总结文档里截取来的。需要复制的童鞋自己手写一下~
2、程序部分
1)Matlab实验程序。
clc;clear;close all;
Image=imread('Fotor_LomoOrg.bmp');
figure(1);
imshow(Image);
R=double(Image(:,:,1));
G=double(Image(:,:,2));
B=double(Image(:,:,3));
%调整参数
HighLight=238;
Shadow=159;
Midtones=0.51;
Diff=HighLight-Shadow;
rDiff=R-Shadow;
gDiff=G-Shadow;
bDiff=B-Shadow;
rDiff(rDiff<0)=0;
gDiff(gDiff<0)=0;
bDiff(bDiff<0)=0;
R=(rDiff/Diff).^(1/Midtones)*255;
G=(gDiff/Diff).^(1/Midtones)*255;
B=(bDiff/Diff).^(1/Midtones)*255;
R(R>255)=255;
G(G>255)=255;
B(B>255)=255;
img(:,:,1)=uint8(R);
img(:,:,2)=uint8(G);
img(:,:,3)=uint8(B);
figure(2);
imshow(img);
</span>
void LevelAdjustRGB(unsigned char *pSrc, unsigned char *pDest, int nWidth, int nHeight,int nShadow,int nHighLight,double dMidtone)
{
//局部变量声明
int i = 0;
int nLength = nWidth * nHeight;
double dDiff = nHighLight-nShadow;
int *nRgbDiff = new int[3 * nLength];
for(i = 0;i < 3 * nLength; i++)
{
nRgbDiff[i] = pSrc[i] - nShadow;
if(nRgbDiff[i] < 0)
{
nRgbDiff[i] = 0;
}
//此处必须用int作为中间变量 不能用char 会有数据截断
int nTemp = static_cast<int>(pow((nRgbDiff[i] / dDiff),1 / dMidtone) * 255);
pDest[i] = CLIP8(nTemp);
}
//释放空间
if(!nRgbDiff)
{
delete []nRgbDiff;
nRgbDiff = NULL;
}
}</span>#define CLIP8(a) (((a) & 0xFFFFFF00) ? (((a) < 0) ? 0 : 255 ) : (a)) ///<判断8位数据范围
3、实验结果,同photoshop处理结果
图1 原图
图2 nShadow=159
nHighLight=238 dMidtone=0.51结果
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:photoshop 图像处理 算法 颜色空间 色阶调整
原文地址:http://blog.csdn.net/xingyanxiao/article/details/48034857