-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathINRIAImages.m
226 lines (195 loc) · 6.94 KB
/
INRIAImages.m
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
function [] = INRIAImages()
% Detection and segmentation of elongated structures in images
%
% Version: v1.0
% Author: Nicola Strisciuglio ([email protected])
%
% Application of the B-COSFIRE filters for detection of elongated
% structures in images.
%
% This code provides the benchmark results on the images of the INRIA line network data
% set used in the paper Strisciuglio, N. Petkov, N. Delineation of line patterns in
% images using B-COSFIRE filters, IWOBI 2017".
%
% If you use this software please cite the following paper:
%
% George Azzopardi, Nicola Strisciuglio, Mario Vento, Nicolai Petkov,
% Trainable COSFIRE filters for vessel delineation with application to retinal images,
% Medical Image Analysis, Volume 19 , Issue 1 , 46 - 57, ISSN 1361-8415
%
% Strisciuglio, N. Petkov, N. "Delineation of line patterns in images
% using B-COSFIRE filters", IWOBI 2017
if ~isdeployed
addpath('./COSFIRE');
addpath('./Gabor');
addpath('./Performance');
addpath('./Preprocessing');
end
% NOTE: It requires a compiled mex-file of the fast implementation
% of the max-blurring function.
if ~exist('./COSFIRE/dilate')
BeforeUsing();
end
%% Process images
LEAF = 1;
ROAD = 2;
RIVER = 3;
TILE = 4;
images = [LEAF, ROAD, RIVER, TILE];
for n = 1:numel(images)
[dname, eval_radius, params] = GetParameters(images(n));
disp(['Processing image: ' dname]);
[img, response, GT, mask] = ProcessImage(images(n), dname, params);
[th, tpr, fpr, mcc] = ComputePerformance(response, GT, mask, eval_radius);
figure;
subplot(1,3,1); imagesc(img); axis off; axis image; title(['Image: ' dname]);
subplot(1,3,2); imagesc(response); colormap gray; axis off; axis image; title('B-COSFIRE response');
subplot(1,3,3); imagesc((rescaleImage(response, 0, 255) + 1) .* mask > th); colormap gray; axis off; axis image; title(['Binary - Mcc: ' num2str(mcc)]);
disp(['TPR: ' num2str(tpr) ' - FPR: ' num2str(fpr) ' - MCC: ' num2str(mcc)]);
end
end
function [imageInput, response, GT, mask] = ProcessImage(dataset, dname, params)
datasetpath = './data/INRIA_line_networks/';
LEAF = 1;
ROAD = 2;
RIVER = 3;
TILE = 4;
%% B-COSFIRE filter configuration
% Symmetric filter params and configuration
x = 101; y = 101; % center
line1(:, :) = zeros(201);
line1(:, x) = 1; %prototype line
symmfilter = cell(1);
symm_params = SystemConfig;
% COSFIRE params
symm_params.inputfilter.DoG.sigmalist = params.sigma;
symm_params.COSFIRE.rholist = 0:2:params.len;
symm_params.COSFIRE.sigma0 = params.sigma0 / 6;
symm_params.COSFIRE.alpha = params.alpha / 6;
% Orientations
symm_params.invariance.rotation.psilist = 0 : pi / params.noriens : pi - pi / params.noriens;
% Configuration
symmfilter{1} = configureCOSFIRE(line1, round([y x]), symm_params);
% Prepare the filter set
filterset(1) = symmfilter;
% Inhibitory part configuration
% if inhibFactor ~= 0
% inhibSymmfilter{1} = symmfilter{1};
% inhibSymmfilter{1}.tuples(1,:) = 0;
% inhibSymmfilter{1}.tuples(2,:) = inhibSymmfilter{1}.tuples(2,:) * stdFactor;
% filterset(2) = inhibSymmfilter;
% end
%% Processing
imageInput = double(imread([datasetpath dname '/' dname '.bmp'])) ./ 255;
if size(imageInput, 3) > 1
imageInput = rgb2gray(imageInput);
end
%imageInput = double(imageInput) ./ 255;
if dataset == RIVER || dataset == TILE
imageInput = imcomplement(imageInput);
end
% Read the corresponding ground-truth
GT = double(imread([datasetpath dname '/' dname '_GT.bmp'])) ./ 255;
if size(GT, 3) > 1
GT = GT(:, :, 1);
end
GT = imcomplement(GT);
% Prepare input image
if dataset == ROAD
imageInput = imresize(imageInput, size(GT));
end
% Prepare mask
mask = ones(size(imageInput, 1), size(imageInput, 2), 1);
if dataset == LEAF
mask = double(rgb2gray(imread([datasetpath dname '/' dname '_mask.bmp']))) ./ 255;
end
% Pad input image to avoid border effects
NP = 50;
imageInput = padarray(imageInput, [NP NP], 'replicate');
%% Filter response
%tic;
%response = applyCOSFIRE(imageInput, filterset);
tuple = computeTuples(imageInput, filterset);
response = applyCOSFIRE_inhib(imageInput, filterset, 0, tuple);
%toc;
response = response{1};
% unpad response image
response = response(NP+1:end-NP, NP+1:end-NP);
% unpad original image
imageInput = imageInput(NP+1:end-NP, NP+1:end-NP);
end
function [dbname, eval_radius, params] = GetParameters(dataset)
% These parameters are reported in the paper:
% Strisciuglio, N. Petkov, N. "Delineation of line patterns in images
% using B-COSFIRE filters", IWOBI 2017
LEAF = 1;
ROAD = 2;
RIVER = 3;
TILE = 4;
if dataset == LEAF
dbname = 'leaf';
eval_radius = 0;
params.sigma = 2.9;
params.len = 10;
params.sigma0 = 2;
params.alpha = 0.8;
params.noriens = 12;
elseif dataset == ROAD
dbname = 'road';
eval_radius = 1;
params.sigma = 1.7;
params.len = 22;
params.sigma0 = 4;
params.alpha = 1.1;
params.noriens = 12;
elseif dataset == RIVER
dbname = 'river';
eval_radius = 0;
params.sigma = 2.4;
params.len = 12;
params.sigma0 = 3;
params.alpha = 0.8;
params.noriens = 12;
elseif dataset == TILE
dbname = 'tiles';
eval_radius = 0;
params.sigma = 1.4;
params.len = 8;
params.sigma0 = 2;
params.alpha = 0.4;
params.noriens = 12;
end
end
function [threshold, tpr, fpr, mcc] = ComputePerformance(response, GT, mask, eval_radius)
scaledresp = rescaleImage(response, 0, 255);
numth = numel(0:255);
TPR = [];
FPR = [];
MCC = [];
% CAL = [];
%RESULTS = [];
for j = 1:numth
binresp = (scaledresp + 1 > j) .* mask;
% Standard evaluation metrics
thresult = EvaluateINRIA(binresp, GT, eval_radius);
% CAL
% [SG, gtdil, gtthin] = getGTInfo(binresp, GT, mask);
% [calTMP, ~, ~, ~] = CAL_evaluate_binary(binresp, GT, mask, SG, gtdil, gtthin);
% Results accumulation
%RESULTS = [RESULTS; thresult];
FPR = [FPR thresult(5)];
TPR = [TPR thresult(6)];
MCC = [MCC thresult(7)];
%CAL = [CAL calTMP];
binresp = [];
end
% Best threshold (trade-off TPR and FPR)
% D = sqrt((ones(1, numth) - TPR).^2 + FPR.^2);
% [m, thopt] = min(D);
% res = [thopt RESULTS(thopt, :);];
% Best threshold (the one that maximizes MCC)
[mcc, threshold] = max(MCC);
tpr = TPR(threshold);
fpr = FPR(threshold);
%res_mcc = [thmcc RESULTS(thmcc, :)]; % CAL(thmcc)];
end