Why is imcolordiff not symmetric and what is output range?

조회 수: 1 (최근 30일)
Ryan Fogarty
Ryan Fogarty 2022년 6월 25일
댓글: Ryan Fogarty 2022년 6월 29일
Hello, I was trying to use the imcolordiff() function to determine color distance between histopathology patches (separated via k-means). I was attempting to use imcolordiff as a distance function to optimize a preprocessing step on whole slide images. But I need to determine the range of the output variable dE (which might be [0,148.471]). But was hoping to know that number exactly. In attempting to determine the range (with values such as [0,0,0] and [0,255,0]), I noticed that imcolordiff is not symmetric. I.e. imcolordiff(c1,c2) != imcolordiff(c2,c1). I tried individual pixels as well as creating small 400x400 patches. Quick code example demonstrating:
i1=[0,0,0];
i2=[255,0,0];
% Shouldn't the following 2 be equal?
imcolordiff(uint8(i1),uint8(i2))
ans = single 117.3272
imcolordiff(uint8(i2),uint8(i1))
ans = single 56.3068
c1=uint8(reshape(ones(400*400,1)*i1(1,:),400,400,3));
c2=uint8(reshape(ones(400*400,1)*i2(1,:),400,400,3));
diff1=imcolordiff(c1,c2);
diff2=imcolordiff(c2,c1);
% Shouldn't the following 2 be equal?
max(diff1(:))
ans = single 117.3272
max(diff2(:))
ans = single 56.3068
TLDR: Why is the distance function imcolordiff not symmetric (or perhaps the correct term is commutative)? Is this a bug? I also discovered the deltaE function does appear to be symmetric. Also what is the range of the output for both of these functions (given R,G,B uint8 input)?
Thank you,
Ryan

채택된 답변

Image Analyst
Image Analyst 2022년 6월 25일
I didn't even know about this fairly new function. Maybe I should read release notes. Or maybe I just forgot about it.
No it's not a bug. The color space is not uniform so determining the color difference depends on where the reference color is.
I don't know the possible range but in general a dE of 0 means no color difference, a dE of 1 is just barely noticeable, a dE of 5 is definitely easily noticeable, and delta E's more than 15 or 20 are huge differences, so much so that they're probably a completely different color, like blue vs. yellow, or red vs. green.
Note that the values are not calibrated, which is why I probably won't use them. They depend on your RGB being sRGB I believe, and use theoretical "book" formulas so your values won't match those of your spectrophotometer if you measure your object with a spectrophotometer. A spectrophotometer is considered the best possible, gold standard instrument for measuring color difference. It WILL be right. Not so with a digital image. Let's say you take a picture of a scene - a bowl of oranges say. Now you want to get the CIE LAB color values so you run your image through rgb2lab and get an LAB image. Now let's say you reduce your exposure by half so that all the digital values were half of before. Now your LAB values are half of before. But your scene didn't change at all! So basically you can make your scene have whatever LAB you want be adjusting the exposure and color of lighting. So how can you get the "true" lab values? You have to calibrate by putting in a known standard, like the Calibrite Color Checker chart and make up a transform that transforms actual RGB values into known, calibrated, true LAB values.
  댓글 수: 4
DGM
DGM 2022년 6월 28일
편집: DGM 2022년 6월 28일
Minor clarification in case OP doesn't realize it.
The 1976 method used by deltaE() is a simple Euclidean distance. The inputs can be swapped without changing the results. On the other hand, the 1994 and 2000 methods derive weighting values from one of the two inputs (the reference image).
imcolordiff() uses CIE94 (default) or CIE2000 methods, so they won't be commutative. I feel that the documentation is misleading in that it makes no mention of this property, and makes no mention of which argument is the reference image. The first argument ("I1" in the docs) is the reference image.
Ryan Fogarty
Ryan Fogarty 2022년 6월 29일
Ok, I see now. Thank you both for the clarification.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by