[61] | 1 |
|
---|
| 2 | %NOT DONE Need a list of bag labels first corresponding to the WAV files!
|
---|
| 3 |
|
---|
| 4 |
|
---|
| 5 | wavlist = dir(fullfile(mildatapath,'birds', 'wavs', '*.wav'));
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | mildata = [];
|
---|
| 9 | instlab=[];
|
---|
| 10 | bagid = [];
|
---|
| 11 |
|
---|
| 12 | for j=1:length(wavlist)
|
---|
| 13 | [signal,fs] = wavread(fullfile(mildatapath,'birds','wavs',wavlist(j).name));
|
---|
| 14 |
|
---|
| 15 |
|
---|
| 16 | fmax = 256;
|
---|
| 17 | [S,f,t] = spectrogram(signal,512,256,fmax,fs);
|
---|
| 18 |
|
---|
| 19 | s2 = specwhiten(S,fmax);
|
---|
| 20 | G = fspecial('gaussian',[5 5],2);
|
---|
| 21 | I = imfilter(abs(s2),G,'same');
|
---|
| 22 | t = dd_threshold(I(:),0.95);
|
---|
| 23 | mask = (I>t);
|
---|
| 24 | mask(f<2000,:) = 0;
|
---|
| 25 |
|
---|
| 26 |
|
---|
| 27 | labeledx = bwlabel(mask);
|
---|
| 28 | Nseg = max(unique(labeledx)); %Segment labels, segment 0 is background
|
---|
| 29 |
|
---|
| 30 | absim = abs(S);
|
---|
| 31 | realim = real(S);
|
---|
| 32 | imagim = imag(S);
|
---|
| 33 |
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | maskfeats = nan(Nseg,3);
|
---|
| 37 | absfeats = nan(Nseg, 7);
|
---|
| 38 |
|
---|
| 39 |
|
---|
| 40 | bagjlab = baglabs(j,:);
|
---|
| 41 |
|
---|
| 42 | for i=1:Nseg
|
---|
| 43 |
|
---|
| 44 | ix = (labeledx == i);
|
---|
| 45 |
|
---|
| 46 | pixtotal = sum(sum(ix));
|
---|
| 47 | pixheight = max(sum(ix,1));
|
---|
| 48 | pixwidth = max(sum(ix,2));
|
---|
| 49 |
|
---|
| 50 | maskfeats(i,:) = [pixtotal pixheight pixwidth];
|
---|
| 51 |
|
---|
| 52 |
|
---|
| 53 | seg = absim(ix);
|
---|
| 54 | absfeats(i,1) = mean(seg);
|
---|
| 55 | absfeats(i,2) = std(seg);
|
---|
| 56 |
|
---|
| 57 | absfeats(i,3) = quantile(seg(:),0);
|
---|
| 58 | absfeats(i,4) = quantile(seg(:),0.25);
|
---|
| 59 | absfeats(i,5) = quantile(seg(:),0.5);
|
---|
| 60 | absfeats(i,6) = quantile(seg(:),0.75);
|
---|
| 61 | absfeats(i,7) = quantile(seg(:),1);
|
---|
| 62 |
|
---|
| 63 | instlab = [instlab; bagjlab];
|
---|
| 64 | bagid = [bagid; j];
|
---|
| 65 | end
|
---|
| 66 |
|
---|
| 67 | segdata = [maskfeats absfeats];
|
---|
| 68 | mildata = [mildata; segdata];
|
---|
| 69 | end
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | a = genmil(mildata, instlab, bagid, 'presence');
|
---|