I am getting error in the code below "matrix dimensions must agree" It occurs in the line of code (Shw=Sh+a*Sw;) The coverImage I am using is a grayscale image, tiff format as is the watermark. Any suggestions what my problem could be?? Thank you
filename='107_3.tif';
coverImage = imread(filename);
Mc=size(coverImage,1);
Nc=size(coverImage,2);
a=10;
watermark = imread('dmg1.tif');
watermark=im2bw(watermark,0.05);
Mn=size(watermark,1);
Nn=size(watermark,2);
[LL,LH,HL,HH] = dwt2(coverImage,'haar');
%[LL1,LH1,HL1,HH1] = dwt2(HH,'haar');
Ih=idwt2([],[],[],HH,'haar');
[Uh,Sh,Vh]=svd(Ih);
[Uw,Sw,Vw]=svd(double(watermark));
Shw=Sh+a*Sw;**%%%%%ERROR OCCURRING HERE%%%%%**
VhT=transpose(Vh);
Ihw=Uh*Shw*VhT;
[LL2,LH2,HL2,HH2]=dwt2(Ihw,'haar');
watermarked_image=idwt2(LL,LH,LH,HH,'haar');
figure;
imshow(watermarked_image,[]);
title('Watermarked Image');
[Uh,Sh,Vh]=svd(Ih);
[Uw,Sw,Vw]=svd(double(watermark));
When you run svd
, the resultant matrix Sh
has the same dimensions as Ih
, and resultant Sw
has the dimensions as watermark
.
http://www.mathworks.com/help/matlab/ref/svd.html
Now,
Shw=Sh+a*Sw;
you are adding 2 matrices together. Matrix addition requires that the matrices you are adding together have the same dimensions (same number of rows
, same number of cols
)
http://en.wikipedia.org/wiki/Matrix_addition
So, what this appears to mean is: Your code expects the watermark to be the same dimensions as the input image. I don't know what images you are using in your situation, but it seems like that is a faulty expectation. I am guessing that the watermark you are using is typically smaller, likely much smaller, than the input image you are embedding it into.
So it appears you either need to