Similarity measure between two images

10,951

Solution 1

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.

Solution 2

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.

Share:
10,951
roni
Author by

roni

Indian Institute of Science Bangalore.

Updated on June 12, 2022

Comments

  • roni
    roni almost 2 years

    I am currently implementing image segmentation on MATLAB . I have two implementations.

    1. The image is segmented into two regions - foreground and background.
    2. The image is segmented into more than two regions - suppose 3 segmented regions or 4.

    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 ?

    enter image description here

  • roni
    roni over 10 years
    Thanks I will look into it. Suppose the image is divided into 4 regions with each region having values 1,2,3 and 4 for both the ground truth and the segmented image. Do you think your code will work in such a case ?
  • roni
    roni over 10 years
    Please can you explain your second method a bit more? It would really help me.
  • nkjt
    nkjt over 10 years
    As long as the images are the same size, that line of code should work. For the second, you can create a BW image just by something like segIm1 = segIm == 1. The dice coefficient for segIm1 & grndTruth1 would then be "how close is the segmentation for region 1", and so on. This might be helpful if you expect some regions to be easier to segment than others.
  • roni
    roni over 10 years
    please check my edited question. I have tried to implement your suggestions.
  • nkjt
    nkjt over 10 years
    Yes, that looks fine - note that this type of comparison isn't really robust against certain types of error, though. For example if you wanted to get a count of how many objects there are in an image, you should have a metric which penalises errors which join objects together or split a single object into parts. A lot depends on what your objective is.
  • roni
    roni over 10 years
    Thanks for checking my answer. This is adequate for my work. Just out of curiosity do you think Hausdorff measure can be applied in this case ?
  • nkjt
    nkjt over 10 years
    For boundary comparison? Possibly (depends again, on what sort of images and what metric is important). Here's an example implementation from the literature: midag.cs.unc.edu/pubs/papers/MICCAI01-gerig-valmet.pdf‎