source: birds/createmilbirds_19cl.m @ 70

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

Maybe a bit better...

File size: 3.4 KB
RevLine 
[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:
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
[67]13dpath = '../birds_mlsp2013/mlsp_contest_dataset/essential_data/';
[65]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);
[70]16[bagid3,Itst] = textread(fullfile(dpath,'CVfolds_2.txt'),'%n%n',...
17'delimiter',',','headerlines',1);
[65]18
19
[67]20%[bagid3,Itst] =
21%textread(fullfile(dpath,'CVfolds_2.txt'),'%n%d','headerlines',1);
22
23%VC: Ik krijg hier foutmeldingen. textread gaat weg, dus ze raden aan om
24%textscan te gebruiken.
25%>Error using dataread
26%>Trouble reading integer from file (row 1, field 2) ==> ,1\n
27%>Error in textread (line 175)
28%>[varargout{1:nlhs}]=dataread('file',varargin{:}); %#ok<REMFF1>
29 
30
31N = length(bagid2);
32CVfile = fopen(fullfile(dpath,'CVfolds_2.txt'));
33CVdata = textscan(CVfile, '%f,%f', N, 'headerlines',1);
34fclose(CVfile);
35
36bagid3 = CVdata{1};
37Itst = CVdata{2};
38
39
[65]40if any(bagid~=bagid2)
41        error('Bagid''s do not match.');
42end
43G = fspecial('gaussian',[5 5],2);
44
45% run over the files, and get the features:
46B = size(bagid,1);
47x = cell(B,1);
48baglab = zeros(B,13);
49instlab = '';
50bagid = [];
51for i=1:B
52        %load the signal;
[67]53        [signal,fs] = wavread(fullfile(dpath,'src_wavs',names{i}(2:end)));
[65]54        [S,f,t] = spectrogram(signal,windowlen,windowlen/2,fmax,fs);
55        % smooth and threshold the spectrogram:
56        I = imfilter(abs(S),G,'same');
57        mask = (I>dd_threshold(I(:),intens_thr));
58        mask(f<f_min) = 0;
59        % find interesting regions:
60        props = regionprops(bwlabel(mask),abs(S));
61        bloblab = bwlabel(mask);
62        Nseg = max(unique(bloblab));
63
64        % run over blobs:
65        im = abs(S);
66        thisx = zeros(Nseg,7);
67        for j=1:Nseg
68                ix = (bloblab==j);
69      % compute/add some blob-properties:
70                thisx(j,:) = [props(j).Area, props(j).Centroid, props(j).BoundingBox];
71                % don't forget:
[67]72                %bagid(end+1) = i;
73       
74        bagid = [bagid i];
75       
[65]76        end
77        x{i} = thisx;
78
[67]79        %Get the labels right for the training bags:
80   
[65]81   if ~Itst(i)
[67]82      eval(['baglab(i,[',labstr{i}(2:end),']+1)=1;']);
[65]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);
[70]121x = a(~J,:);
122z = a(logical(J),:);
123save('birds20130709.mat', 'a', 'x', 'z', 'Itst', 'J');
Note: See TracBrowser for help on using the repository browser.