Clear Filters
Clear Filters

Which image is not like the others?

1 view (last 30 days)
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

Accepted Answer

Abhishek Gangwar
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
Image Analyst on 19 Jul 2020
diff is a built in function so you should use a different name for your output variable.

Sign in to comment.

More Answers (1)

KSSV
KSSV on 19 Jul 2020
Edited: KSSV on 19 Jul 2020
n = numel(I1) ;
if nnz(I1==I2==I3) == n
dif = I4 ;
elseif nnz(I2==I3==I4) == n
dif = I1 ;
elseif nnz(I3==I4==I1) == n
dif = I2 ;
else
dif = I3 ;
end

Categories

Find more on Images in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!