├── Ground Truth ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── Lecture 2. Shape Modelling.pdf ├── Original Images ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── README.md ├── Script.m ├── alg1 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── alg2 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── alg3 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── alg4 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── alg5 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── alg6 ├── rdb005ll.tif ├── rdb023ll.tif ├── rdb025ll.tif └── rdb028rl.tif ├── coefficients.m ├── confusion.m └── script_Noor_MIA_Lab1.m /Ground Truth/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Ground Truth/rdb005ll.tif -------------------------------------------------------------------------------- /Ground Truth/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Ground Truth/rdb023ll.tif -------------------------------------------------------------------------------- /Ground Truth/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Ground Truth/rdb025ll.tif -------------------------------------------------------------------------------- /Ground Truth/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Ground Truth/rdb028rl.tif -------------------------------------------------------------------------------- /Lecture 2. Shape Modelling.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Lecture 2. Shape Modelling.pdf -------------------------------------------------------------------------------- /Original Images/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Original Images/rdb005ll.tif -------------------------------------------------------------------------------- /Original Images/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Original Images/rdb023ll.tif -------------------------------------------------------------------------------- /Original Images/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Original Images/rdb025ll.tif -------------------------------------------------------------------------------- /Original Images/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/Original Images/rdb028rl.tif -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Implementing-Active-contour-model-Snakes-Algorithm- 2 | Active contour model, also called snakes, is a framework in computer vision for delineating an object outline from a possibly noisy 2D image. The snakes model is popular in computer vision, and snakes are greatly used in applications like object tracking, shape recognition, segmentation, edge detection and stereo matching. 3 | -------------------------------------------------------------------------------- /Script.m: -------------------------------------------------------------------------------- 1 | %% script 2 | clc 3 | clear 4 | close all; 5 | 6 | 7 | % Initializing cells to store images from all 6 algorithms 8 | 9 | IM_A1={}; 10 | IM_A2={}; 11 | IM_A3={}; 12 | IM_A4={}; 13 | IM_A5={}; 14 | IM_A6={}; 15 | IM_G={}; 16 | 17 | % Directory names 18 | Alg1 = dir('alg1/*.tif'); 19 | Alg2 = dir('alg2/*.tif'); 20 | Alg3 = dir('alg3/*.tif'); 21 | Alg4 = dir('alg4/*.tif'); 22 | Alg5 = dir('alg5/*.tif'); 23 | Alg6 = dir('alg6/*.tif'); 24 | G = dir('Ground Truth/*.tif'); 25 | 26 | % For loop to store images in the cells 27 | for k = 1:length(Alg1) 28 | filename = ['alg1\' Alg1(k).name]; 29 | I = imread(filename); 30 | IM_A1{k}=I; 31 | 32 | filename = ['alg2\' Alg2(k).name]; 33 | I = imread(filename); 34 | IM_A2{k}=I; 35 | 36 | filename = ['alg3\' Alg3(k).name]; 37 | I = imread(filename); 38 | IM_A3{k}=I; 39 | 40 | filename = ['alg4\' Alg4(k).name]; 41 | I = imread(filename); 42 | IM_A4{k}=I; 43 | 44 | filename = ['alg5\' Alg5(k).name]; 45 | I = imread(filename); 46 | IM_A5{k}=I; 47 | 48 | filename = ['alg1\' Alg6(k).name]; 49 | I = imread(filename); 50 | IM_A6{k}=I; 51 | 52 | filename = ['Ground Truth\' G(k).name]; 53 | I = imread(filename); 54 | IM_G{k}=I; 55 | 56 | end 57 | 58 | % Threshold values. provided between the range 0-1 59 | threshold = 0.05:0.05:1; 60 | 61 | % Allocating memory for matrices holding TP, TN, FP FN values for all 62 | % thresholds. Will be used to calculate similarity/dissimilarity measures. 63 | 64 | vals_A1 = zeros(length(threshold),length(IM_G)); 65 | vals_A2 = zeros(length(threshold),length(IM_G)); 66 | vals_A3 = zeros(length(threshold),length(IM_G)); 67 | vals_A4 = zeros(length(threshold),length(IM_G)); 68 | vals_A5 = zeros(length(threshold),length(IM_G)); 69 | vals_A6 = zeros(length(threshold),length(IM_G)); 70 | 71 | % Loop to calculate sensitivity and fp rate and TP, TN ,FP, FN values for all images at each 72 | % threshold value 73 | for i =1:length(IM_G) 74 | 75 | for j = 1 : length(threshold) 76 | 77 | [S_A1(i,j), FP_A1(i,j) vals_A1(j,:)] = confusion (IM_A1{i}, IM_G{i} , threshold(j)); 78 | 79 | [S_A2(i,j), FP_A2(i,j) vals_A2(j,:)] = confusion (IM_A2{i}, IM_G{i} , threshold(j)); 80 | 81 | [S_A3(i,j), FP_A3(i,j) vals_A3(j,:)] = confusion (IM_A3{i}, IM_G{i} , threshold(j)); 82 | 83 | [S_A4(i,j), FP_A4(i,j) vals_A4(j,:)] = confusion (IM_A4{i}, IM_G{i} , threshold(j)); 84 | 85 | [S_A5(i,j), FP_A5(i,j) vals_A5(j,:)] = confusion (IM_A5{i}, IM_G{i} , threshold(j)); 86 | 87 | [S_A6(i,j), FP_A6(i,j) vals_A6(j,:)] = confusion (IM_A6{i}, IM_G{i} , threshold(j)); 88 | 89 | 90 | end 91 | end 92 | 93 | 94 | % Plotting 95 | figure 96 | plot(FP_A1(1,:),S_A1(1,:),'r'); 97 | hold on 98 | plot(FP_A1(2,:),S_A1(2,:),'g'); 99 | hold on 100 | plot(FP_A1(3,:),S_A1(3,:),'b'); 101 | plot(FP_A1(4,:),S_A1(4,:),'y'); 102 | title('ROCs for algorithm 1'); 103 | xlabel('FP rate'); 104 | ylabel('Specifivity'); 105 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 106 | axis([0 0.02 0 0.6]) 107 | 108 | 109 | figure 110 | plot(FP_A2(1,:),S_A2(1,:),'r'); 111 | hold on 112 | plot(FP_A2(2,:),S_A2(2,:),'g'); 113 | plot(FP_A2(3,:),S_A2(3,:),'b'); 114 | hold on 115 | plot(FP_A2(4,:),S_A2(4,:),'y'); 116 | title('ROCs for algorithm 2'); 117 | xlabel('FP rate'); 118 | ylabel('Specifivity'); 119 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 120 | axis([0 0.02 0 0.6]) 121 | 122 | 123 | figure 124 | plot(FP_A3(1,:),S_A3(1,:),'r'); 125 | hold on 126 | plot(FP_A3(2,:),S_A3(2,:),'g'); 127 | plot(FP_A3(3,:),S_A3(3,:),'b'); 128 | plot(FP_A3(4,:),S_A3(4,:),'y'); 129 | title('ROCs for algorithm 3'); 130 | xlabel('FP rate'); 131 | ylabel('Specifivity'); 132 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 133 | axis([0 0.02 0 0.6]) 134 | 135 | 136 | figure 137 | plot(FP_A4(1,:),S_A4(1,:),'r'); 138 | hold on 139 | plot(FP_A4(2,:),S_A4(2,:),'g'); 140 | hold on 141 | plot(FP_A4(3,:),S_A4(3,:),'b'); 142 | hold on 143 | plot(FP_A4(4,:),S_A4(4,:),'y'); 144 | title('ROCs for algorithm 4'); 145 | xlabel('FP rate'); 146 | ylabel('Specifivity'); 147 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 148 | axis([0 0.02 0 0.6]) 149 | 150 | 151 | 152 | figure 153 | plot(FP_A5(1,:),S_A5(1,:),'r'); 154 | hold on 155 | plot(FP_A5(2,:),S_A5(2,:),'g'); 156 | hold on 157 | plot(FP_A5(3,:),S_A5(3,:),'b'); 158 | hold on 159 | plot(FP_A5(4,:),S_A5(4,:),'y'); 160 | title('ROCs for algorithm 5'); 161 | xlabel('FP rate'); 162 | ylabel('Specifivity'); 163 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 164 | axis([0 0.02 0 0.6]) 165 | 166 | 167 | figure 168 | plot(FP_A6(1,:),S_A6(1,:),'r'); 169 | hold on 170 | plot(FP_A6(2,:),S_A6(2,:),'g'); 171 | hold on 172 | plot(FP_A6(3,:),S_A6(3,:),'b'); 173 | hold on 174 | plot(FP_A6(4,:),S_A6(4,:),'y'); 175 | title('ROCs for algorithm 6'); 176 | xlabel('FP rate'); 177 | ylabel('Specifivity'); 178 | legend('IMG 1','IMG 2', 'IMG 3', 'IMG 4'); 179 | axis([0 0.02 0 0.6]) 180 | 181 | 182 | [jaccard dice] = coefficients(vals_A1, 1); 183 | -------------------------------------------------------------------------------- /alg1/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg1/rdb005ll.tif -------------------------------------------------------------------------------- /alg1/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg1/rdb023ll.tif -------------------------------------------------------------------------------- /alg1/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg1/rdb025ll.tif -------------------------------------------------------------------------------- /alg1/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg1/rdb028rl.tif -------------------------------------------------------------------------------- /alg2/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg2/rdb005ll.tif -------------------------------------------------------------------------------- /alg2/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg2/rdb023ll.tif -------------------------------------------------------------------------------- /alg2/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg2/rdb025ll.tif -------------------------------------------------------------------------------- /alg2/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg2/rdb028rl.tif -------------------------------------------------------------------------------- /alg3/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg3/rdb005ll.tif -------------------------------------------------------------------------------- /alg3/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg3/rdb023ll.tif -------------------------------------------------------------------------------- /alg3/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg3/rdb025ll.tif -------------------------------------------------------------------------------- /alg3/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg3/rdb028rl.tif -------------------------------------------------------------------------------- /alg4/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg4/rdb005ll.tif -------------------------------------------------------------------------------- /alg4/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg4/rdb023ll.tif -------------------------------------------------------------------------------- /alg4/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg4/rdb025ll.tif -------------------------------------------------------------------------------- /alg4/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg4/rdb028rl.tif -------------------------------------------------------------------------------- /alg5/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg5/rdb005ll.tif -------------------------------------------------------------------------------- /alg5/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg5/rdb023ll.tif -------------------------------------------------------------------------------- /alg5/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg5/rdb025ll.tif -------------------------------------------------------------------------------- /alg5/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg5/rdb028rl.tif -------------------------------------------------------------------------------- /alg6/rdb005ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg6/rdb005ll.tif -------------------------------------------------------------------------------- /alg6/rdb023ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg6/rdb023ll.tif -------------------------------------------------------------------------------- /alg6/rdb025ll.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg6/rdb025ll.tif -------------------------------------------------------------------------------- /alg6/rdb028rl.tif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mohitkumarahuja/Implementing-Active-contour-model-Snakes-Algorithm-/f55c62edcc9fc492f0e54a67e735640e98865837/alg6/rdb028rl.tif -------------------------------------------------------------------------------- /coefficients.m: -------------------------------------------------------------------------------- 1 | function [jaccard dice] = coefficients (values, threshold) 2 | jaccard = 0; 3 | dice = 0; 4 | 5 | TP = values(threshold,1); 6 | TN = values(threshold,2); 7 | FP = values(threshold,3); 8 | FN = values(threshold,4); 9 | 10 | jaccard = TP/(FP+FN-TP); 11 | -------------------------------------------------------------------------------- /confusion.m: -------------------------------------------------------------------------------- 1 | function [sensitivity fpRate values] = confusion(Alg_image, ground_truth, threshold) 2 | 3 | %initializing values to zero 4 | 5 | TP = 0; 6 | TN =0; 7 | FP = 0; 8 | FN = 0; 9 | sensitivity = 0; 10 | specificity = 0; 11 | 12 | %thresholding the input image at the provided threshold 13 | Alg_image = im2bw(Alg_image, threshold); 14 | 15 | %converting the ground truth image into a binary image 16 | ground_truth = im2bw (ground_truth,0); 17 | 18 | 19 | %calculating TP, FP,TN and FN values 20 | for i = 1:size(Alg_image,1) 21 | for j = 1: size(ground_truth,2) 22 | 23 | if (Alg_image(i,j) == 1 && ground_truth(i,j) == 1) 24 | TP = TP+1; 25 | 26 | else if (Alg_image(i,j) == 0 && ground_truth(i,j) == 0) 27 | 28 | TN = TN + 1; 29 | 30 | else if (Alg_image(i,j) == 1 && ground_truth(i,j) == 0) 31 | 32 | FP = FP + 1; 33 | 34 | else if (Alg_image(i,j) == 0 && ground_truth(i,j) == 1) 35 | 36 | FN = FN + 1 ; 37 | 38 | 39 | end 40 | end 41 | end 42 | end 43 | end 44 | end 45 | 46 | %return sensitivity and fp rate at the nd of loop 47 | values = [TP TN FP FN]; 48 | sensitivity = TP /(TP+FN); 49 | fpRate = (FP / (FP + TN)); % false positive 50 | end 51 | -------------------------------------------------------------------------------- /script_Noor_MIA_Lab1.m: -------------------------------------------------------------------------------- 1 | %% Algorithm 1 2 | 3 | VALUES = []; 4 | 5 | for k=1:17 6 | 7 | % Image 1 8 | A1I1 = imread('alg1/rdb005ll.tif'); 9 | A1G1 = imread('Ground Truth/rdb005ll.tif'); 10 | 11 | %histogram(A1I1); 12 | TG = 0; 13 | A1G1 = im2bw(A1G1, TG); 14 | 15 | 16 | T = [0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.75 0.8 0.85]; 17 | A1I1 = im2bw(A1I1, T(k)); 18 | 19 | % A1I1 = wthresh(A1I1, 's', T); 20 | 21 | TP = 0; 22 | FP = 0; 23 | FN = 0; 24 | TN = 0; 25 | 26 | for i=1:1080 27 | for j=1:650 28 | if(A1I1(i,j) == 1 && A1G1(i,j) == 1) 29 | TP = TP + 1; 30 | elseif(A1I1(i,j) == 0 && A1G1(i,j) == 0) 31 | TN = TN + 1; 32 | elseif(A1I1(i,j) == 1 && A1G1(i,j) == 0) 33 | FP = FP + 1; 34 | elseif(A1I1(i,j) == 0 && A1G1(i,j) == 1) 35 | FN = FN + 1; 36 | end 37 | end 38 | end 39 | VALUES = [VALUES; TP FP FN TN]; 40 | end 41 | 42 | 43 | RATES = []; % [TP_rate FP_rate] == [Sensitivity 1-Specificity] 44 | for k=1:17 45 | V = VALUES(k,:); 46 | TP_rate = V(1)/(V(1)+V(3)); 47 | FP_rate = V(2)/(V(2)+V(4)); 48 | RATES = [RATES; TP_rate FP_rate]; 49 | end 50 | 51 | figure(2); 52 | plot(RATES(:,2), RATES(:,1)); 53 | 54 | 55 | --------------------------------------------------------------------------------