我有两张图像,我想根据特定像素的值进行比较并执行不同的操作。问题是它真的很慢,我需要加快操作速度,代码可以做什么?
currentFrame = rgbimage; %rgbimage is an 800x450x3 matrix
for i = 1:size(currentFrame, 1)
for j = 1 : size(currentFrame,2)
if currentFrame(i,j) > backgroundImage(i,j) %backgroundimage is an equally sized image which i would like to compare with
backgroundImage(i,j, :) = double(backgroundImage(i,j, :) +1);
elseif currentFrame(i,j) < backgroundImage(i,j)
backgroundImage(i,j, :) = double(backgroundImage(i,j, :) -1);
end
end
end
diff = abs(double(currentFrame) - double(backgroundImage)); %difference between my backgroundimage and my current frame
fusion = zeros(size(currentFrame)); % A fusion image
for i=1:size(backgroundImage,1)
for j = 1:size(backgroundImage,2)
if diff(i,j) > 20
fusion(i,j, :) = double(currentFrame(i,j, :));
else
fusion(i,j, :) = 0;
end
end
end
谢谢你的帮助!