[088209]: / combinedDeepLearningActiveContour / functions / DiceSimilarity2DImage.m

Download this file

44 lines (33 with data), 1.3 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
%by Dr. Rex Cheung
%cheung.r100@gmail.com
%This programs calculate and visualize the dice similarity (volume overlap) of 2D binary images.
%This program is useful for quantifying the accuracy of 2D image
%registration using DICE similarity (see wikipedia):
% Dice Coef = 2*intersect(A,B)/(absolute(A)+absolute(B))
%This program also allows users to see the parts that are not registrated
%to guide further refinement registration.
function [OverlapImage DiceCoef] = DiceSimilarity2DImage(img1, img2)
%The steps are:
%1. set one image non-zero values as 200
%img1(img1>0)=200;
img1=200*img1;
%2. set second image non-zero values as 300
%img2(img2>0)=300;
img2=300*img2;
%3. set overlap area 100
OverlapImage = img2-img1;
%4. count the overlap100 pixels
[r,c,v] = find(OverlapImage==100);
countOverlap100=size(r);
%5. count the image200 pixels
[r1,c1,v1] = find(img1==200);
img1_200=size(r1);
%6. count the image300 pixels
[r2,c2,v2] = find(img2==300);
img2_300=size(r2);
%7. calculate Dice Coef
DiceCoef = 2*countOverlap100/(img1_200+img2_300);
%8. visualize the volumes by slicing
%figure(1);image(OverlapImage);colormap(gray);title('Overlapping area used to calculate Dice Coef')
%command
% [a b]=DiceSimilarity2DImage(cropprostmask1,cropprostmask2)