为图像像素指定值

时间:2016-04-26 08:12:53

标签: matlab

我想要分配前一帧的值,其中下一帧中的值为零

if (n_image(:,:,1)==0 && n_image(:,:,2)==0 && n_image(:,:,3)==0)
               n_image(:,:,1)=grabbed_image(:,:,1);
               n_image(:,:,2)=grabbed_image(:,:,2);
               n_image(:,:,3)=grabbed_image(:,:,3);
end

ERROR:

  

||&&运算符的操作数必须可转换为逻辑标量值。

1 个答案:

答案 0 :(得分:1)

您将逻辑条件与逻辑索引混淆

to_replace = all( n_image == 0, 3 );  %// logical index for pixels to be replaces
n_image = bsxfun(@times, n_image, ~to_replace) + bsxfun(@times, grabbed_image, to_replace);

使用索引而不是乘法

to_replace = to_replace(:,:,[1 1 1]);  %// replicate logical indices to channel dimension
n_image(to_replace) = grabbed_image(to_replace);