我有以下功能,我需要将其转换为MATLAB代码,我非常确定我已正确翻译了该功能。但是我的代码有一个小问题。
翻译功能:
当我尝试运行此功能时,phi的值出现为inf
我真的不确定为什么会这样?
另外,有人可以告诉我,如果我使用此功能的总和部分做正确的事吗?在我看来,这告诉我将此函数应用于每个值,然后将该值添加到phi中,但我不确定这是否是我实际在做的事情。
function [exists] = detectHaarWatermark(watermarkedCoefs, watermark)
coefsSize = size(watermarkedCoefs,1);
phi = 0;
numeratorTotal = 0;
denomanatorTotal = 0;
for i = 1 : coefsSize
for j = 1 : coefsSize
y = watermarkedCoefs(i,j) %Watermarked coefficient
w = watermark(i,j) %Watermark
% val = ((w * sign(y))^2) / (w^2)
numerator = (w * sign(y))
numeratorTotal = numeratorTotal + numerator;
numeratorTotal = numeratorTotal^2;
denomanator = (w^2)
denomanatorTotal = denomanatorTotal + denomanator;
val = numeratorTotal / denomanatorTotal;
phi = val;
end
end
phi
stdDev = std2(watermarkedCoefs)
if phi > (10*stdDev)
exists = true;
else
exists = false;
end
end %end function
编辑:
numerator = (sum(sum(watermark.*(sign(watermarkedCoefs)))));
numerator = power(numerator, 2);
denomanator = sum(sum(watermark.^2));
phi = numerator / denomanator