MATLAB: Problem in extracting the watermark ! !

dctextracting the watermarkwatermarking

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.

Best Answer

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 .* ?