我想知道是否有人可以帮助我对这些循环进行矢量化我已尝试过一段时间但未能提前感谢。
pixel_depth = 16;
pixel_range = 2^pixel_depth -1;
for i=1:height
for j=1:width
for k=1:gaussianComponents
mean(i,j,k) = rand*pixel_range;
weights(i,j,k) = 1/gaussianComponents;
pixelDeviation(i,j,k) = diviationNew;
end
end
end
感谢您的帮助......
答案 0 :(得分:5)
mean = rand(height, width, gaussianComponents) * pixel_range;
weights = 1/gaussianComponents * ones(height, width, gaussianComponents);
pixelDeviation = diviationNew * ones(height, width, gaussianComponents);
请注意,mean
是变量的错误名称,因为它会隐藏mean
函数。