matlab公共函数之保存YUV数据
生活随笔
收集整理的這篇文章主要介紹了
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: hudalikm@163.com % Version: V1.0function flag = saveYUVData(filename,Y,U,V,format) flag = 1;[height,width] = size(Y);fid=fopen(filename,'w+'); if fid <= 0flag = -1;disp('cannot open file!')return; endimgY = Y'; imgU = U'; imgV = V'; imgYUV = Y'; switch formatcase '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(:);otherwisedisp('not support!') endfwrite(fid,imgYUV,'uint8');fclose(fid);end?
轉載于:https://www.cnblogs.com/Keven-Lee/p/7419859.html
總結
以上是生活随笔為你收集整理的matlab公共函数之保存YUV数据的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 关于javascript中私有作用域的预
- 下一篇: ABP框架插件开发