Problem in extracting the watermark ! !

2 次查看(过去 30 天)
Dear Sir,
I have an issue in extracting the watermark..
PROPOSED APPROACH :
1.Bring the image to frequency domain by applying the DCT
2.generate a watermark signal
3.Use the thousand largest coefficients of the original image to embed a watermark sequence of length 1000.
4.Coefficients are modified according to the stream bits of the message using the equation below,
CAW = CA (1 + α Wi)
5.Extraction process – simply subtracting the original DCT coefficients from the watermarked image coefficients.
--------------------------------------------------------------------------------------------------------------------------------
*The code for embedding and extraction is as follows :*
______________________________________________________________
[fname pthname]=uigetfile('*.jpg;*.png;*.tif;*bmp','Select the Asset Image'); %select image
I=imread([pthname fname]);
wmsz=1000; %watermark size
I=I(:,:,1);%get the first color in case of RGB image
[r,c]=size(I);
D=dct2(I);%get DCT of the Asset
D_vec=reshape(D,1,r*c);%putting all DCT values in a vector
[D_vec_srt,Idx]=sort(abs(D_vec),'descend');%re-ordering all the absolute values
W=randn(1,wmsz);%generate a Gaussian spread spectrum noise to use as watermark signal
Idx2=Idx(2:wmsz+1);%choosing 1000 biggest values other than the DC value
%finding associated row-column order for vector values
IND=zeros(wmsz,2);
for k=1:wmsz
x=floor(Idx2(k)/r)+1;%associated culomn in the image
y=mod(Idx2(k),r);%associated row in the image
IND(k,1)=y;
IND(k,2)=x;
end
D_w=D;
for k=1:wmsz
%insert the WM signal into the DCT values
D_w(IND(k,1),IND(k,2))=D_w(IND(k,1),IND(k,2))+.1*D_w(IND(k,1),IND(k,2)).*W(k);
end
I2=idct2(D_w);%inverse DCT to produce the watermarked asset
%The extraction process is simply subtracting the original DCT %coefficients from the
%watermarked image ones. The code can be written like below:
W2=[];%will contain watermark signal extracted from the image
for k=1:wmsz
W2=[W2(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];%watermark extraction
end
_____________________________________________________________
The ERROR appears as follows in the 25th line :
??? Attempted to access W2(-0.0432565); index must be a positive integer or logical.
Error in ==> pooya at 29
W2=[W2(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];%watermark extraction
-----------------------------------------------------------
Please help
Thank you.
  1 个评论
Walter Roberson
Walter Roberson 2011-12-14
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup

请先登录,再进行评论。

采纳的回答

Eric Pahlke
Eric Pahlke 2011-12-15
There's a lot of code to sort through to figure out exactly what you need to fix, but what stands out is this line:
D_w(IND(k,1),IND(k,2))=D_w(IND(k,1),IND(k,2))+.1*D_w(IND(k,1),IND(k,2)).*W(k);
You're using D_w as an index on line 25(where you get the error), which means it has to be an integer.
However in the line above you're assigning fractional values to D_w:
(D_w(stuff) = D_w(stuff) + .1*D_w(stuff)
Was the .1* intended to be a .* ?
  2 个评论
mcc mscelec
mcc mscelec 2011-12-16
No.. the value is (0.1)
And i'm extremely sorry to say that it was my mistake to mention as to where the error appears. The error actually appears in the 29th line:
W2=[W2(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];
The error says
"??? Attempted to access W2(-0.0432565); index must be a positive integer or logical."
Could you help me in debugging the error.
Thank you :)
Walter Roberson
Walter Roberson 2012-3-17
You have a division in your subscript calculations, but you are expecting the result will always be an integer ??

请先登录,再进行评论。

更多回答(4 个)

mcc mscelec
mcc mscelec 2012-3-18
I figured out the flaw in the code line:
W2=[W2(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];%watermark extraction
All this while i haven't been storing the new values of W2. The code worked successfully when i made a small modification as follows:
W2(k)=[(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];%watermark extraction
------------------Here is the complete working program:-----------------------------
I=imread('girl512.bmp');
subplot(2,3,1),imshow(I,[]),title('Original Image');
wmsz=1000;
I=I(:,:,1);
[r,c]=size(I);
D=dct2(I);
D_vec=reshape(D,1,r*c);
[D_vec_srt,Idx]=sort(abs(D_vec),'descend');
W=randn(1,wmsz);
subplot(2,3,2),plot(W),title('Watermark');
Idx2=Idx(2:wmsz+1);%choosing 1000 biggest values other than the DC
%finding associated row-column order for vector values
IND=zeros(wmsz,2);
for k=1:wmsz
x=floor(Idx2(k)/r)+1;%associated culomn in the image
y=mod(Idx2(k),r);%associated row in the image
IND(k,1)=y;
IND(k,2)=x;
end
D_w=D;
%WATERMARK EMBEDDING
for k=1:wmsz
fw=D_w((IND(k,1),IND(k,2));
fw=fw+0.1*fw.*W(k);
end
I2=idct2(D_w);%inverse DCT to produce the watermarked asset
I2_int=uint8(I2);
imwrite(I2_int,'I2_watermarkedn.bmp','bmp');
subplot(2,3,3),imshow('I2_watermarkedn.bmp'),title('Watermarked Image');
%WATERMARK EXTRACTION
W2=[];
for k=1:wmsz
W2(k)=[(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];
end
subplot(2,3,4),plot(W2),title('Extracted Watermark');
Thank you for all the comments and suggestions :)
  5 个评论
Pardeep Kumar
Pardeep Kumar 2013-4-15
编辑:Walter Roberson 2013-4-15
pls correct these errors
fw=D_w(IND(k,1),IND(k,2));
and
%WATERMARK EXTRACTION
W2=(2500000);
for k=1:wmsz
W2(k)=((D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10);
end
subplot(2,3,4),plot(W2),title('Extracted Watermark');
Walter Roberson
Walter Roberson 2013-4-15
What error message are you seeing ?

请先登录,再进行评论。


mcc mscelec
mcc mscelec 2012-4-14
Code for WATERMARK DETECTOR RESPONSE FUNCTION
function WM_plot(r,c,ext_wm,orig_wm)
for k=1:1000
wm=randn(r,c);%depending on the size of the watermark
wm=uint8(wm);%if necessary
store(k)=WM_detect(ext_wm,wm);%wrong watermarks
if k == 400
store(k)=WM_detect(ext_wm,orig_wm);%original watermark detection
end
end
figure(1),plot(1:k,[store]),ylabel('Watermark detector response'),xlabel('random watermarks');
hold on
%threshold calculation
[peak,ind]=sort(store,'descend');
threshold=peak(2)+(peak(2)*0.1);%T=second highest peak+10percentof the same
figure(1),plot(1:1000,[threshold],'red');
hold on
figure(1),plot(1:1000,peak(2),'green');
Regards, mcc :)
  1 个评论
Pardeep Kumar
Pardeep Kumar 2013-5-26
sir ,there is error showing in the line store(k)=WM_detect(ext_wm,orig_wm);
ie.value assigned to variable store might be unused .

请先登录,再进行评论。


Lester
Lester 2013-3-2
sir ,
may i know what are the steps followed for embedding and extracting the image in DCT domain in the above code....???

Alaa Eleyan
Alaa Eleyan 2013-11-22
the code is working properly..
You just need to add space between W2 and (D_w(....... in the for loop :
Wrong : W2=[W2(D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];
Correct : W2=[W2 (D_w(IND(k,1),IND(k,2))/D(IND(k,1),IND(k,2))-1)*10];

Community Treasure Hunt

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

Start Hunting!

Translated by