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

조회 수: 1 (최근 30일)
Faradisa
Faradisa 2018년 2월 5일
댓글: Torsten 2018년 2월 5일
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);

답변 (1개)

Torsten
Torsten 2018년 2월 5일
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
Faradisa
Faradisa 2018년 2월 5일
would you please give the correct one, sir?
Torsten
Torsten 2018년 2월 5일
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.

댓글을 달려면 로그인하십시오.

제품

Community Treasure Hunt

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

Start Hunting!

Translated by