1 | % create a MIL dataset from the original WAV-files, segmentation of the |
---|
2 | % spectrograms, and computation of features on the segmented regions |
---|
3 | % |
---|
4 | % This is the new 19 species dataset from the MLSP competition |
---|
5 | |
---|
6 | % some settings: |
---|
7 | windowlen = 512; |
---|
8 | fmax = 256; |
---|
9 | intens_thr = 0.8; % remove 80% of the signal?? |
---|
10 | f_min = 2000; % frequency threshold (everything below is removed) |
---|
11 | |
---|
12 | % load the 'meta' data like labels and filenames |
---|
13 | dpath = '../birds_mlsp2013/mlsp_contest_dataset/essential_data/'; |
---|
14 | [bagid,names] = textread(fullfile(dpath,'rec_id2filename.txt'),'%n%s','headerlines',1); |
---|
15 | [bagid2,labstr] = textread(fullfile(dpath,'rec_labels_test_hidden.txt'),'%n%s','headerlines',1); |
---|
16 | [bagid3,Itst] = textread(fullfile(dpath,'CVfolds_2.txt'),'%n%n',... |
---|
17 | 'delimiter',',','headerlines',1); |
---|
18 | |
---|
19 | |
---|
20 | %[bagid3,Itst] = |
---|
21 | %textread(fullfile(dpath,'CVfolds_2.txt'),'%n%d','headerlines',1); |
---|
22 | |
---|
23 | %VC: Ik krijg hier foutmeldingen. textread gaat weg, dus ze raden aan om |
---|
24 | %textscan te gebruiken. |
---|
25 | %>Error using dataread |
---|
26 | %>Trouble reading integer from file (row 1, field 2) ==> ,1\n |
---|
27 | %>Error in textread (line 175) |
---|
28 | %>[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1> |
---|
29 | |
---|
30 | |
---|
31 | N = length(bagid2); |
---|
32 | CVfile = fopen(fullfile(dpath,'CVfolds_2.txt')); |
---|
33 | CVdata = textscan(CVfile, '%f,%f', N, 'headerlines',1); |
---|
34 | fclose(CVfile); |
---|
35 | |
---|
36 | bagid3 = CVdata{1}; |
---|
37 | Itst = CVdata{2}; |
---|
38 | |
---|
39 | |
---|
40 | if any(bagid~=bagid2) |
---|
41 | error('Bagid''s do not match.'); |
---|
42 | end |
---|
43 | G = fspecial('gaussian',[5 5],2); |
---|
44 | |
---|
45 | % run over the files, and get the features: |
---|
46 | B = size(bagid,1); |
---|
47 | x = cell(B,1); |
---|
48 | baglab = zeros(B,13); |
---|
49 | instlab = ''; |
---|
50 | bagid = []; |
---|
51 | for i=1:B |
---|
52 | %load the signal; |
---|
53 | [signal,fs] = wavread(fullfile(dpath,'src_wavs',names{i}(2:end))); |
---|
54 | [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs); |
---|
55 | % smooth and threshold the spectrogram: |
---|
56 | I = imfilter(abs(S),G,'same'); |
---|
57 | mask = (I>dd_threshold(I(:),intens_thr)); |
---|
58 | mask(f<f_min) = 0; |
---|
59 | % find interesting regions: |
---|
60 | props = regionprops(bwlabel(mask),abs(S)); |
---|
61 | bloblab = bwlabel(mask); |
---|
62 | Nseg = max(unique(bloblab)); |
---|
63 | |
---|
64 | % run over blobs: |
---|
65 | im = abs(S); |
---|
66 | thisx = zeros(Nseg,7); |
---|
67 | for j=1:Nseg |
---|
68 | ix = (bloblab==j); |
---|
69 | % compute/add some blob-properties: |
---|
70 | thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox]; |
---|
71 | % don't forget: |
---|
72 | %bagid(end+1) = i; |
---|
73 | |
---|
74 | bagid = [bagid i]; |
---|
75 | |
---|
76 | end |
---|
77 | x{i} = thisx; |
---|
78 | |
---|
79 | %Get the labels right for the training bags: |
---|
80 | |
---|
81 | if ~Itst(i) |
---|
82 | eval(['baglab(i,[',labstr{i}(2:end),']+1)=1;']); |
---|
83 | end |
---|
84 | end |
---|
85 | |
---|
86 | % create a dataset |
---|
87 | a = genmil(x); |
---|
88 | % add the labels one by one: |
---|
89 | ll = [... |
---|
90 | 'BRCR-Brown Creeper '; |
---|
91 | 'PAWR-Pacific Wren '; |
---|
92 | 'PSFL-Pacific-slope Flycatcher '; |
---|
93 | 'RBNU-Red-breasted Nuthatch '; |
---|
94 | 'DEJU-Dark-eyed Junco '; |
---|
95 | 'OSFL-Olive-sided Flycatcher '; |
---|
96 | 'HETH-Hermit Thrush '; |
---|
97 | 'CBCH-Chestnut-backed Chickadee'; |
---|
98 | 'VATH-Varied Thrush '; |
---|
99 | 'HEWA-Hermit Warbler '; |
---|
100 | 'SWTH-Swainsons Thrush '; |
---|
101 | 'HAFL-Hammonds Flycatcher '; |
---|
102 | 'WETA-Western Tanager '; |
---|
103 | 'BHGB-Black-headed Grosbeak '; |
---|
104 | 'GCKI-Golden Crowned Kinglet '; |
---|
105 | 'WAVI-Warbling Vireo '; |
---|
106 | 'MGWA-MacGillivrays Warbler '; |
---|
107 | 'STJA-Stellars Jay '; |
---|
108 | 'CONI-Common Nighthawk ']; |
---|
109 | |
---|
110 | |
---|
111 | for i=1:size(baglab,2) |
---|
112 | I = ismember(bagid,find(baglab(:,i))); |
---|
113 | a = addlabels(a,genmillabels(I',1),ll(i,:)); |
---|
114 | end |
---|
115 | % set it to the first bird: |
---|
116 | a = changelablist(a,2); |
---|
117 | thisll = getlablistnames(a); |
---|
118 | a = setname(a,strtrim(thisll(curlablist(a),:))); |
---|
119 | |
---|
120 | J = Itst(bagid); |
---|
121 | x = a(~J,:); |
---|
122 | z = a(logical(J),:); |
---|
123 | save('birds20130709.mat', 'a', 'x', 'z', 'Itst', 'J'); |
---|