source: birds/createmilbirds.m @ 64

Last change on this file since 64 was 63, checked in by dtax, 11 years ago

Now it should create a good MIL dataset.

File size: 2.2 KB
RevLine 
[62]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% some settings:
5windowlen = 512;
6fmax = 256;
7intens_thr = 0.8;   % remove 80% of the signal??
8f_min = 2000;       % frequency threshold (everything below is removed)
9
10% load the 'meta' data like labels and filenames
11dpath = fullfile(mildatapath,'birds');
12[bagid,names] = textread(fullfile(dpath,'id2filename.txt'),'%n%s','headerlines',1);
13[bagid2,labstr] = textread(fullfile(dpath,'hja_birdsong_bag_labels.txt'),'%n%s','headerlines',1);
14
15if any(bagid~=bagid2)
16        error('Bagid''s do not match.');
17end
18G = fspecial('gaussian',[5 5],2);
19
20% run over the files, and get the features:
21B = size(bagid,1);
22x = cell(B,1);
23baglab = zeros(B,13);
24instlab = '';
25bagid = [];
26for i=1:B
27        %load the signal;
28        [signal,fs] = wavread(fullfile(dpath,'wavs',names{i}(2:end)));
29        [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs);
30        % smooth and threshold the spectrogram:
31        I = imfilter(abs(S),G,'same');
32        mask = (I>dd_threshold(I(:),intens_thr));
33        mask(f<f_min) = 0;
34        % find interesting regions:
35        props = regionprops(bwlabel(mask),abs(S));
36        bloblab = bwlabel(mask);
37        Nseg = max(unique(bloblab));
38
39        % run over blobs:
40        im = abs(S);
[63]41        thisx = zeros(Nseg,3);
[62]42        for j=1:Nseg
43                ix = (bloblab==j);
44                thisx(j,:) = [props(j).Area props(j).Centroid];
45                % don't forget:
46                bagid(end+1) = i;
47        end
48        x{i} = thisx;
49
50        % get the labels right:
51        eval(['baglab(i,[',labstr{i}(2:end),'])=1;']);
52end
53
54% create a dataset
55a = genmil(x);
[63]56% add the labels one by one:
57ll = [...
58'BRCR - Brown Creeper            ';
59'WIWR - Winter Wren              ';
60'PSFL - Pacific-slope Flycatcher ';
61'RBNU - Red-breasted Nuthatch    ';
62'DEJU - Dark-eyed Junco          ';
63'OSFL - Olive-sided Flycatcher   ';
64'HETH - Hermit Thrush            ';
65'CBCH - Chestnut-backed Chickadee';
66'VATH - Varied Thrush            ';
67'HEWA - Hermit Warbler           ';
68'SWTH - Swainsons Thrush         ';
69'HAFL - Hammonds Flycatcher      ';
70'WETA - Western Tanager          '];
71
72for i=1:size(baglab,2)
73   I = ismember(bagid,find(baglab(:,i)));
74   a = addlabels(a,genmillabels(I',1),ll(i,:));
75end
76% set it to the first bird:
77a = changelablist(a,2);
78thisll = getlablistnames(a);
79a = setname(a,strtrim(thisll(curlablist(a),:)));
80
Note: See TracBrowser for help on using the repository browser.