生成彩条的MATLAB代码
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'); %% 写txt文件 fprintf(fid,'%02x\n',yuvimout); fclose(fid);
~~~~~~~~~~~~~~~~ 博文多为个人学习中的笔记,不保证完全正确;
参考摘录了诸多书籍,文档,仅用于学习交流
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~