Compute difference of two images using "imabsdiff()" function, output of this function would be a matrix if both images are same, resulting matrix would have all zeros, you can use this logic.
for example:-
diff1 = imabsdiff(I1, I2);
diff2 = imabsdiff(I2, I3);
diff3 = imabsdiff(I3, I4);
diff4 = imabsdiff(I4, I1);
if sum(sum(diff1)) == 0 && sum(sum(diff2)) == 0 && sum(sum(diff3)) ~= 0 && sum(sum(diff4)) ~= 0
diff = I4;
elseif sum(sum(diff1)) == 0 && sum(sum(diff2)) ~= 0 && sum(sum(diff3)) ~= 0 && sum(sum(diff4)) == 0
diff = I3;
elseif sum(sum(diff1)) ~= 0 && sum(sum(diff2)) ~= 0 && sum(sum(diff3)) == 0 && sum(sum(diff4)) == 0
diff = I2;
elseif sum(sum(diff1)) ~= 0 && sum(sum(diff2)) == 0 && sum(sum(diff3)) == 0 && sum(sum(diff4)) ~= 0
diff = I1;
end
Best Answer