我有一个用于计算sigma
的等式,其中i是1 to N
的索引,*
表示卷积运算,Omega是图像域。
我想用matlab代码实现它。目前,我有三个选项来实现上述等式。你能看看我的方程并对我说哪一个是正确的?我花了很多时间来看看方法之间有什么不同但我找不到。提前致谢
方法1和方法2之间的差异是方法1计算循环后的西格玛,但方法2在循环中计算它。
sigma(1:row,1:col,1:dim) = nu/d;
是否会给出相同的结果?
=========== Matlab代码==============
方法1
nu = 0;
d = 0;
I2 = I.^2;
[row,col] = size(I);
for i = 1:N
KuI2 = conv2(u(:,:,i).*I2,k,'same');
bc = b.*(c(:,:,i));
bcKuI = -2*bc.*conv2(u(:,:,i).*I,k,'same');
bc2Ku = bc.^2.*conv2(u(:,:,i),k,'same');
nu = nu + sum(sum(KuI2+bcKuI+bc2Ku));
ku = conv2(u(:,:,i),k,'same');
d = d + sum(sum(ku));
end
d = d + (d==0)*eps;
sigma(1:row,1:col,1:dim) = nu/d;
方法2:
I2 = I.^2;
[row,col] = size(I);
for i = 1:dim
KuI2 = conv2(u(:,:,i).*I2,k,'same');
bc = b.*(c(:,:,i));
bcKuI = -2*bc.*conv2(u(:,:,i).*I,k,'same');
bc2Ku = bc.^2.*conv2(u(:,:,i),k,'same');
nu = sum(sum(KuI2+bcKuI+bc2Ku));
ku = conv2(u(:,:,i),k,'same');
d = sum(sum(ku));
d = d + (d==0)*eps;
sigma(1:row,1:col,i) = nu/d;
end
方法3:
I2 = I.^2;
[row,col] = size(I);
for i = 1:dim
KuI2 = conv2(u(:,:,i).*I2,k,'same');
bc = b.*(c(:,:,i));
bcKuI = -2*bc.*conv2(u(:,:,i).*I,k,'same');
bc2Ku = bc.^2.*conv2(u(:,:,i),k,'same');
ku = conv2(u(:,:,i),k,'same');
d = ku + (ku==0)*eps;
sigma(:,:,i) = (KuI2+bcKuI+bc2Ku)./d;
end
sigma = sigma + (sigma==0).*eps;
答案 0 :(得分:0)
我认为方法1假设sigma1=sigma2=...sigman
因为你是在循环函数之外计算的
sigma(1:row,1:col,1:dim) = nu/d;
其中nu和d是每次迭代的累积和。
虽然,方法2显示sigma1 !=sigma 2 !=..sigman
,因为每个西格玛都是在循环函数中计算的
希望有所帮助