-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathone_image_one_bag.m
73 lines (67 loc) · 2.85 KB
/
one_image_one_bag.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
function [bag,label] = one_image_one_bag(soilfileParameter,rootfileParameter,trainparameters)
% one_image_one_bag: generate training data for the case that each image is a bag
% Syntax: [bag,label] = one_image_one_bag(soilfileParameter,rootfileParameter,trainparameters)
%
% Inputs:
% soilfileParameter - structure - the following fields in the structure:
% (1)soilfileParameter.filelist.totfilecnt: totle number of training image that having no root
% rootfileParameter - sturcture - the following fields in the structure:
% (1)rootfileParameter.filelist.totfilecnt: totle number of training image that having root
% trainparameters - structure - the following fields in the structure:
% (1)trainparameters.featurenormalize : scale feature
% Outputs:
% bag - array of cell array - each cell is an array contains all features of instance in the bag
% label - vector - the label of each bag
%
% University of Florida, Electrical and Computer Engineering
% Email Address: [email protected]
% Latest Revision: May 5, 2019
% This product is Copyright (c) 2019 University of Florida
% All rights reserved.
bag = {};
label = [];
for iter_soiltrain = 1:soilfileParameter.filelist.totfilecnt
hist_indcell = {};
soilfile = readFileFromFolder(iter_soiltrain,soilfileParameter);
myfeatures = load(soilfile.feFileName);
tempfeatures = fieldnames(myfeatures);
features = myfeatures.(tempfeatures{1});
max_G = max(features(:,5));
min_G = min(features(:,5));
hist_range = min_G:(max_G-min_G)/200:max_G;
[bincounts,ind]= histc(features(:,5),hist_range);
for i = 1:max(ind)
[hist_indcell{end+1},~] = find(ind ==i);
end
super_ind = [];
for i = 1:length(hist_indcell)
if ~isempty(hist_indcell{i})
super_ind(end+1) = hist_indcell{i}(randi(size(hist_indcell{i},1)));
end
end
bag{end+1} = features(super_ind,4:end)./trainparameters.featurenormalize;
label(end+1) =0;
end
for iter_roottrain = 1:rootfileParameter.filelist.totfilecnt
hist_indcell = {};
rootfile = readFileFromFolder(iter_roottrain,rootfileParameter);
myfeatures = load(rootfile.feFileName);
tempfeatures = fieldnames(myfeatures);
features = myfeatures.(tempfeatures{1});
max_G = max(features(:,5));
min_G = min(features(:,5));
hist_range = min_G:(max_G-min_G)/200:max_G;
[bincounts,ind]= histc(features(:,5),hist_range);
for i = 1:max(ind)
[hist_indcell{end+1},~] = find(ind ==i);
end
super_ind = [];
for i = 1:length(hist_indcell)
if ~isempty(hist_indcell{i})
super_ind(end+1) = hist_indcell{i}(randi(size(hist_indcell{i},1)));
end
end
bag{end+1} = features(super_ind,4:end)./trainparameters.featurenormalize;
label(end+1) =1;
end
end