source: birds/createmilbirds_19cl.m @ 92

Last change on this file since 92 was 77, checked in by dtax, 11 years ago

Oops!

File size: 4.9 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);
[77]71    momentfeats = nan(Nseg,62);
[72]72       
[65]73        for j=1:Nseg
[72]74   
75       
[65]76                ix = (bloblab==j);
[72]77       
[65]78      % compute/add some blob-properties:
[72]79          %     thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox];
80     
81        pixtotal = sum(sum(ix));
82        pixheight = max(sum(ix,1));
83        pixwidth = max(sum(ix,2));
84
85        maskfeats(j,:) = [pixtotal pixheight pixwidth];
86
87
88        seg = absim(ix);
89        absfeats(j,1) = mean(seg);
90        absfeats(j,2) = std(seg);
91
92        absfeats(j,3) = quantile(seg(:),0);
93        absfeats(j,4) = quantile(seg(:),0.25);
94        absfeats(j,5) = quantile(seg(:),0.5);
95        absfeats(j,6) = quantile(seg(:),0.75);
96        absfeats(j,7) = quantile(seg(:),1);
97       
98           seg = realim(ix);
99        realfeats(j,1) = mean(seg);
100        realfeats(j,2) = std(seg);
101
102        realfeats(j,3) = quantile(seg(:),0);
103        realfeats(j,4) = quantile(seg(:),0.25);
104        realfeats(j,5) = quantile(seg(:),0.5);
105        realfeats(j,6) = quantile(seg(:),0.75);
106        realfeats(j,7) = quantile(seg(:),1);
107       
108           seg = imagim(ix);
109        imagfeats(j,1) = mean(seg);
110        imagfeats(j,2) = std(seg);
111
112        imagfeats(j,3) = quantile(seg(:),0);
113        imagfeats(j,4) = quantile(seg(:),0.25);
114        imagfeats(j,5) = quantile(seg(:),0.5);
115        imagfeats(j,6) = quantile(seg(:),0.75);
116        imagfeats(j,7) = quantile(seg(:),1);
117         
[75]118           seg = absim.*ix;
[77]119        momentfeats(j,:) = [moments(seg,[1;0],[0;1],1,0) ...
[75]120           moments(seg,[2;1;0],[0;1;2],1,0) ...
121           moments(seg,[2,1,0],[0,1,2],1,1) ...
122           hu_moments(seg) zernike_moments(seg)];
[72]123       
[65]124                % don't forget:
[72]125                bagid(end+1) = i;
126
[67]127       
[65]128        end
[75]129        x{i} = [maskfeats absfeats realfeats imagfeats momentfeat];
[65]130
[67]131        %Get the labels right for the training bags:
132   
[65]133   if ~Itst(i)
[67]134      eval(['baglab(i,[',labstr{i}(2:end),']+1)=1;']);
[65]135   end
136end
137
138% create a dataset
139a = genmil(x);
140% add the labels one by one:
141ll = [...
142'BRCR-Brown Creeper            ';
143'PAWR-Pacific Wren             ';
144'PSFL-Pacific-slope Flycatcher ';
145'RBNU-Red-breasted Nuthatch    ';
146'DEJU-Dark-eyed Junco          ';
147'OSFL-Olive-sided Flycatcher   ';
148'HETH-Hermit Thrush            ';
149'CBCH-Chestnut-backed Chickadee';
150'VATH-Varied Thrush            ';
151'HEWA-Hermit Warbler           ';
152'SWTH-Swainsons Thrush         ';
153'HAFL-Hammonds Flycatcher      ';
154'WETA-Western Tanager          ';
155'BHGB-Black-headed Grosbeak    ';
156'GCKI-Golden Crowned Kinglet   ';
157'WAVI-Warbling Vireo           ';
158'MGWA-MacGillivrays Warbler    ';
159'STJA-Stellars Jay             ';
160'CONI-Common Nighthawk         '];
161
162
163for i=1:size(baglab,2)
164   I = ismember(bagid,find(baglab(:,i)));
165   a = addlabels(a,genmillabels(I',1),ll(i,:));
166end
167% set it to the first bird:
168a = changelablist(a,2);
169thisll = getlablistnames(a);
170a = setname(a,strtrim(thisll(curlablist(a),:)));
171
172J = Itst(bagid);
[70]173x = a(~J,:);
174z = a(logical(J),:);
[76]175save('birds20130710.mat', 'a', 'x', 'z', 'Itst', 'J');
Note: See TracBrowser for help on using the repository browser.