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 | |
---|
17 | |
---|
18 | %[bagid3,Itst] = |
---|
19 | %textread(fullfile(dpath,'CVfolds_2.txt'),'%n%d','headerlines',1); |
---|
20 | |
---|
21 | %VC: Ik krijg hier foutmeldingen. textread gaat weg, dus ze raden aan om |
---|
22 | %textscan te gebruiken. |
---|
23 | %>Error using dataread |
---|
24 | %>Trouble reading integer from file (row 1, field 2) ==> ,1\n |
---|
25 | %>Error in textread (line 175) |
---|
26 | %>[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1> |
---|
27 | |
---|
28 | |
---|
29 | N = length(bagid2); |
---|
30 | CVfile = fopen(fullfile(dpath,'CVfolds_2.txt')); |
---|
31 | CVdata = textscan(CVfile, '%f,%f', N, 'headerlines',1); |
---|
32 | fclose(CVfile); |
---|
33 | |
---|
34 | bagid3 = CVdata{1}; |
---|
35 | Itst = CVdata{2}; |
---|
36 | |
---|
37 | |
---|
38 | if any(bagid~=bagid2) |
---|
39 | error('Bagid''s do not match.'); |
---|
40 | end |
---|
41 | G = fspecial('gaussian',[5 5],2); |
---|
42 | |
---|
43 | % run over the files, and get the features: |
---|
44 | B = size(bagid,1); |
---|
45 | x = cell(B,1); |
---|
46 | baglab = zeros(B,13); |
---|
47 | instlab = ''; |
---|
48 | bagid = []; |
---|
49 | for i=1:B |
---|
50 | %load the signal; |
---|
51 | [signal,fs] = wavread(fullfile(dpath,'src_wavs',names{i}(2:end))); |
---|
52 | [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs); |
---|
53 | % smooth and threshold the spectrogram: |
---|
54 | I = imfilter(abs(S),G,'same'); |
---|
55 | mask = (I>dd_threshold(I(:),intens_thr)); |
---|
56 | mask(f<f_min) = 0; |
---|
57 | % find interesting regions: |
---|
58 | props = regionprops(bwlabel(mask),abs(S)); |
---|
59 | bloblab = bwlabel(mask); |
---|
60 | Nseg = max(unique(bloblab)); |
---|
61 | |
---|
62 | % run over blobs: |
---|
63 | im = abs(S); |
---|
64 | thisx = zeros(Nseg,7); |
---|
65 | for j=1:Nseg |
---|
66 | ix = (bloblab==j); |
---|
67 | % compute/add some blob-properties: |
---|
68 | thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox]; |
---|
69 | % don't forget: |
---|
70 | %bagid(end+1) = i; |
---|
71 | |
---|
72 | bagid = [bagid i]; |
---|
73 | |
---|
74 | end |
---|
75 | x{i} = thisx; |
---|
76 | |
---|
77 | %Get the labels right for the training bags: |
---|
78 | |
---|
79 | if ~Itst(i) |
---|
80 | %eval(['baglab(i,[',labstr{i}(2:end),'])=1;']); |
---|
81 | %VC: in the text file, label numbers are 0 to 18, we want 1 to 19? |
---|
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); |
---|