source: birds/createmilbirds_19cl.m @ 72

Last change on this file since 72 was 72, checked in by vcheplygina, 11 years ago
File size: 4.6 KB
RevLine 
[65]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:
7windowlen = 512;
8fmax = 256;
9intens_thr = 0.8;   % remove 80% of the signal??
10f_min = 2000;       % frequency threshold (everything below is removed)
[71]11% blurring of the spectrogram:
12G = fspecial('gaussian',[5 5],2);
[65]13
14% load the 'meta' data like labels and filenames
[71]15%dpath = '../birds_mlsp2013/mlsp_contest_dataset/essential_data/';
16dpath = '/data/birds_mlsp2013/mlsp_contest_dataset2/essential_data';
17% load the filenames
18fid = fopen(fullfile(dpath,'rec_id2filename.txt'));
19data = textscan(fid,'%n%s','headerlines',1);
20fclose(fid);
21bagid = data{1};
22names = data{2};
23% next load the labels:
24fid = fopen(fullfile(dpath,'rec_labels_test_hidden.txt'));
25data = textscan(fid,'%n%s','headerlines',1);
26bagid2 = data{1};
27labstr = data{2};
28% load the indices for the training and test objects:
[67]29N = length(bagid2);
30CVfile = fopen(fullfile(dpath,'CVfolds_2.txt'));
[71]31   CVdata = textscan(CVfile, '%f,%f', N, 'headerlines',1);
[67]32fclose(CVfile);
33bagid3 = CVdata{1};
34Itst = CVdata{2};
35
[71]36% some checking
[65]37if any(bagid~=bagid2)
38        error('Bagid''s do not match.');
39end
40
41% run over the files, and get the features:
42B = size(bagid,1);
43x = cell(B,1);
44baglab = zeros(B,13);
45instlab = '';
46bagid = [];
47for i=1:B
[72]48    i
49   
[65]50        %load the signal;
[67]51        [signal,fs] = wavread(fullfile(dpath,'src_wavs',names{i}(2:end)));
[65]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:
[72]63        absim = abs(S);
64        realim = real(S);
65    imagim = imag(S);
66   
67    maskfeats = nan(Nseg,3);
68    absfeats = nan(Nseg, 7);
69    realfeats = nan(Nseg,7);
70    imagfeats = nan(Nseg,7);
71       
[65]72        for j=1:Nseg
[72]73   
74       
[65]75                ix = (bloblab==j);
[72]76       
[65]77      % compute/add some blob-properties:
[72]78          %     thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox];
79     
80        pixtotal = sum(sum(ix));
81        pixheight = max(sum(ix,1));
82        pixwidth = max(sum(ix,2));
83
84        maskfeats(j,:) = [pixtotal pixheight pixwidth];
85
86
87        seg = absim(ix);
88        absfeats(j,1) = mean(seg);
89        absfeats(j,2) = std(seg);
90
91        absfeats(j,3) = quantile(seg(:),0);
92        absfeats(j,4) = quantile(seg(:),0.25);
93        absfeats(j,5) = quantile(seg(:),0.5);
94        absfeats(j,6) = quantile(seg(:),0.75);
95        absfeats(j,7) = quantile(seg(:),1);
96       
97           seg = realim(ix);
98        realfeats(j,1) = mean(seg);
99        realfeats(j,2) = std(seg);
100
101        realfeats(j,3) = quantile(seg(:),0);
102        realfeats(j,4) = quantile(seg(:),0.25);
103        realfeats(j,5) = quantile(seg(:),0.5);
104        realfeats(j,6) = quantile(seg(:),0.75);
105        realfeats(j,7) = quantile(seg(:),1);
106       
107           seg = imagim(ix);
108        imagfeats(j,1) = mean(seg);
109        imagfeats(j,2) = std(seg);
110
111        imagfeats(j,3) = quantile(seg(:),0);
112        imagfeats(j,4) = quantile(seg(:),0.25);
113        imagfeats(j,5) = quantile(seg(:),0.5);
114        imagfeats(j,6) = quantile(seg(:),0.75);
115        imagfeats(j,7) = quantile(seg(:),1);
116         
117       
[65]118                % don't forget:
[72]119                bagid(end+1) = i;
120
[67]121       
[65]122        end
[72]123        x{i} = [maskfeats absfeats realfeats imagfeats];
[65]124
[67]125        %Get the labels right for the training bags:
126   
[65]127   if ~Itst(i)
[67]128      eval(['baglab(i,[',labstr{i}(2:end),']+1)=1;']);
[65]129   end
130end
131
132% create a dataset
133a = genmil(x);
134% add the labels one by one:
135ll = [...
136'BRCR-Brown Creeper            ';
137'PAWR-Pacific Wren             ';
138'PSFL-Pacific-slope Flycatcher ';
139'RBNU-Red-breasted Nuthatch    ';
140'DEJU-Dark-eyed Junco          ';
141'OSFL-Olive-sided Flycatcher   ';
142'HETH-Hermit Thrush            ';
143'CBCH-Chestnut-backed Chickadee';
144'VATH-Varied Thrush            ';
145'HEWA-Hermit Warbler           ';
146'SWTH-Swainsons Thrush         ';
147'HAFL-Hammonds Flycatcher      ';
148'WETA-Western Tanager          ';
149'BHGB-Black-headed Grosbeak    ';
150'GCKI-Golden Crowned Kinglet   ';
151'WAVI-Warbling Vireo           ';
152'MGWA-MacGillivrays Warbler    ';
153'STJA-Stellars Jay             ';
154'CONI-Common Nighthawk         '];
155
156
157for i=1:size(baglab,2)
158   I = ismember(bagid,find(baglab(:,i)));
159   a = addlabels(a,genmillabels(I',1),ll(i,:));
160end
161% set it to the first bird:
162a = changelablist(a,2);
163thisll = getlablistnames(a);
164a = setname(a,strtrim(thisll(curlablist(a),:)));
165
166J = Itst(bagid);
[70]167x = a(~J,:);
168z = a(logical(J),:);
169save('birds20130709.mat', 'a', 'x', 'z', 'Itst', 'J');
Note: See TracBrowser for help on using the repository browser.