使用与索引有关的abs()时出错

时间:2019-05-23 02:41:06

标签: matlab

我有以下for循环:

for i = 1:3000
    disp(DCT(key(i, 1), key(i, 2)));

    %Apply formula to HL3 in key location i
    x = sign(DCT(key(i, 1), key(i, 2)));
    y = abs(DCT(key(i, 1), key(i, 2)))^(C-1);
    z = w(1, i);

    %Add result to phi
    phi = phi + (x*y*z);

end

我收到一条错误消息:

y = abs(DCT(key(i, 1), key(i, 2)))^(C-1);

说:

    Array indices must be positive integers or logical values.

Error in CosineWatermarkDetector (line 25)
    y = abs(DCT(key(i, 1), key(i, 2)))^(C-1);

但是下面的代码返回值-48.6990

disp(DCT(key(i, 1), key(i, 2)));

有人可以看到原因吗?

编辑: 这是完整的代码

load Key.mat
load watermark.mat

%Select image
[filename, pathname] = uigetfile({'*.tif;*.ppm;*.bmp','Picture files (*.tif,*.ppm,*.bmp)'}, 'Pick a image');
path=[pathname,filename];

%Load image from selected path
image = imread(path);

%DWT image
DCT = dct2(image);
figure; imshow(DCT);

%Set value of C
C = 1.7;

%Set values of phi to 0
phi = 0;

for i = 1:3000

    %Apply formula to HL3 in key location i
    x = sign(DCT(key(i, 1), key(i, 2)));
    y = abs(DCT(key(i, 1), key(i, 2)))^(C-1);
    z = w(1, i);

    %Add result to phi
    phi = phi + (x*z);

end
disp(phi);
%If all values of phi are greater than 0 then watermark exists
if (phi > 0)
   disp('Watermark detected');
else
    disp('No watermark detected');
end

0 个答案:

没有答案