[65] | 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 | % This is the new 19 species dataset from the MLSP competition |
---|
| 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 = '/data/birds_mlsp2013/mlsp_contest_dataset2/essential_data/'; |
---|
| 14 | [bagid,names] = textread(fullfile(dpath,'rec_id2filename.txt'),'%n%s','headerlines',1); |
---|
| 15 | [bagid2,labstr] = textread(fullfile(dpath,'rec_labels_test_hidden.txt'),'%n%s','headerlines',1); |
---|
| 16 | [bagid3,Itst] = textread(fullfile(dpath,'CVfolds_2.txt'),'%n%d','headerlines',1); |
---|
| 17 | |
---|
| 18 | |
---|
| 19 | if any(bagid~=bagid2) |
---|
| 20 | error('Bagid''s do not match.'); |
---|
| 21 | end |
---|
| 22 | G = fspecial('gaussian',[5 5],2); |
---|
| 23 | |
---|
| 24 | % run over the files, and get the features: |
---|
| 25 | B = size(bagid,1); |
---|
| 26 | x = cell(B,1); |
---|
| 27 | baglab = zeros(B,13); |
---|
| 28 | instlab = ''; |
---|
| 29 | bagid = []; |
---|
| 30 | for i=1:B |
---|
| 31 | %load the signal; |
---|
| 32 | [signal,fs] = wavread(fullfile(dpath,'wavs',names{i}(2:end))); |
---|
| 33 | [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs); |
---|
| 34 | % smooth and threshold the spectrogram: |
---|
| 35 | I = imfilter(abs(S),G,'same'); |
---|
| 36 | mask = (I>dd_threshold(I(:),intens_thr)); |
---|
| 37 | mask(f<f_min) = 0; |
---|
| 38 | % find interesting regions: |
---|
| 39 | props = regionprops(bwlabel(mask),abs(S)); |
---|
| 40 | bloblab = bwlabel(mask); |
---|
| 41 | Nseg = max(unique(bloblab)); |
---|
| 42 | |
---|
| 43 | % run over blobs: |
---|
| 44 | im = abs(S); |
---|
| 45 | thisx = zeros(Nseg,7); |
---|
| 46 | for j=1:Nseg |
---|
| 47 | ix = (bloblab==j); |
---|
| 48 | % compute/add some blob-properties: |
---|
| 49 | thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox]; |
---|
| 50 | % don't forget: |
---|
| 51 | bagid(end+1) = i; |
---|
| 52 | end |
---|
| 53 | x{i} = thisx; |
---|
| 54 | |
---|
| 55 | % get the labels right for the training bags: |
---|
| 56 | if ~Itst(i) |
---|
| 57 | eval(['baglab(i,[',labstr{i}(2:end),'])=1;']); |
---|
| 58 | end |
---|
| 59 | end |
---|
| 60 | |
---|
| 61 | % create a dataset |
---|
| 62 | a = genmil(x); |
---|
| 63 | % add the labels one by one: |
---|
| 64 | ll = [... |
---|
| 65 | 'BRCR-Brown Creeper '; |
---|
| 66 | 'PAWR-Pacific Wren '; |
---|
| 67 | 'PSFL-Pacific-slope Flycatcher '; |
---|
| 68 | 'RBNU-Red-breasted Nuthatch '; |
---|
| 69 | 'DEJU-Dark-eyed Junco '; |
---|
| 70 | 'OSFL-Olive-sided Flycatcher '; |
---|
| 71 | 'HETH-Hermit Thrush '; |
---|
| 72 | 'CBCH-Chestnut-backed Chickadee'; |
---|
| 73 | 'VATH-Varied Thrush '; |
---|
| 74 | 'HEWA-Hermit Warbler '; |
---|
| 75 | 'SWTH-Swainsons Thrush '; |
---|
| 76 | 'HAFL-Hammonds Flycatcher '; |
---|
| 77 | 'WETA-Western Tanager '; |
---|
| 78 | 'BHGB-Black-headed Grosbeak '; |
---|
| 79 | 'GCKI-Golden Crowned Kinglet '; |
---|
| 80 | 'WAVI-Warbling Vireo '; |
---|
| 81 | 'MGWA-MacGillivrays Warbler '; |
---|
| 82 | 'STJA-Stellars Jay '; |
---|
| 83 | 'CONI-Common Nighthawk ']; |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | for i=1:size(baglab,2) |
---|
| 87 | I = ismember(bagid,find(baglab(:,i))); |
---|
| 88 | a = addlabels(a,genmillabels(I',1),ll(i,:)); |
---|
| 89 | end |
---|
| 90 | % set it to the first bird: |
---|
| 91 | a = changelablist(a,2); |
---|
| 92 | thisll = getlablistnames(a); |
---|
| 93 | a = setname(a,strtrim(thisll(curlablist(a),:))); |
---|
| 94 | |
---|
| 95 | J = Itst(bagid); |
---|