Error in Matlab Code
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
marie lasz
il 14 Dic 2020
Commentato: Image Analyst
il 18 Dic 2020
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
end
end
subplot(2,2,1);
imshow(W);
title('the extracted watermark image');
imwrite(W,'w1.jpg','jpg');
'
0 Commenti
Risposta accettata
Image Analyst
il 14 Dic 2020
Matrices are indexed (row, column), which is (y, x), NOT (x,y) as you have it.
Also check the limits of your for loop to make sure you don't step outside the image.
Attach your 2 images if you still need help so we can run your code.
9 Commenti
Image Analyst
il 18 Dic 2020
Not sure without delving into it much more than I have time for. I notice that your're using x and y and a lot of novices confuse x and y with row and column. They do NOT correspond like that.
Matrixes are indexed M(row, column) which is M(y, x), NOT M(x,y) so make sure all that is correct. I saw for W you're using p as the first index which is derived from x, so that's not right in general but would be okay for a perfectly square matrix. And you're using x as the first index for A instead of y.
Più risposte (1)
Cris LaPierre
il 14 Dic 2020
Error is in this line of code:
BLOCK1=A(x:x+K-1,y:y+K-1);
"Index in position 2 exceeds array bounds (must not exceed 512)"
Position 2 corresponds to your second index: y:y+K-1
Apparently A is a mx512 array. You define y as y=(q-1)*K+1; At its largest value (q=512, K=8), y is 511*8+1, which is >> 512.
You likely need to rethink your approach.
Vedere anche
Categorie
Scopri di più su Computer Vision with Simulink in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!