I am currently working on a function for averaging images in MATLAB. But I feel that the following lines could be much simpler, only I don’t know how.
centroidImage(:,:,1) = double(centroidImage(:,:,1)) ./ alphaImage;
centroidImage(:,:,2) = double(centroidImage(:,:,2)) ./ alphaImage;
centroidImage(:,:,3) = double(centroidImage(:,:,3)) ./ alphaImage;
I get an error if I write it as:
centroidImage = double(centroidImage) ./ alphaImage;
Because the dimensions don’t match (alphaImage is [y x] and centroidImage is [y x 3]). Is there not a simpler, more efficient way to iterate the dimensions of the centroidImage variable, without having to explicitly state them all one by one?
You can use
bsxfunfor this: