Which image is not like the others?
3 views (last 30 days)
Show older comments
Ron Volkovinsky
on 19 Jul 2020
Commented: Image Analyst
on 19 Jul 2020
I have four RGB images I1, I2, I3, and I4. 3 of them are exactly the same, and one is different. Is there an elegant solution to find which image is different? Currently, I'm using something like the following.
if ~isequal(I1, I2) & ~isequal(I1, I3) & ~isequal(I1, I4)
dif = I1
elseif ~isequal(I2, I1) & ~isequal(I2, I3) & ~isequal(I2, I4)
dif = I2
%etc.
end
0 Comments
Accepted Answer
Abhishek Gangwar
on 19 Jul 2020
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
1 Comment
Image Analyst
on 19 Jul 2020
diff is a built in function so you should use a different name for your output variable.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!