## Matrix Dimensions Must Agree

### Mesita Widia Cahyaning (view profile)

on 15 Sep 2019
Latest activity Commented on by per isakson

### per isakson (view profile)

on 16 Sep 2019
Hello I'm new to mathlab and I'm facing this issue. I'm gonna making image watermarking using dct method and this is my code, hope i can find the solution of this, thankyou beforeee
clc;
clear all
if size(I,3)==3
I=rgb2gray(I);
end
figure,imshow(I), title('CITRA Penampung')
if size(W,3)==3
W=rgb2gray(W);
end
figure,imshow(W), title('CITRA Watermark')
alpha = 0.02;
A = dct2(double(I));
B = dct2(double(W));
C = A + alpha*B;
Iw = round(real(idct2(C)));
IIw = uint8(Iw)
figure,imshow(IIw), title('CITRA Terwatermark')
if size(I,3)==3
I=rgb2gray(I);
end
A=dct2(double(I));
C1=dct2(double(Iw));
B1=(C1-A)./alpha;
W1=uint8(idct2(B1));
figure,imshow(W1), title('CITRA Watermark Hasil Ekstraksi')
%this is the error I get
Matrix dimensions must agree.
Error in dctcoba (line 19)
C = A + alpha*B;

R2017a

### per isakson (view profile)

on 15 Sep 2019
Edited by per isakson

### per isakson (view profile)

on 15 Sep 2019

Is this a copy&paste error?
Replacing the line by
might help.

Mesita Widia Cahyaning

### Mesita Widia Cahyaning (view profile)

on 16 Sep 2019
Oh yes, I think I dont really need to re-read Sunset in line 24, and now I'm deleting it.
Done put a breakpoint and this is the values I get:
I = 300x300x3 uint8
W = 512x512 uint8
Walter Roberson

on 16 Sep 2019