source: birds/createmilbirds_13cl.m @ 133

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

Rearrange stuff.

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