首页 > 其他 > 详细

生成彩条的MATLAB代码

时间:2016-02-28 16:37:07      阅读:177      评论:0      收藏:0      [点我收藏+]
clc;close all;clear
%read image
% RGBimga = imread(bmpinput_1080p.bmp);
RGBimga = imread(bmpinput_720p.bmp);
RGBimgb = RGBimga*0;
RGBimga = RGBimgb;

[Hs Vs Dim] = size(RGBimga);
gate = Vs/6; %6个竖彩条间隔
i = 1;
RGBimga(:,(i-1)*gate+1:i*gate,1) = 255;    %R
i = i+1;
RGBimga(:,(i-1)*gate+1:i*gate,2) = 255;    %G
i = i+1;
RGBimga(:,(i-1)*gate+1:i*gate,3) = 255;    %B
i = i+1;
RGBimga(:,(i-1)*gate+1:i*gate,1) = 255;    %R
i = i+1;
RGBimga(:,(i-1)*gate+1:i*gate,2) = 255;    %G
i = i+1;
RGBimga(:,(i-1)*gate+1:i*gate,3) = 255;    %B
figure;imshow(RGBimga);

[Hs Vs Dim] = size(RGBimgb);
gate = Hs/3; %3个横彩条间隔
RGBimgb(1:gate,:,1) = 255;                 %R
RGBimgb(gate+1:2*gate,:,2) = 255;     %G
RGBimgb(2*gate+1:3*gate,:,3) = 255;  %B
figure;imshow(RGBimgb);

RGBimga = uint8(RGBimga);
RGBimgb = uint8(RGBimgb);

yuvima = rgb2yuv(RGBimga);  %rgb2ycbcr
% yuvima = rgb2ycbcr(RGBimga);
figure;imshow(uint8(yuvima));
yuvimb = rgb2yuv(RGBimgb);
figure;imshow(yuvimb);

YUVimg = yuvima;
yuvimout = zeros(1,Hs*Vs*Dim);   %整理数据
yuvimout(1:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,1),1,Hs*Vs); %%Y
yuvimout(2:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,2),1,Hs*Vs); %%U
yuvimout(3:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,3),1,Hs*Vs); %%V
fid= fopen(imga_720p.yuv,wb);   %整理后可快速输出到文件
    fwrite(fid,yuvimout,uint8);
fclose(fid);
fid= fopen(imga_720p.txt,w);
    fprintf(fid,%02x\n,yuvimout);
fclose(fid);

YUVimg = yuvimb;
yuvimout = zeros(1,Hs*Vs*Dim);
yuvimout(1:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,1),1,Hs*Vs);
yuvimout(2:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,2),1,Hs*Vs);
yuvimout(3:3:Hs*Vs*Dim) = reshape(YUVimg(:,:,3),1,Hs*Vs);
fid= fopen(imgb_720p.yuv,wb);
    fwrite(fid,yuvimout,uint8);
fclose(fid);
fid= fopen(imgb_720p.txt,w);
    fprintf(fid,%02x\n,yuvimout);
fclose(fid);

 

生成彩条的MATLAB代码

原文:http://www.cnblogs.com/hythink/p/5224901.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!