博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
matlab公共函数之保存YUV数据
阅读量:6441 次
发布时间:2019-06-23

本文共 1961 字,大约阅读时间需要 6 分钟。

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 <= 0    flag = -1;    disp('cannot open file!')    return;endimgY = 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!')endfwrite(fid,imgYUV,'uint8');fclose(fid);end

 

转载于:https://www.cnblogs.com/Keven-Lee/p/7419859.html

你可能感兴趣的文章
怎样避免应用冷启动
查看>>
把vux中的@font-face为base64格式的字体信息解码成可用的字体文件
查看>>
vue sync
查看>>
CentOS6下OpenLDAP+PhpLdapAdmin基本安装及主从/主主高可用模式部署记录
查看>>
Wix 安装部署教程(十一) ---QuickWix
查看>>
Spring @Value注解问题
查看>>
P1886 滑动窗口
查看>>
实施vertex compression所遇到的各种问题和解决办法
查看>>
ubuntu 12.04 rails server 时候报错 execjs
查看>>
linux下文件压缩与解压操作
查看>>
使用树莓派实现微信远程监控
查看>>
在 SQL Server 中查询EXCEL 表中的数据遇到的各种问题
查看>>
linux sed命令
查看>>
浅谈当下网页设计趋势
查看>>
TCP 滑动窗口和 拥塞窗口
查看>>
VS2008调试程序时出现"XXX mutex not created."
查看>>
解决Java连接MySQL存储过程返回参数值为乱码问题
查看>>
c++ 字符检测 TCharacter
查看>>
MalformedObjectNameException: Invalid character '' in value part of property
查看>>
Hadoop格式化HDFS报错java.net.UnknownHostException: localhost.localdomain: localhost.localdomain
查看>>