-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
209 lines (179 loc) · 8.74 KB
/
main.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
clear all; close all;
%%%%%% parameter setting
autoCharaScale = 0;
resizeImage = 1; %%% for testing automatic scalability
removeBoundaryBlobs=0;
useNonmaxsuppts = 0;
useLocalMaxima = 1-useNonmaxsuppts;
applying_watershed = 0;
eccentricityConstraint = 0;
withAnisodiff = 0;
useLogScaleNorm = 1;
alpha = 1;
sigmaStep = -1;
ellipGaussianIntensity = 25;
onlyDetectBlobCenters = 1; %%% only detect centers, no shape and ori
detectDarkBlobs = 1; %%% only detect dark blobs
detectBrightBlobs = 1; %%% only detect bright blobs
detectAllBlobs = detectDarkBlobs && detectBrightBlobs; %%% detect both
outputLoGDetection = 1;
output_gLoG_detection=detectDarkBlobs && detectBrightBlobs;
detectVanishingPoint = 1;
useSparseVotingPixels = 1; %%% whether or not only use detected blob centers for voting vanishing point
%%%%% input and output paths
imagePath = 'yourDir\images\';
outputPath = [imagePath,'outputDir\'];
if exist(outputPath,'dir')==0
mkdir(outputPath);
end
vanishing_point_output_path = [imagePath,'vanishing_point_output_sparse1\'];
if exist(vanishing_point_output_path,'dir')==0
mkdir(vanishing_point_output_path);
end
vpCoord = [];
for imageId = 1:500
if imageId<10
imageName = ['image','000', int2str(imageId), '.jpg'];
elseif imageId<100
imageName = ['image','00', int2str(imageId), '.jpg'];
elseif imageId<1000
imageName = ['image','0', int2str(imageId), '.jpg'];
else
imageName = ['image',int2str(imageId), '.jpg'];
end
imgColor=imread([imagePath,imageName]);
%%%%% output path
imageNameLen = length(imageName);
outputPath = [imagePath,'output_dominant_road_blob1\'];
outputPath = [outputPath,imageName(1:imageNameLen-4)];
imgH = size(imgColor,1);
imgW = size(imgColor,2);
if (imgH~=180)||(imgW~=240)
imgColor = imresize(imgColor,[180,240],'bilinear');
end
imgH = size(imgColor,1);
imgW = size(imgColor,2);
if size(imgColor,3) ==3
imgR = imgColor(:,:,1);
imgG = imgColor(:,:,2);
imgB = imgColor(:,:,3);
else
imgR = imgColor;
imgColor = zeros(imgH, imgW, 3);
imgColor(:,:,1) = imgR;
imgColor(:,:,2) = imgR;
imgColor(:,:,3) = imgR;
end
tic;
%%%%% preprocessing the input image
disp('preprocessing input image.................................');
if detectBrightBlobs == 1
[grayImage, grayImageCpy, binaryImage] = preprocessImage(imgColor, withAnisodiff, 'bright', outputPath);
end
if detectDarkBlobs == 1
[grayImage_Neg, grayImageCpy_Neg, binaryImage_Neg] = preprocessImage(imgColor, withAnisodiff, 'dark', outputPath);
end
disp('calculate characteristic scale (for both bright and dark blobs) of input image.................................');
%%%%% compute the characteristic scale by LoG detector and output blobs by LoG method
if autoCharaScale==1
if detectBrightBlobs == 1
%%%%% get the char scale for bright regions
[charaScale_bright,blobs_bright,blobs_trimmed_bright] = calculateCharaScale(grayImage);
%%%%% get the sigma range (largest and smallest sigma_x) for sigma_x
[largestSigma_bright,smallestSigma_bright] = getRangeOfSigmaX(charaScale_bright,4);
%%%%% output the detected bright blobs by LoG (before and after trimming)
if outputLoGDetection==1
outputDetectedBlobs_byLoG(blobs_bright, blobs_trimmed_bright, imgColor, 'bright', outputPath);
end
end
if detectDarkBlobs == 1
%%%%% get the char scale for dark regions
[charaScale_dark,blobs_dark,blobs_trimmed_dark] = calculateCharaScale(grayImage_Neg);
%%%%% get the sigma range (largest and smallest sigma_x) for sigma_x
[largestSigma_dark,smallestSigma_dark] = getRangeOfSigmaX(charaScale_dark,4);
%%%%% output the detected dark blobs by LoG (before and after trimming)
if outputLoGDetection==1
outputDetectedBlobs_byLoG(blobs_dark, blobs_trimmed_dark, imgColor, 'dark', outputPath);
end
end
%%%%% if the sigma step used for convolution is 2 or -2, we should
%%%%% make the following sigma upper and lower bounds to be even
%%%%% numbers.
% if mod(largestSigma_bright,2)~=0
% largestSigma_bright = largestSigma_bright-1;
% end
% if mod(smallestSigma_bright,2)~=0
% if (smallestSigma_bright-1>0)
% smallestSigma_bright = smallestSigma_bright-1;
% else
% smallestSigma_bright = smallestSigma_bright+1;
% end
% end
% if mod(largestSigma_dark,2)~=0
% largestSigma_dark = largestSigma_dark-1;
% end
% if mod(smallestSigma_dark,2)~=0
% if (smallestSigma_dark-1>0)
% smallestSigma_dark = smallestSigma_dark-1;
% else
% smallestSigma_dark = smallestSigma_dark+1;
% end
% end
else
%%% manually set scale parameters
largestSigma_bright = 8; %16;
smallestSigma_bright = 2; % 4;
largestSigma_dark = 8; % 16;
smallestSigma_dark = 2; % 4;
end
% [largestSigma_bright,smallestSigma_bright]
% [largestSigma_dark,smallestSigma_dark]
%%%%%% parameter settings
if detectDarkBlobs == 1
kerSize_dark = largestSigma_dark*4;
end
if detectBrightBlobs == 1
kerSize_bright = largestSigma_bright*4;
end
maxNumOfBlobs = 10000;
localMaxThr = 60;
pi = 3.14159;
thetaStep = 3.14159/9;
if detectBrightBlobs == 1
[filterScales_bright]=set_gLoG_kernels(smallestSigma_bright,largestSigma_bright,sigmaStep,thetaStep);
numOfFilters_bright = size(filterScales_bright,1);
end
if detectDarkBlobs == 1
[filterScales_dark]=set_gLoG_kernels(smallestSigma_dark,largestSigma_dark,sigmaStep,thetaStep);
numOfFilters_dark = size(filterScales_dark,1);
end
%%%%% processing dark blobs
if detectDarkBlobs == 1
disp('start detecting dark blobs................................');
[blobCenters_dark, blobCenters_far_from_border_dark, blobShapes_dark, blobOri_dark, blobShapes_oo_dark, blobOri_oo_dark]=detectBlobs_gLoG(imgColor,grayImage_Neg,binaryImage_Neg,...
largestSigma_dark,smallestSigma_dark,filterScales_dark,sigmaStep,...
thetaStep, kerSize_dark, alpha, useLogScaleNorm, applying_watershed,...
'dark', localMaxThr, maxNumOfBlobs, onlyDetectBlobCenters, outputPath);
end
if detectBrightBlobs == 1
disp('start detecting bright blobs................................');
[blobCenters_bright, blobCenters_far_from_border_bright, blobShapes_bright, blobOri_bright, blobShapes_oo_bright, blobOri_oo_bright]=detectBlobs_gLoG(imgColor,grayImage,binaryImage,...
largestSigma_bright,smallestSigma_bright,filterScales_bright,sigmaStep,...
thetaStep, kerSize_bright, alpha, useLogScaleNorm, applying_watershed,...
'bright', localMaxThr, maxNumOfBlobs, onlyDetectBlobCenters, outputPath);
end
%%%%%%% combine the detected bright and dark blobs and output results
if output_gLoG_detection==1
outputAllBobs(imgColor, blobCenters_dark, blobCenters_far_from_border_dark, blobShapes_dark, blobOri_dark, blobCenters_bright, blobCenters_far_from_border_bright, blobShapes_bright, blobOri_bright, onlyDetectBlobCenters, outputPath);
end
time_cost_for_blob_detection = toc
%%%%%%% vanishing point detection for road images based on blob centers
tic
grayImage = double(rgb2gray(imgColor));
[vpY_all,vpX_all] = vanishing_point_gLoG(grayImage, imgColor, 36, largestSigma_bright, smallestSigma_bright, ...
largestSigma_dark, smallestSigma_dark, blobCenters_dark, blobCenters_bright, useSparseVotingPixels, ...
vanishing_point_output_path, imageId);
time_cost_for_vanishing_point_detection = toc
vpCoord = [vpCoord; vpY_all vpX_all];
end
save('vp_dominant_blob1.mat', 'vpCoord', '-mat');