Hi, i am trying to run this code and facing problem. So plz help.....!!!

1 view (last 30 days)
clc;
close all;
clear all;
% save start time
start_time=cputime;
k=2; % set the gain factor for embeding
%read the original video and get the information
vid = VideoReader('vipmen.avi');
mov = read(vid);
% size of the each frame
Mc=mov.Height;
Nc=mov.Width;
% read in the message image and reshape it into a vector
file_name='_copyright_small.bmp';
message=double(imread(file_name)); % 0's and 255's in matrix
[Mm,Nm]=size(message);
message_vector=round(reshape(message,Mm*Nm,1)./256);
% read in key for PN generator
file_name='_key.bmp';
key=double(imread(file_name))./256;
% key=mean(key);
for h=1:mov.NumFrames
for z=1:3
% take the single frame of the video
cover_object=mov(h).cdata(:,:,z);
cover_object=double(cover_object);
% reset MATLAB's PN generator to state "key"
rand('state',key(1));
%perform DWT
[cA1,cH1,cV1,cD1] = dwt2(cover_object,'haar');
% add pn sequences to H1 and V1 componants when message = 0
for (kk=1:length(message_vector))
pn_sequence_h=round(2*(rand(Mc/2,Nc/2)-0.5));
pn_sequence_v=round(2*(rand(Mc/2,Nc/2)-0.5));
if (message(kk) == 0)
cH1=cH1+k*pn_sequence_h;
cV1=cV1+k*pn_sequence_v;
end
end
% perform IDWT
watermarked_image = idwt2(cA1,cH1,cV1,cD1,'haar',[Mc,Nc]);
R{z}=watermarked_image;
end
% I2--> 3D color watermarked frame
I2=cat(3,cell2mat(R(1)),cell2mat(R(2)),cell2mat(R(3)));
% I3--> all watermarked frames in 4-D
I3(:,:,:,h)=I2;
end
%convert all the frames into matlab movie format
for y=1:h
mov2(y).cdata=uint8(I3(:,:,:,y));
mov2(y).colormap=[];
end
% matlab movie is converted into avi file and it is stored into hard disk
movie2avi(mov2,'watermarkedvideo','FPS',30,'compression','None')
% display processing time
elapsed_time=cputime-start_time
  4 Comments
Naman
Naman on 6 May 2014
Moved: DGM on 14 Feb 2023
Error has been fixed. Now i want to use it with MATLAB function block and i do not knw how to use it with this code.

Sign in to comment.

Answers (1)

Mehdi
Mehdi on 3 May 2014
Can you attach vipmen.avi so the code can be run to check errors
  1 Comment
Naman
Naman on 6 May 2014
Moved: DGM on 14 Feb 2023
vipmen.avi is a small video. You can consider any video instead of this and rename it as vipmen.avi (.avi is a kind of video format)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by