source: birds/createmilbirds_19cl.m @ 66

Last change on this file since 66 was 65, checked in by dtax, 11 years ago

Rearrange stuff.

File size: 2.7 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)
11
12% load the 'meta' data like labels and filenames
13dpath = '/data/birds_mlsp2013/mlsp_contest_dataset2/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%d','headerlines',1);
17
18
19if any(bagid~=bagid2)
20        error('Bagid''s do not match.');
21end
22G = fspecial('gaussian',[5 5],2);
23
24% run over the files, and get the features:
25B = size(bagid,1);
26x = cell(B,1);
27baglab = zeros(B,13);
28instlab = '';
29bagid = [];
30for i=1:B
31        %load the signal;
32        [signal,fs] = wavread(fullfile(dpath,'wavs',names{i}(2:end)));
33        [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs);
34        % smooth and threshold the spectrogram:
35        I = imfilter(abs(S),G,'same');
36        mask = (I>dd_threshold(I(:),intens_thr));
37        mask(f<f_min) = 0;
38        % find interesting regions:
39        props = regionprops(bwlabel(mask),abs(S));
40        bloblab = bwlabel(mask);
41        Nseg = max(unique(bloblab));
42
43        % run over blobs:
44        im = abs(S);
45        thisx = zeros(Nseg,7);
46        for j=1:Nseg
47                ix = (bloblab==j);
48      % compute/add some blob-properties:
49                thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox];
50                % don't forget:
51                bagid(end+1) = i;
52        end
53        x{i} = thisx;
54
55        % get the labels right for the training bags:
56   if ~Itst(i)
57      eval(['baglab(i,[',labstr{i}(2:end),'])=1;']);
58   end
59end
60
61% create a dataset
62a = genmil(x);
63% add the labels one by one:
64ll = [...
65'BRCR-Brown Creeper            ';
66'PAWR-Pacific Wren             ';
67'PSFL-Pacific-slope Flycatcher ';
68'RBNU-Red-breasted Nuthatch    ';
69'DEJU-Dark-eyed Junco          ';
70'OSFL-Olive-sided Flycatcher   ';
71'HETH-Hermit Thrush            ';
72'CBCH-Chestnut-backed Chickadee';
73'VATH-Varied Thrush            ';
74'HEWA-Hermit Warbler           ';
75'SWTH-Swainsons Thrush         ';
76'HAFL-Hammonds Flycatcher      ';
77'WETA-Western Tanager          ';
78'BHGB-Black-headed Grosbeak    ';
79'GCKI-Golden Crowned Kinglet   ';
80'WAVI-Warbling Vireo           ';
81'MGWA-MacGillivrays Warbler    ';
82'STJA-Stellars Jay             ';
83'CONI-Common Nighthawk         '];
84
85
86for i=1:size(baglab,2)
87   I = ismember(bagid,find(baglab(:,i)));
88   a = addlabels(a,genmillabels(I',1),ll(i,:));
89end
90% set it to the first bird:
91a = changelablist(a,2);
92thisll = getlablistnames(a);
93a = setname(a,strtrim(thisll(curlablist(a),:)));
94
95J = Itst(bagid);
Note: See TracBrowser for help on using the repository browser.