前言
图像处理中,如果要调整图像的对比度、色度、饱和度,在RGB色彩空间处理实为不变,这需要转换到HSV色彩空间中去,不够快速。因此本文提出了直接基于YUV色彩空间处理的方法。
对比度调节
代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
C1=0.5;
C2=2;
for i=1:m
for j=1:n
Y1(i,j) = Y1(i,j)*C1;
end
end
for i=1:m
for j=1:n
Y2(i,j) = Y2(i,j)*C2;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
效果如下:
色度调节
代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%调节色度
% U' = (U-128) x Cos(H) + (V-128) x Sin(H)
% V' = (V-128) x Cos(H) - (U-128) x Sin(H)
H1=120;
H1=H1/180*pi;
for i=1:m
for j=1:n
Cb1(i,j) =(Cb1(i,j)-128)*sin(H1) +(Cr1(i,j)-128)*cos(H1)+128;
Cr1(i,j) =(Cr1(i,j)-128)*sin(H1) -(Cb1(i,j)-128)*cos(H1)+128;
end
end
H2=60;
H2=H2/180*pi;
for i=1:m
for j=1:n
Cb2(i,j) =(Cb2(i,j)-128)*sin(H2) +(Cr2(i,j)-128)*cos(H2)+128;
Cr2(i,j) =(Cr2(i,j)-128)*sin(H2) -(Cb2(i,j)-128)*cos(H2)+128;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
效果如下:
饱和度调节
代码如下:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
S1=0.25;
S2=0.75;
for i=1:m
for j=1:n
Cb1(i,j) =(Cb1(i,j)-128)*S1 +128;
Cr1(i,j) =(Cr1(i,j)-128)*S1 +128;
end
end
for i=1:m
for j=1:n
Cb2(i,j) =(Cb2(i,j)-128)*S2 +128;
Cr2(i,j) =(Cr2(i,j)-128)*S2 +128;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
效果如下:
欢迎点赞收藏