source: birds/createmilbirds_19cl.m @ 69

Last change on this file since 69 was 68, checked in by vcheplygina, 11 years ago
File size: 3.4 KB
Line 
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:
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 = '../birds_mlsp2013/mlsp_contest_dataset/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
17
18%[bagid3,Itst] =
19%textread(fullfile(dpath,'CVfolds_2.txt'),'%n%d','headerlines',1);
20
21%VC: Ik krijg hier foutmeldingen. textread gaat weg, dus ze raden aan om
22%textscan te gebruiken.
23%>Error using dataread
24%>Trouble reading integer from file (row 1, field 2) ==> ,1\n
25%>Error in textread (line 175)
26%>[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
27 
28
29N = length(bagid2);
30CVfile = fopen(fullfile(dpath,'CVfolds_2.txt'));
31CVdata = textscan(CVfile, '%f,%f', N, 'headerlines',1);
32fclose(CVfile);
33
34bagid3 = CVdata{1};
35Itst = CVdata{2};
36
37
38if any(bagid~=bagid2)
39        error('Bagid''s do not match.');
40end
41G = fspecial('gaussian',[5 5],2);
42
43% run over the files, and get the features:
44B = size(bagid,1);
45x = cell(B,1);
46baglab = zeros(B,13);
47instlab = '';
48bagid = [];
49for i=1:B
50        %load the signal;
51        [signal,fs] = wavread(fullfile(dpath,'src_wavs',names{i}(2:end)));
52        [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs);
53        % smooth and threshold the spectrogram:
54        I = imfilter(abs(S),G,'same');
55        mask = (I>dd_threshold(I(:),intens_thr));
56        mask(f<f_min) = 0;
57        % find interesting regions:
58        props = regionprops(bwlabel(mask),abs(S));
59        bloblab = bwlabel(mask);
60        Nseg = max(unique(bloblab));
61
62        % run over blobs:
63        im = abs(S);
64        thisx = zeros(Nseg,7);
65        for j=1:Nseg
66                ix = (bloblab==j);
67      % compute/add some blob-properties:
68                thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox];
69                % don't forget:
70                %bagid(end+1) = i;
71       
72        bagid = [bagid i];
73       
74        end
75        x{i} = thisx;
76
77        %Get the labels right for the training bags:
78   
79   if ~Itst(i)
80      %eval(['baglab(i,[',labstr{i}(2:end),'])=1;']);
81      %VC: in the text file, label numbers are 0 to 18, we want 1 to 19?
82      eval(['baglab(i,[',labstr{i}(2:end),']+1)=1;']);
83   end
84end
85
86% create a dataset
87a = genmil(x);
88% add the labels one by one:
89ll = [...
90'BRCR-Brown Creeper            ';
91'PAWR-Pacific Wren             ';
92'PSFL-Pacific-slope Flycatcher ';
93'RBNU-Red-breasted Nuthatch    ';
94'DEJU-Dark-eyed Junco          ';
95'OSFL-Olive-sided Flycatcher   ';
96'HETH-Hermit Thrush            ';
97'CBCH-Chestnut-backed Chickadee';
98'VATH-Varied Thrush            ';
99'HEWA-Hermit Warbler           ';
100'SWTH-Swainsons Thrush         ';
101'HAFL-Hammonds Flycatcher      ';
102'WETA-Western Tanager          ';
103'BHGB-Black-headed Grosbeak    ';
104'GCKI-Golden Crowned Kinglet   ';
105'WAVI-Warbling Vireo           ';
106'MGWA-MacGillivrays Warbler    ';
107'STJA-Stellars Jay             ';
108'CONI-Common Nighthawk         '];
109
110
111for i=1:size(baglab,2)
112   I = ismember(bagid,find(baglab(:,i)));
113   a = addlabels(a,genmillabels(I',1),ll(i,:));
114end
115% set it to the first bird:
116a = changelablist(a,2);
117thisll = getlablistnames(a);
118a = setname(a,strtrim(thisll(curlablist(a),:)));
119
120J = Itst(bagid);
121save('birds20130709.mat', 'a', 'Itst', 'J');
Note: See TracBrowser for help on using the repository browser.