MATLAB: Finding maximum abs value of four images

finding maximum abs value of four images

I have four 16×16 images.I want to form another image by taking the maximum abs value of all four values of a particular pixel e.g. by comparing I1(3,3),I2(3,3),I3(3,3) and I4(3,3),I will be getting I5(3,3).
my piece of code is:
for k:4
.......
figure,imshow(B);
s=size(B)
eval(sprintf('im_%d=B;',k));
end

Best Answer

No loops necessary:
CombinedImages = cat(3, I1, I2, I3, I4)
I5 = max(abs(CombinedImages),[],3)