前言:之前在公司做项目的用到photoshop颜色空间的一些相关方法,在此总结一下。下面原理部分是从我的总结文档里截取来的。需要复制的童鞋自己手写一下~
2、程序部分
1)Matlab实验程序。
clc;clear;close all;
Image=imread('IMG_0950_cut.jpg');
figure(1);
imshow(Image);
R=double(Image(:,:,1));
G=double(Image(:,:,2));
B=double(Image(:,:,3));
%输入调整参数value [-100,100]之间,与photoshop一致
value=-50;
%放缩到[-255,255]之间 对应物理意义的
value=value*255/100;
if(value>=0)
R = R + (255 - R) * value / 255;
G = G + (255 - G) * value / 255;
B = B + (255 - B) * value / 255;
else
R = R + R * value / 255;
G = G + G * value / 255;
B = B + B * value / 255;
end
img(:,:,1)=uint8(R);
img(:,:,2)=uint8(G);
img(:,:,3)=uint8(B);
figure(2);
imshow(img);
void BrightAdjustRGB(unsigned char *pSrc, unsigned char *pDest, int nWidth, int nHeight,int nParameter)
{
//参数范围有效性判断
if (nParameter < -100 || nParameter > 100)
return;
//局部变量声明
int i = 0;
int t = 0;
int nLength = nWidth * nHeight;
//缩放明度调整参数
nParameter = nParameter * 255 / 100;
//得到结果
if(nParameter >= 0)
{
for (i = 0; i < nLength; i++)
{
t = i * 3;
pDest[t] = pSrc[t] + (255 - pSrc[t]) * nParameter / 255;
pDest[t + 1] = pSrc[t + 1]+(255 - pSrc[t + 1]) * nParameter / 255;
pDest[t + 2] = pSrc[t + 2]+(255 - pSrc[t + 2]) * nParameter / 255;
}
}
else
{
for (i = 0; i < nLength; i++)
{
t = i * 3;
pDest[t] = pSrc[t] + pSrc[t] * nParameter / 255;
pDest[t + 1] = pSrc[t + 1] + pSrc[t + 1] * nParameter / 255;
pDest[t + 2] = pSrc[t + 2] + pSrc[t + 2] * nParameter / 255;
}
}
}
图1 原图
图2 参数为-50结果
图3 参数为50结果
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/xingyanxiao/article/details/48028415