matlab实现PS算法之渐变

%{
色调分离的原理就是将R, G, B每个通道 0-255 
的色调区间进行强制划分到给定的区间里去,
所以色调会合并,最终的图像看起来颜色就是一块一块的。
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
Image = imread(imgaepath);
figure,imshow(Image);

size_info=size(Image);  
height=size_info(1);  
width=size_info(2);  

% 图像转为灰度图
Gray_Img=rgb2gray(Image);


% 建立 lookup table
row=50;
col=256;
Color(:,:,1)=rand(row,col);
Color(:,:,2)=rand(row,col);
Color(:,:,3)=rand(row,col);

for index=1:col
        val=index/col;
        % color 1
% % %         Color(:,index,1)=3*(val);
% % %         Color(:,index,2)=3*(val)-1;
% % %         Color(:,index,3)=3*(val)-1;
       % color 2
        Color(:,index,1)=sin(val);
        Color(:,index,2)=sin(val/2);
        Color(:,index,3)=sin(val/3);
        % color 3
% % %         Color(:,index,1)=val;
% % %         Color(:,index,2)=val;
% % %         Color(:,index,3)=0;
end

figure, imshow(Color);

% 以灰度值为索引,映射得到相应的颜色值。
Image_new=double(Image);

for ii=1:height
    for jj=1:width
        index=Gray_Img(ii,jj);
        Image_new(ii,jj,:)=Color(1, index+1, :);
    end
end


figure, imshow(Image_new);



%{
先设置一个遮罩层,然后用遮罩层与原图进
行相乘,遮罩层不同,图像最后呈现的渐变效
果也不一样。
%}
clear,clc;
[filename,pathname] = uigetfile('*.jpg;*.bmp','选择图片','E:\pictures\For_Project\Matlab');
imgaepath = strcat(pathname,filename);
Image = imread(imgaepath);
figure,imshow(Image);

Image=double(Image)/255;
size_info=size(Image);  
height=size_info(1);  
width=size_info(2);  

% 设置遮罩层
Map=zeros(height, width);
for i=1:width
    Map(:, i)=(1-abs(i*2/width-1))*0.8;
end

% 遮罩层与原图相乘
Img_new=Image;
for kk=1:3
      Img_new(:,:,kk)=Image(:,:,kk).*Map;
end
figure, imshow(Img_new);


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值