forked from iN1k1/CVPR2012
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NM_reid_wcnwasa12_compute_signature.m
151 lines (122 loc) · 5.56 KB
/
NM_reid_wcnwasa12_compute_signature.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
function [signatures] = NM_reid_wcnwasa12_compute_signature(dataset, pars)
% COMPUTE SIGNATURES
%
% Author: Niki Martinel
% Copyright: Niki Martinel, 2012
%
fprintf('Computing signatures...');
t_reid_feature_extraction_all = tic;
% Update width and height of images according to pars.dataset.imageMagFactor value
pars.dataset.imageWidth = pars.dataset.imageWidth * pars.dataset.imageMagFactor;
pars.dataset.imageHeight = pars.dataset.imageHeight * pars.dataset.imageMagFactor;
% Set features parameters
phogPars.bin = pars.phog.bins;
phogPars.angle = pars.phog.angle;
phogPars.levels = pars.phog.levels;
phogPars.roi = [];
phogPars.evaluateDifferentChannels = true;
% Set SIFT feature parameters
wgchPars.points = pars.sift.points;
wgchPars.displayImage = false;
wgchPars.plotFrame = false;
wgchPars.plotDescriptors = false;
wgchPars.levels = pars.sift.levels;
wgchPars.colorRadius = pars.wgch.radius;
wgchPars.colorMeanAndHist = true;
wgchPars.colorHistBin = pars.wgch.colorHistBin;
if isfield(pars.wgch, 'gaussianKernelSigma')
wgchPars.gaussianKernelSigma = pars.wgch.gaussianKernelSigma;
end
% Haralick pars
harPars.offsetmat = pars.glcm.offsetmat;
harPars.levels = pars.glcm.grayLevels;
harPars.symmetric = pars.glcm.symmetry;
harPars.computeForEachLevel = pars.haralick.computeForEachLevel;
harPars.meanValues = true;
harPars.type = pars.haralick.type;
if pars.reid.beta == 0
harPars = [];
end
%% ------------------------------------------------------------------------
% LOAD DATA
signaturesFile = fullfile(pars.settings.outputDataFolder, [pars.settings.outputFilePrefix '_signatures.mat']);
if exist(signaturesFile, 'file')
load(signaturesFile);
else
%% --------------------------------------------------------------------
% IMAGE PRE-PROCESSING
% Squared structuring element used to open/close image
squaredSE = strel('square', 3);
% Resize all dataset images if mag factor is bigger than one
if pars.dataset.imageMagFactor > 1
tmpImages = zeros(pars.dataset.imageHeight, pars.dataset.imageWidth, 3, dataset.count, 'double');
for i=1:dataset.count
tmpImages(:,:,:,i) = double(imresize(dataset.images(:,:,:, i), pars.dataset.imageMagFactor))/255;
end
dataset.images = tmpImages;
clear tmpImages;
% Load mask or set mask to be the complete image
tmpMasks = ones(pars.dataset.imageHeight, pars.dataset.imageWidth, dataset.count, 'double');
if isfield(pars.reid, 'useMasks') && pars.reid.useMasks
for i=1:dataset.count
tmpMasks(:,:,i) = NM_binarization(imresize(dataset.masks(:,:,i),pars.dataset.imageMagFactor), 0.5);
end
end
dataset.masks = tmpMasks;
clear tmpMasks;
else
dataset.images = double(dataset.images)/255;
end
for i=1:dataset.count
% Remove possible noise and fill gaps
dataset.masks(:,:,i) = imfill(dataset.masks(:,:,i), 'holes');
dataset.masks(:,:,i) = imerode(dataset.masks(:,:,i), squaredSE);
dataset.masks(:,:,i) = imdilate(dataset.masks(:,:,i), squaredSE);
end
%% --------------------------------------------------------------------
% FEATURES EXTRACTION
% Create waiting bar for feature extraction process
hWaitingReidExtraction = waitbar(0, 'Please wait while extracting features');
%% IMAGE PROCESSING
maskedImagePHOG = zeros(size(dataset.images(:,:,:,1)));
maskedImageGLCM = zeros(size(dataset.images(:,:,:,1)));
maskedImageSIFT = zeros(size(dataset.images(:,:,:,1)));
maskedImageWGCH = zeros(size(dataset.images(:,:,:,1)));
% Loop through all dataset images to extract features
for i=1:dataset.count
% -----------------------------------------------------------------
% Main feature extraction part
% Compute masked and color converted images
[maskedImagePHOG, maskedImageGLCM, maskedImageSIFT, maskedImageWGCH] = NM_reid_wcnwasa12_images( dataset.images(:,:,:,i), dataset.masks(:,:,i), pars);
% Divide upper and lower body part
[torso, legs, head] = NM_div3parts( dataset.images(:,:,:,i), dataset.masks(:,:,i) );
% Extract kernel map
kernelMap = NM_reid_person_kernelmap( dataset.masks(:,:,i), torso, legs, head, pars.wgch.kernelType);
% Extract features
if i == 1
[phogFeatures, ~, ~] = NM_reid_wcnwasa12_extractfeatures( maskedImagePHOG, ...
maskedImageGLCM, maskedImageSIFT, maskedImageWGCH, ...
dataset.masks(:,:,i), phogPars, wgchPars, harPars, ...
kernelMap );
signatures.phogFeatures = zeros(size(phogFeatures,1), size(phogFeatures,2), dataset.count);
end
[signatures.phogFeatures(:,:,i), signatures.siftFeatures(i), ...
signatures.haralickFeatures(i)] = NM_reid_wcnwasa12_extractfeatures( maskedImagePHOG,...
maskedImageGLCM, maskedImageSIFT, maskedImageWGCH, ...
dataset.masks(:,:,i), phogPars, wgchPars, harPars, ...
kernelMap, torso, legs );
% Step waiting bar
waitbar(i/dataset.count, hWaitingReidExtraction);
end %End for dataset.count
% Close feature extraction waiting bar
close(hWaitingReidExtraction);
% Save data
try
save(signaturesFile, 'signatures');
catch ME
warning('nm_reid_main:saveSignatures', 'Unable to save signatures data on file %s.', signaturesFile)
end
end
% Features extraction time
fprintf('done in %.2f(s)\n', toc(t_reid_feature_extraction_all));
end