[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: |
---|
| 7 | windowlen = 512; |
---|
| 8 | fmax = 256; |
---|
| 9 | intens_thr = 0.8; % remove 80% of the signal?? |
---|
| 10 | f_min = 2000; % frequency threshold (everything below is removed) |
---|
| 11 | |
---|
| 12 | % load the 'meta' data like labels and filenames |
---|
| 13 | dpath = 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 | |
---|
| 17 | if any(bagid~=bagid2) |
---|
| 18 | error('Bagid''s do not match.'); |
---|
| 19 | end |
---|
| 20 | G = fspecial('gaussian',[5 5],2); |
---|
| 21 | |
---|
| 22 | % run over the files, and get the features: |
---|
| 23 | B = size(bagid,1); |
---|
| 24 | x = cell(B,1); |
---|
| 25 | baglab = zeros(B,13); |
---|
| 26 | instlab = ''; |
---|
| 27 | bagid = []; |
---|
| 28 | for 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;']); |
---|
| 55 | end |
---|
| 56 | |
---|
| 57 | % create a dataset |
---|
| 58 | a = genmil(x); |
---|
[63] | 59 | % add the labels one by one: |
---|
| 60 | ll = [... |
---|
| 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 | |
---|
| 75 | for i=1:size(baglab,2) |
---|
| 76 | I = ismember(bagid,find(baglab(:,i))); |
---|
| 77 | a = addlabels(a,genmillabels(I',1),ll(i,:)); |
---|
| 78 | end |
---|
| 79 | % set it to the first bird: |
---|
| 80 | a = changelablist(a,2); |
---|
| 81 | thisll = getlablistnames(a); |
---|
| 82 | a = setname(a,strtrim(thisll(curlablist(a),:))); |
---|
| 83 | |
---|