matlab公共函数之保存YUV数据
Posted hudalikm
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了matlab公共函数之保存YUV数据相关的知识,希望对你有一定的参考价值。
matlab保存图像为YUV格式的脚本函数
% function flag = saveYUVData(filename,Y,U,V,format) % input params. % filename: saving data path % Y: Y data, res. width x height % U: U data, res. width/2 x height/2 for NV12, NV21 and YUV420P, width x height for YUV444 % V: V data, res. width/2 x height/2 for NV12, NV21 and YUV420P, width x height for YUV444 % format: must be NV12, NV21, YUV420P or YUV444 % % output % flag: if successed, flag = 1, otherwise flag = 0 % % % Author: KevenLee % Contact: [email protected] % Version: V1.0 function flag = saveYUVData(filename,Y,U,V,format) flag = 1; [height,width] = size(Y); fid=fopen(filename,‘w+‘); if fid <= 0 flag = -1; disp(‘cannot open file!‘) return; end imgY = Y‘; imgU = U‘; imgV = V‘; imgYUV = Y‘; switch format case ‘NV21‘ imgNV21UV = zeros(width,height/2); imgNV21UV(1:2:end,:) = imgV; imgNV21UV(2:2:end,:) = imgU; imgYUV = zeros(1,width*height*1.5); imgYUV(1:1:width*height) = imgY(:); imgYUV(width*height+1:end) = imgNV21UV(:); case ‘NV12‘ imgNV21UV = zeros(width,height/2); imgNV21UV(1:2:end,:) = imgU; imgNV21UV(2:2:end,:) = imgV; imgYUV = zeros(1,width*height*1.5); imgYUV(1:1:width*height) = imgY(:); imgYUV(width*height+1:end) = imgNV21UV(:); case ‘YUV420P‘ imgUV = zeros(width,height/2); imgUV(1:1:round(width/2),:) = imgU; imgUV(round(width/2)+1:1:end,:) = imgV; imgYUV = zeros(1,width*height*1.5); imgYUV(1:1:width*height) = imgY(:); imgYUV(width*height+1:end) = imgUV(:); case ‘YUV444‘ imgYUV = zeros(1,width*height*3); imgYUV(1:1:width*height) = imgY(:); imgYUV(width*height+1:1:width*height*2) = imgU(:); imgYUV(width*height*2+1:1:width*height*3) = imgV(:); otherwise disp(‘not support!‘) end fwrite(fid,imgYUV,‘uint8‘); fclose(fid); end
以上是关于matlab公共函数之保存YUV数据的主要内容,如果未能解决你的问题,请参考以下文章