[求救] 有RGB的陣列資料 要如何輸出影片
我要YUV的影片檔能在matlab上播放
所以我將YUV的陣列轉成RGB
取得RGB3個資料陣列,要如何以imshow播放?
附上程式碼
function [r,g,b] = yuvRead(vid, width, height, nFrame)
fid = fopen(vid,'r');
stream = fread(fid,'*uchar');
length = 1.5 * width * height;
y = uint8(zeros(height, width, nFrame));
u = uint8(zeros(height, width, nFrame));
v = uint8(zeros(height, width, nFrame));
r = zeros(height, width, nFrame);
g = zeros(height, width, nFrame);
b = zeros(height, width, nFrame);
for iFrame = 1:nFrame
frame = stream((iFrame-1)*length+1:iFrame*length);
yImage = reshape(frame(1:width*height), width, height)';
uImage = reshape(frame(width*height+1:1.25*width*height), width/2, height/2)';
vImage = reshape(frame(1.25*width*height+1:1.5*width*height), width/2, height/2)';
y(:,:,iFrame) = uint8(yImage);
u(1:2:height-1,1:2:width-1,iFrame)=uint8(uImage);
u(1:2:height-1,2:2:width,iFrame)=uint8(uImage);
u(2:2:height,1:2:width-1,iFrame)=uint8(uImage);
u(2:2:height,2:2:width,iFrame)=uint8(uImage);
v(1:2:height-1,1:2:width-1,iFrame)=uint8(vImage);
v(1:2:height-1,2:2:width,iFrame)=uint8(vImage);
v(2:2:height,1:2:width-1,iFrame)=uint8(vImage);
v(2:2:height,2:2:width,iFrame)=uint8(vImage);
r(:,:,iFrame) = 1 *y(:,:,iFrame) + 1.4022* (v(:,:,iFrame)-128);
g(:,:,iFrame) = 1 * y(:,:,iFrame) -0.3946 *(u(:,:,iFrame)-128) -0.5806* (v(:,:,iFrame)-128);
b(:,:,iFrame)= 1 *y(:,:,iFrame) + 1.7710 * (u(:,:,iFrame)-128) ;
r(:,:,iFrame)=uint8(round(r(:,:,iFrame)));
g(:,:,iFrame)=uint8(round(g(:,:,iFrame)));
b(:,:,iFrame)=uint8(round(b(:,:,iFrame)));
end
videoSequence = 'sampleQCIF.yuv';
width = 176;
height = 144;
nFrame = 500;
[r,g,b] = yuvRead(videoSequence, width, height ,nFrame);
figure;
c = 0;
for iFrame = 1:500
imshow(r(:,:,iFrame));
title(['frame #', num2str(iFrame)]);
end
以上的資料陣列r 是有值的,但播放的影片是白色
求解
--
Sent from my Windows
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 140.125.35.138
※ 文章網址: https://www.ptt.cc/bbs/MATLAB/M.1512387654.A.79A.html
MATLAB 近期熱門文章
PTT數位生活區 即時熱門文章
-1
12