source: birds/createmilbirds.m @ 62

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

Make a cleaner version of generating a new MIL dataset.

File size: 1.5 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);
41        thisx = zeros(Nseg,2);
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);
Note: See TracBrowser for help on using the repository browser.