insert text as watermark in video( one frame)
Show older comments
Hi every one
I use matlab R2018b, I try to insert a text (converting to binary) in one frame from my video using dct method but I get some problem so I need help
this is my code:
% Button pushed function: insrerdataButton
function insrerdataButtonPushed(app, event)
Msg_bin = app.EditField2.Value;
couvert = getimage(app.UIAxes2);
%couvert = rgb2ycbcr(couvert);
taille_msg = size(Msg_bin,1)*size(Msg_bin,2);
n = size(couvert,1);
m = size(couvert,2);
%définit le cle secret
%init de la matrice cle que cle(1,1)=1 et cle(2,1)=1
cle(1,1)=1;
cle(2,1)=1;
a = 1;
b = 1;
%pour obtenir les donneés de la cle cad les positions de l'image
for h=2:taille_msg % on commencer par h=2 puisque on fixer que la cle(1,1)=1 et cle(2,1)=1 pour 2'ieme colonne
a=a+14;%pour le block est de taille 8 et on besoin de 15 pixels pour calculer les block
if (a+10>n)
a=1;
b=b+14;
end
cle(1,h)=a;
cle(2,h)=b;
end
for i=1:taille_msg
% cle(1,i):cle(1,i)+7 =(1:8) cle(2,i):cle(2,i)+7=(1:8)...etc
block(:,:,i)=couvert(cle(1,i):cle(1,i)+7,cle(2,i):cle(2,i)+7);%pour donner les blocks de taille 8*8
end
%Calcule le DCT de chaque Block,;
block = zeros(taille_msg);
dct_image = zeros(taille_msg);
for i=1:taille_msg
dct_image(:,:,i) = dct(block(:,:,i));
% error dans cette instruction
end
% parcour de msg
a=1;
b=1;
for i=1:taille_msg
%pour vérifier que B1(u1,v1)=B1(u2,v2)
% 3 et 2 sont des m et n (Amn)
if (dct_image(3,2,i)==dct_image(2,3,i))
dct_image(3,2,i)=dct_image(3,2,i)+1;
end
% vérifier l'opération de la partie 4 de l'algo
if dct_image(3,2,i)<dct_image(2,3,i) && Msg_bin(b,a)=='1'
valeur= dct_image(3,2,i);
dct_image(3,2,i)=dct_image(2,3,i);
dct_image(2,3,i)=valeur;
else
if dct_image(3,2,i)>dct_image(2,3,i) && Msg_bin(b,a)=='0'
valeur= dct_image(3,2,i);
dct_image(3,2,i)=dct_image(2,3,i);
dct_image(2,3,i)=valeur;
end
end
end
%pour revenir a la ligne 2 de message c a d le parcour de tt le msg
if a==7
a=1;
b=b+1;
else
a=a+1;
end
%le idct
image_marque=couvert;
%calcule le idct
% on utilise le idct du matlab
for i = 1:taille_msg
image_marque(cle(1,i):cle(1,i)+7,cle(2,i):cle(2,i)+7)=uint8(idct(dct_image(:,:,i)));
end
setappdata(0,'cle_kz',cle);
setappdata(0,'image_kz',image_marque);
imshow(image_marque,'Parent',app.UIAxes3);
end
When I push on this button I got that error:
Index in position 3 exceeds array bounds (must not exceed 1).
Error in app1/insrerdataButtonPushed (line 154)
dct_image(:,:,i) = dct(block(:,:,i));
Error using matlab.ui.control.internal.controller.ComponentController/executeUserCallback (line 335)
Error while evaluating Button PrivateButtonPushedFcn.
please help and than you
4 Comments
LEKHCHINE Somia
on 12 Aug 2019
Adam Danz
on 15 Aug 2019
Check again ;)
Adam Danz
on 24 Aug 2019
Hi
I use matlab R2018b
I insert text as watermark in specific frame from video ( using DCT ) but I have some problem
1- I want to replace the original frame by the watermarked frame
2- the text that I can insert just one char
LEKHCHINE Somia
on 24 Aug 2019
Answers (1)
Based on the error message, it appears that "block" is an [m x n x 1] array (or simply, [m x n]).
You're accessing "block" in a for-loop that controls the 3rd index value. So I'm guessing you get this error on the 2nd iteration where i equals 2 (below).
for i=1:taille_msg
dct_image(:,:,i) = dct(block(:,:,i)); % ERROR when i==2
Just prior to that for-loop you define "block" as an [m x n] array or zeros. So certainly, the 3rd dimension of "block" cannot be greater than 1.
block = zeros(taille_msg);
Curiously, you defined "block" earlier in your code within a different for-loop and in this definition, "block" does appear to be 3D [m x n x i] but you're overwriting it with the zeros which makes it 2D. Now it no longer has a 3rd dimension.
for i=1:taille_msg
block(:,:,i)=couvert(cle(1,i):cle(1,i)+7,cle(2,i):cle(2,i)+7); % THIS IS 3D
end
% and later...
block = zeros(taille_msg); % THIS IS 2D
Categories
Find more on Watermarking in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!