Do you think I can reverse the process for reshape and build a video file again?

2 ビュー (過去 30 日間)
Jaykumar Soni
Jaykumar Soni 2018 年 11 月 20 日
I am compeletly new to programming and MATLAB.I working on a project which is kind of compulsary.But now I am stuck at one place and don'tknow how to solve.
The main code I am using is
clc; clear; close all;
% Set the video information
videoSequence = 'bus_cif.yuv';
width = 352;
height = 288;
nFrame = 150;
secimage = 'Data/secret.png'; % Secret image path
x = 0.1;
% Read the video sequence
[Y,U,V] = yuvRead(videoSequence, width, height ,nFrame);
%% Frame by Frame Embedding
display('Begin Embedding...')
tic
secret = imread(secimage);
% convert image into binary (0.1 is a predetermined threshold...)
S = im2bw(secret,0.1);
[wmh,wmw] = size(S);
yImage1 = uint8(zeros(height, width, nFrame));
uImage1 = uint8(zeros(height/2, width/2, nFrame));
vImage1 = uint8(zeros(height/2, width/2, nFrame));
% Y component of the frame
for iFrame = 1:nFrame
yImage1(:,:,iFrame) = dwt_embedd(Y(:,:,iFrame),S,x);
uImage1(:,:,iFrame)=U(:,:,iFrame);
vImage1(:,:,iFrame)=V(:,:,iFrame);
end
%wMark(1:nFrame) = struct('cdata',zeros(wmh,wmw,1,'uint8'),'colormap',[]);
%for iFrame = 1:nFrame
% wMark(iFrame).cdata = dwt_extract(Y_out(:,:,iFrame),Y(:,:,iFrame),x,[wmh wmw]);
%end
% PSNR
% Only the Y frame of the YUV image is considered. Specific method is not
% defined on the paper. Using the provided algorithm..
I want write all the three components back to 'yuv' video file.
The function, I used to read the YUV components is
function [y, u, v] = yuvRead(vid, width, height, nFrame)
fid = fopen(vid,'r'); % Open the video file
stream = fread(fid,'*uchar'); % Read the video file
length = 1.5 * width * height; % Length of a single frame
y = uint8(zeros(height, width, nFrame));
u = uint8(zeros(height/2, width/2, nFrame));
v = uint8(zeros(height/2, width/2, nFrame));
for iFrame = 1:nFrame
frame = stream((iFrame-1)*length+1:iFrame*length);
% Y component of the frame
yImage = reshape(frame(1:width*height), width, height)';
% U component of the frame
uImage = reshape(frame(width*height+1:1.25*width*height), width/2, height/2)';
% V component of the frame
vImage = reshape(frame(1.25*width*height+1:1.5*width*height), width/2, height/2)';
y(:,:,iFrame) = uint8(yImage);
u(:,:,iFrame) = uint8(uImage);
v(:,:,iFrame) = uint8(vImage);
end
Do you think I can reverse the loop and make video file again??

回答 (0 件)

製品


リリース

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by