[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: |
---|
| 5 | windowlen = 512; |
---|
| 6 | fmax = 256; |
---|
| 7 | intens_thr = 0.8; % remove 80% of the signal?? |
---|
| 8 | f_min = 2000; % frequency threshold (everything below is removed) |
---|
| 9 | |
---|
| 10 | % load the 'meta' data like labels and filenames |
---|
| 11 | dpath = 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 | |
---|
| 15 | if any(bagid~=bagid2) |
---|
| 16 | error('Bagid''s do not match.'); |
---|
| 17 | end |
---|
| 18 | G = fspecial('gaussian',[5 5],2); |
---|
| 19 | |
---|
| 20 | % run over the files, and get the features: |
---|
| 21 | B = size(bagid,1); |
---|
| 22 | x = cell(B,1); |
---|
| 23 | baglab = zeros(B,13); |
---|
| 24 | instlab = ''; |
---|
| 25 | bagid = []; |
---|
| 26 | for 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;']); |
---|
| 52 | end |
---|
| 53 | |
---|
| 54 | % create a dataset |
---|
| 55 | a = genmil(x); |
---|