RGB色彩空间中波形图、直方图、矢量图绘制

波形图

    代码如下:      

WaveForm_R=zeros(300,n,3); 
WaveForm_G=zeros(300,n,3); 
WaveForm_B=zeros(300,n,3); 

for i=1:m
   for j=1:n 
      WaveForm_R(uint8(R(i,j)+1)+50,j,1)=1;
      WaveForm_G(uint8(G(i,j)+1)+50,j,2)=1;
      WaveForm_B(uint8(B(i,j)+1)+50,j,3)=1;
   end
end

subplot(2,2,1),imshow(imresize(src_img,[300,n]));title('原图');
subplot(2,2,2),imshow(WaveForm_R);title('WaveForm R');
subplot(2,2,3),imshow(WaveForm_G);title('WaveForm G');
subplot(2,2,4),imshow(WaveForm_B);title('WaveForm B');

  效果如下:

        

 直方图

        代码如下:

        

CountR=zeros(256,1); 
CountG=zeros(256,1); 
CountB=zeros(256,1); 

for i=1:m
   for j=1:n 
      CountR(uint8(R(i,j)+1)) = CountR(uint8(R(i,j)+1))+1;
      CountG(uint8(G(i,j)+1)) = CountG(uint8(G(i,j)+1))+1;
      CountB(uint8(B(i,j)+1)) = CountB(uint8(B(i,j)+1))+1;
   end
end

MaxCountR=max(CountR);
MaxCountG=max(CountG);
MaxCountB=max(CountB);

HistR=CountR./MaxCountR;
HistG=CountG./MaxCountG;
HistB=CountB./MaxCountB;

x=1:256;
subplot(2,2,1),imshow(src_img);title('原图');
subplot(2,2,2),stem(x,HistR,'R');title('红色分量');
subplot(2,2,3),stem(x,HistG,'G');title('绿色分量');
subplot(2,2,4),stem(x,HistB,'B');title('蓝色分量');

效果如下:

        

矢量图

代码如下:

        

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读取新的图像
src_img=imread('brightness-slider.png'); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%取出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); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
RGB2YUV=[0.2990 0.5870 0.1140;
         -0.1687 -0.3313 0.500;
         0.5000 -0.4187 -0.0813];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%转换成YCbCr形式
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%读取向量图
bkg_img=imread('graticule.png');
[h w d]=size(bkg_img);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Y=zeros(m,n); 
U=zeros(m,n); 
V=zeros(m,n);
for i=1:m
   for j=1:n 
        temp=RGB2YUV*[R(i,j) G(i,j) B(i,j)]';
        Y(i,j)=temp(1);
        U(i,j)=temp(2);
        V(i,j)=temp(3);
        bkg_img(uint8(w/2-V(i,j)),uint8(U(i,j)+h/2),1)=uint8(R(i,j));
        bkg_img(uint8(w/2-V(i,j)),uint8(U(i,j)+h/2),2)=uint8(G(i,j));
        bkg_img(uint8(w/2-V(i,j)),uint8(U(i,j)+h/2),3)=uint8(B(i,j));
   end
end

subplot(1,2,1),imshow(src_img);
subplot(1,2,2),imshow(bkg_img);

 效果如下:

        

 

 

        

欢迎点赞收藏

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值