YUV色彩空间中高光和低光调节

文章介绍了图像处理中的高光和低光调节技术,区别于普通的亮度增强,这种调节旨在分别改变图像的亮部和暗部。文中提供了MATLAB代码示例,包括普通亮度调节和高低光调节,并展示了调光系数的生成过程,涉及色彩空间转换,如RGB到YCbCr。
摘要由CSDN通过智能技术生成

前言

        高光和低光调节属于亮度调节范畴,但是和通过伽马变换来时实现的亮度增强不是一个意思。高低光的调节是指,增强亮部并降低暗部,或者降低亮部并增强暗部。

普通亮度调节

 代码如下:        


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Bright1 =50;
Bright2 =-50;

for i=1:m
   for j=1:n 
       Y1(i,j) =  Y1(i,j)+ Bright1;
   end
end
for i=1:m
   for j=1:n 
       Y2(i,j) =  Y2(i,j)+ Bright2;
   end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,2,1),imshow(src_img);title('原图');
subplot(2,2,2),imshow(dst_img1);title('亮度增强50');
subplot(2,2,3),imshow(src_img);title('原图');
subplot(2,2,4),imshow(dst_img2);title('亮度降低50');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 效果如下:

        

 高低光调节

 代码如下:        

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:m
   for j=1:n 
       Y1(i,j) = z(uint8(Y1(i,j)+1))*255 ;
   end
end
for i=1:m
   for j=1:n 
         Y2(i,j) = y(uint8(Y2(i,j))+1)*255;
   end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
subplot(2,2,1),imshow(src_img);title('原图');
subplot(2,2,2),imshow(dst_img1);title('亮部削弱+暗部增强');
subplot(2,2,3),imshow(src_img);title('原图');
subplot(2,2,4),imshow(dst_img2);title('亮部增强+暗部削弱');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

  效果如下:

        

 

调光系数生成 

代码如下:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x=0:1/256:1;
p=0.5;
r=2;
for i=1:length(x)
    if x(i) <p
        y1=(p)^r;
        y(i)= x(i)^r/y1/2;            
        z1=(p)^(1/r);
        z(i)= x(i)^(1/r)/z1/2;        
    elseif(x(i)==p)
        y(i)= p;
        z(i)= p;
    else
        y(i)= 1-y(length(x)-i+1);
        z(i)= 1-z(length(x)-i+1);
    end
end
plot(x,x);hold on
plot(x,y);hold on
plot(x,z);hold on
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

曲线如下:

   

 实验中其他部分代码如下:        

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读取新的图像
src_img=imread('./image/img2.jpg'); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%取出RGB分量
[m n dim]=size(src_img);
R=src_img(:,:,1);
G=src_img(:,:,2);
B=src_img(:,:,3);
R=double(R);
G=double(G);
B=double(B); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%色彩空间定义:RGB [0,255];YCbCr [0,255]
rgb2yuv=[0.2126    0.7152   0.0722;
        -0.1146  -0.3854   0.5000;
         0.5000   -0.4542   -0.0458];%0~255
yuv2rgb =inv(rgb2yuv);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%转换成YCbCr形式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y1=zeros(m,n); 
Cb1=zeros(m,n); 
Cr1=zeros(m,n);
for i=1:m
   for j=1:n 
        tmp=rgb2yuv*[R(i,j) G(i,j) B(i,j)]';
        Y1(i,j)=tmp(1);
        Cb1(i,j)=tmp(2)+128;
        Cr1(i,j)=tmp(3)+128;
   end
end
Y2=zeros(m,n); 
Cb2=zeros(m,n); 
Cr2=zeros(m,n);
for i=1:m
   for j=1:n 
        tmp=rgb2yuv*[R(i,j) G(i,j) B(i,j)]';
        Y2(i,j)=tmp(1);
        Cb2(i,j)=tmp(2)+128;
        Cr2(i,j)=tmp(3)+128;
   end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%转换成rgb形式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:m
   for j=1:n 
        tmp=yuv2rgb*[Y1(i,j) Cb1(i,j)-128 Cr1(i,j)-128]';
        R1(i,j)=tmp(1);
        G1(i,j)=tmp(2);
        B1(i,j)=tmp(3);
   end
end

for i=1:m
   for j=1:n 
        tmp=yuv2rgb*[Y2(i,j) Cb2(i,j)-128 Cr2(i,j)-128]';
        R2(i,j)=tmp(1);
        G2(i,j)=tmp(2);
        B2(i,j)=tmp(3);
   end
end

R1=uint8(R1);
G1=uint8(G1);
B1=uint8(B1); 
dst_img1(:,:,1)=R1;
dst_img1(:,:,2)=G1;
dst_img1(:,:,3)=B1;

R2=uint8(R2);
G2=uint8(G2);
B2=uint8(B2); 
dst_img2(:,:,1)=R2;
dst_img2(:,:,2)=G2;
dst_img2(:,:,3)=B2;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值