In an assignment A(:) = B, the number of elements in A and B must be the same.

1 view (last 30 days)
Hi, I am trying to embed grayscale image to color image (DCT watermarking). I get the error message :
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in watermark>pushbutton3_Callback (line 167)
zz_dct_koeff(L+1:L+n) = V;
this is the code
alpha = 0.2;
L = 1000;
n = 1000;
a=getappdata(0,'host');
b=getappdata(0,'watermark');
yCbCr = rgb2ycbcr(a);
Y = double(yCbCr(:,:,1));
[xm,xn] = size(Y);
scan_order = jpeg_scan(xm,xn); %access jpeg_scan function
%grayscale image as watermark
wt = double(b);
[M,N] = size(wt);
W = reshape(wt,1,[M*N]);
%transform Y component of host image to DCT
Y_dct = dct2(Y);
temp = Y_dct(:);
zz_dct_koeff = temp;
zz_dct_koeff(scan_order(:)) = temp;
V = zz_dct_koeff(L+1:L+n);
V = V + alpha*abs(V).*W; %perform watermark
zz_dct_koeff(L+1:L+n) = V;
temp = zz_dct_koeff(scan_order(:));
Yx_dct = reshape(temp,xm,xn);
Yx = uint8(idct2(Yx_dct));
yCbCr(:,:,1) = Yx;
wtm = ycbcr2rgb(yCbCr);
axes(handles.axes3);
imshow(wtm);

Answers (1)

Torsten
Torsten on 5 Feb 2018
zz_dct_koeff(L+1:L+n) is a single value whereas V is a vector of length M*N.
Thus the assignment
zz_dct_koeff(L+1:L+n) = V;
can't work.
Best wishes
Torsten.
  2 Comments
Torsten
Torsten on 5 Feb 2018
You are the only person who understands the code you are using. So it's up to you to correct the error I tried to explain to you.
Best wishes
Torsten.

Sign in to comment.

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!