In an assignment A(I) = B, the number of elements in B and I must be the same.
The reason for this error is that you are trying to assign all the content of I
to a subset of E
(those pixels where diff>50
). You have to specifically tell MATLAB that you want those pixels set to the matching pixels in I
.
E(diff>50)=I(diff>50);
Incidentally you should be careful using imsubtract
here. For pixels where I
has a higher value than B
, that will result in zeros (if your values are uint8
). It may be okay (not 100% clear if you're looking for the absolute difference or really just where B
is larger than I
)