我有一个像素e1
的逻辑掩码需要“混合”。无论我为k
赋予什么值,循环执行k
次,但图像只受影响一次。
代码:
for k=1:5 %I want to do it 5 times but it does the action only once.
for i=2:rows-1
for j=2:cols-1
if e1(i, j) == 1 %if mask == 1, I take "marked" pixel, 8 pixel surrounding it, and avg them.
I2(i, j, 1) = (I2(i, j-1, 1) + I2(i, j+1, 1) + I2(i-1, j, 1) + I2(i-1, j-1, 1) + I2(i-1, j+1, 1) + I2(i+1, j, 1) + I2(i+1, j+1, 1) + I2(i+1, j-1, 1))/8;
I2(i, j, 2) = (I2(i, j-1, 2) + I2(i, j+1, 2) + I2(i-1, j, 2) + I2(i-1, j-1, 2) + I2(i-1, j+1, 2) + I2(i+1, j, 2) + I2(i+1, j+1, 2) + I2(i+1, j-1, 2))/8;
I2(i, j, 3) = (I2(i, j-1, 3) + I2(i, j+1, 3) + I2(i-1, j, 3) + I2(i-1, j-1, 3) + I2(i-1, j+1, 3) + I2(i+1, j, 3) + I2(i+1, j+1, 3) + I2(i+1, j-1, 3))/8;
end
end
end
end
答案 0 :(得分:0)
我认为你应该尝试:
for k=1:5
I2=convn(I2,[1 1 1;1 0 1;1 1 1]/8);
end