Which image is not like the others?

1 次查看(过去 30 天)
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

采纳的回答

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

请先登录,再进行评论。

更多回答(1 个)

KSSV
KSSV 2020-7-19
编辑:KSSV 2020-7-19
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

类别

Help CenterFile Exchange 中查找有关 Images 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by