I am currently implementing image segmentation on MATLAB . I have two implementations.
I am trying to compute the similarity measure between the segmented image and the ground truth (manual segmented images) by using the dice coefficient or the Jaccard Index. This works well for the segmented images that have been divided into two regions. This is implemented by the following code.
dice = 2*nnz(segIm&grndTruth)/(nnz(segIm) + nnz(grndTruth))
Click Here
This expects segIm and grndTruth to be of the same size. They must also be numeric or logical.
However I have not been able to find a way to apply this measure for comparison of similarity for multiple - region segmented images. Can anyone tell me how I can use the dice coefficient in my application ?
EDIT: With respect to nkjt's suggestions I have done a basic implementation and am giving the results below. Please feel free to upgrade the code anyone for better accuracy.
I am considering two images in the form of two matrices. A is the segmented image and B is the manual ground truth. The matlab code for the above suggested implementation is given below. Please check and do give your thoughts.
A=[1 2 3 4;1 2 3 4;1 2 3 4;1 2 3 4]
B=[1 3 4 4;1 1 3 4;1 2 3 4;1 2 3 1]
%//First Suggestion
dice = 2*nnz(A==B)/(nnz(A) + nnz(B))
%//2nd Suggestion
A1=(A==1);B1=(B==1);
A2=(A==2);B2=(B==2);
A3=(A==3);B3=(B==3);
A4=(A==4);B4=(B==4);
dice = (2*nnz(A1&B1)/(nnz(A1) + nnz(B1))...
+2*nnz(A2&B2)/(nnz(A2) + nnz(B2))...
+2*nnz(A3&B3)/(nnz(A3) + nnz(B3))...
+2*nnz(A4&B4)/(nnz(A4) + nnz(B4)))/4
Please Note : I am also interested to know if Hausdorff Distance Measure can be applied in this case for both the 3 phase and 4 phase segmented images??
EDIT: I do have a new query . If suppose the image has 4 regions and it has been correctly segmented in this manner as shown in the example below: If now different intensity values are used to denote the different regions , then using Dice coefficient the two segmented results will give different results. For Segmented Reg 1, I have dice = 1 ** and for **Segmented Region 2, I have dice = 0.75. But both the results are accurate. How can I modify my code such that the segmented results will reflect the answer of the dice coefficients ?
An similarity measure is a measure of correspondence between two images. If the similarity measure is maximal, the images are considered to be correctly aligned.
Typically, the Jaccard similarity coefficient (or index) is used to compare the similarity between two sets. For two sets, A and B , the Jaccard index is defined to be the ratio of the size of their intersection and the size of their union: J(A,B) = (A ∩ B) / (A ∪ B)
To calculate the similarity between two examples, you need to combine all the feature data for those two examples into a single numeric value. For instance, consider a shoe data set with only one feature: shoe size. You can quantify how similar two shoes are by calculating the difference between their sizes.
The work of Arbel´aez et al. describes several methods to compare results of image segmentation algorithms. See section 3.1 and its sub-sections.
I believe some Matlab code can be found in thier project's webpage.
The Berkeley segmentation dataset (bsds500) is a well established benchmark in the image segmentaiton community.
You might want to look into measures designed for segmentation, such as Normalized Probabilistic Rand.
However, I can see two possible ways of doing something quick with your existing code.
1) Instead of using logical images and &, use:
dice = 2*nnz(segIm==grndTruth)/(nnz(segIm) + nnz(grndTruth));
Both segIm and grndTruth here should be numerical (ideally integer with foreground regions having values of 1,2,3... etc).
2) Produce a set of binary images out of both segIm & grndTruth for each foreground area, and define a dice coefficient for each.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With