I am getting error in this code at line 13 '', 'Index in position 2 exceeds array bounds (must not exceed 512). Looking for the solution.Thanks in advance

`clear all;M=512;N=512;K=8;A=imread('lena2.jpg');A=rgb2gray(A);A=imresize(A,[512,512]);b=imread('Watermarked_Image.jpg');for p=1:N for q=1:N x=(p-1)*K+1; y=(q-1)*K+1; BLOCK1=A(x:x+K-1,y:y+K-1); BLOCK2=b(x:x+K-1,y:y+K-1); BLOCK1=idct2(BLOCK1); BLOCK2=idct2(BLOCK2); if BLOCK1(1,1)~=0 a=(BLOCK2(1,1)/BLOCK1(1,1))-1; if a<0 W(p,q)=0; else W(p,q)=1; end end endendsubplot(2,2,1);imshow(W);title('the extracted watermark image');imwrite(W,'w1.jpg','jpg');`

'

## Best Answer