I'm working in a project on medical image segmentation which uses the Dice Score as part of the loss function, but I got some doubts with the commonly adopted implementation.

The definition of Dice Score is:

$ DSC = \frac{2 |X \cap Y|}{|X|+ |Y|} $

So, if we apply this to arrays by considering them elementwise,

if $ x= \lt a,b,a,a \gt $ and $ y= \lt b,a,a,a \gt $ we would get $ DSC = \frac{2 |\lt a, a \gt|}{|\lt a,b,a,a \gt|+ |\lt b,a,a,a \gt|} = \frac{4}{8} = \frac{1}{2} $, which makes sense since only half of the elements are in common between the two arrays, while $DSC(\lt a,a,a,a \gt, \lt b,b,b,b \gt) = 0 $ and $DSC(\lt b,b,b,b \gt, \lt b,b,b,b \gt) = 1 $

Now, let's suppose that we got a 2x2 ground truth binary image $G$ and a 2x2 predicted image $P$, and we define $X = flatten(G)$ and $Y = flatten(P)$ in order to get two binary vectors, such that $x_i \in \{0,1\}$.

Wikipedia says that:

When applied to boolean data, using the definition of true positive (TP), false positive (FP), and false negative (FN), it can be written as $DSC = \frac{2 TP}{2 TP + FP + FN}$.

My doubt is about this statement:

If we consider my first example, where $a=0$ and $b=1$, and considering $x$ as the ground truth and $y$ as the prediction, we would have (according to the latter definition):

$ x= \lt 0, 1, 0, 0 \gt $

$ y= \lt 1, 0, 0, 0 \gt $

If we call $e_i$ the couple $(x_i, y_i)$ we get

$ TP=|{\emptyset}| = 0 $ , $ FP = |\{e_1\}| = 1 $, $ FN = |\{e_2\}| = 1 $, $ TN = |\{e_3, e_4\}| = 2 $


$DSC = \frac{2 TP}{2 TP + FP + FN}$ = $\frac{2*0}{2*0 + 1 + 1} = 0 \ne \frac{1}{2} $

So if I'm not wrong this formulation does not take into account true negatives (when both the real pixel and the predicted one are 0), while the first formulation does, because it doesn't associate any meaning to the elements of x and y.

Note that this is consinstent with the typical formulation that one can find on the internet (e.g. here, here, etc) in which DSC for binary arrays is often calculated as $\frac{2*\sum{X \land Y}}{len(X)+len(Y)}$, but $|{0}\cap{0}| = |{0}| = 1$ and $\sum({0}\land{0}) = \sum({0}) = 0$.

I spotted this inconsistency while checking the results of a differentiable version of the Dice Score I found on SO and some repos.

What am I missing?



You must log in to answer this question.