# HG changeset patch # User Mathieu Lagrange # Date 1497019070 -7200 # Node ID 39399de892ef86f87ba7ce4cf1ad88d0504c4548 # Parent d0ceb549f734aabf6fbc6c9b607df9aca317350c better handling of displays with pleasantness colors diff -r d0ceb549f734 -r 39399de892ef nonExposed/checkClassPresence.m --- a/nonExposed/checkClassPresence.m Mon May 22 10:46:10 2017 +0200 +++ b/nonExposed/checkClassPresence.m Fri Jun 09 16:37:50 2017 +0200 @@ -6,7 +6,7 @@ if(find(classIndex==1)) classLabel= {sceneObjects.classLabel}; disp({classLabel{logical(classIndex)}}) - error('At least one class has been removed during the simulation process') + fprintf(2, 'At least one class has been removed during the simulation process\n') end diff -r d0ceb549f734 -r 39399de892ef nonExposed/coloredSpectrumVisualization.m --- a/nonExposed/coloredSpectrumVisualization.m Mon May 22 10:46:10 2017 +0200 +++ b/nonExposed/coloredSpectrumVisualization.m Fri Jun 09 16:37:50 2017 +0200 @@ -5,17 +5,26 @@ maxFreqBin=400; % Producing a colored spectrum visualization + for i=1:size(tracks,1) spec = log(1+abs(spectrogram(tracks(i,:), hanning(wSize), wStep, wSize))); spec = min(1, spec ./ max(spec(:))); spec = spec(1:maxFreqBin,:); spec = flipud(spec); - for colorComp=1:3 - if (i==1) - img(:,:,colorComp) = settingFigure.cmap(i,colorComp)*spec; - else - img(:,:,colorComp) = img(:,:,colorComp)+settingFigure.cmap(i,colorComp)*spec; - end + % black background +% for colorComp=1:3 +% if (i==1) +% img(:,:,colorComp) = settingFigure.cmap(i,colorComp)*spec; +% else +% img(:,:,colorComp) = img(:,:,colorComp)+settingFigure.cmap(i,colorComp)*spec; +% end +% end + %white background + if i==1 + img = ones(size(spec, 1), size(spec, 2), 3)*.4; + end + for colorComp=1:3 + img(:,:,colorComp) = (1-spec).*img(:,:,colorComp)+settingFigure.cmap(i,colorComp)*spec; end end @@ -42,14 +51,15 @@ xlabel('time (sec)') ylabel('Frequency (Hz)') -set(f,'PaperUnits','centimeters') -set(f,'PaperPositionMode','manual') -set(f,'papersize',[settingFigure.width,settingFigure.height]) -set(f,'paperposition',[0,0,settingFigure.width,settingFigure.height]) set(findall(f,'-property','FontSize'),'FontSize',settingFigure.FontSize) set(findall(f,'-property','FontName'),'FontName','Arial') -print(f,fileName,'-dpng') - +if figuresOption == 1 + set(f,'PaperUnits','centimeters') + set(f,'PaperPositionMode','manual') + set(f,'papersize',[settingFigure.width,settingFigure.height]) + set(f,'paperposition',[0,0,settingFigure.width,settingFigure.height]) + + print(f,fileName,'-dpng') end diff -r d0ceb549f734 -r 39399de892ef nonExposed/generateColormap.m --- a/nonExposed/generateColormap.m Mon May 22 10:46:10 2017 +0200 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,43 +0,0 @@ -function cmap = generateColormap (sceneObjects) -% returns a colormap with randomly chosen colors somewhat evenly spread in -% the color spectrum, to be used for the graphical representations of a -% synthesized scene. - -% Background sounds will have a saturation of .3, foreground sounds of 1 -% Value is always let to .5, since modifying it would erroneously suggest -% a difference of intensity - -% This program was written by Mathias Rossignol & Grégoire Lafay -% is Copyright (C) 2015 IRCAM -% -% This program is free software: you can redistribute it and/or modify it -% under the terms of the GNU General Public License as published by the Free -% Software Foundation, either version 3 of the License, or (at your option) -% any later version. -% -% This program is distributed in the hope that it will be useful, but -% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -% for more details. -% -% You should have received a copy of the GNU General Public License along -% with this program. If not, see . - -nbTracks = length(sceneObjects); - -% Colors for figures -% Choosing color hues evenly spread in the color spectrum, then randomizing their order -hues = (0:1/nbTracks:1); -hues = hues(1:nbTracks); -hues = hues(randperm(nbTracks)); -% Generate a colormap: -for c=1:nbTracks - if (sceneObjects(c).isBackground) - cmap(c,:) = hsl2rgb([hues(c), .3, .5]); - else - cmap(c,:) = hsl2rgb([hues(c), 1, .5]); - end -end - - -end \ No newline at end of file diff -r d0ceb549f734 -r 39399de892ef nonExposed/generateScene.m --- a/nonExposed/generateScene.m Mon May 22 10:46:10 2017 +0200 +++ b/nonExposed/generateScene.m Fri Jun 09 16:37:50 2017 +0200 @@ -171,7 +171,7 @@ audiowrite([outputPath 'sound/' outputFileName '_channel_split' '.wav'],tracks',sr); case 2 if norm %Normalize to [-norm,norm] - tracks = tracks*norm/max(abs(sum(tracks,1))); + tracks = tracks*norm/(1.05*max(abs(sum(tracks,1)))); end for jj=1:size(tracks,1) audiowrite([outputPath 'sound/' outputFileName '_channel_' num2str(jj) '_class_' sceneObjects(jj).classLabel '.wav'],tracks(jj,:),sr); @@ -180,15 +180,35 @@ if figuresOption - settingFigure.cmap = generateColormap(sceneObjects); + settingFigure.cmap = pleasantnessColormap(sceneObjects); + if any(~sum(settingFigure.cmap, 2)) + fprintf(2, 'Unable to get some of the pleasantness tags, revert to randomized colors'); + settingFigure.cmap = randomColormap(sceneObjects); + end settingFigure.width=29.7; % cm settingFigure.height=21; % cm settingFigure.FontSize=16; settingFigure.sr=sr; settingFigure.sceneDuration=score.sceneDuration; + nbBg = 0; + for k=1:length(sceneObjects) + if sceneObjects(k).isBackground + nbBg = nbBg+1; + bgo(nbBg, :) = resample(abs(tracks(k, :)), 1, 44100); + end + end + + + + [~, bgOrder] = sort(mean(bgo, 2)./median(bgo, 2)); + [~, eventOrder] = sort(sum(tracks(nbBg+1:end,:)==0, 2)); + trackOrder = [bgOrder; eventOrder+nbBg]; + tracks = tracks(trackOrder, :); + sceneObjects = sceneObjects(trackOrder); + settingFigure.cmap = settingFigure.cmap(trackOrder, :); + coloredSpectrumVisualization(tracks,1,settingFigure,figuresOption,[outputPath 'annotation/' outputFileName,'-spectrum.png']); timeDomainVisualization(tracks,2,settingFigure,figuresOption,[outputPath 'annotation/' outputFileName,'-timeDomain.png']); pianoRollVisualization(sceneObjects,sceneSchedule,score,3,settingFigure,figuresOption,[outputPath 'annotation/' outputFileName,'-pianoRoll.png']) end -end diff -r d0ceb549f734 -r 39399de892ef nonExposed/pianoRollVisualization.m --- a/nonExposed/pianoRollVisualization.m Mon May 22 10:46:10 2017 +0200 +++ b/nonExposed/pianoRollVisualization.m Fri Jun 09 16:37:50 2017 +0200 @@ -5,9 +5,9 @@ switch figuresOption case 1 - f=figure('Visible', 'off'); + f=figure('Visible', 'off'); case 2 - f=figure(figNum); + f=figure(figNum); end clf; grid on; @@ -30,15 +30,15 @@ set(gca,'YTick', [],'YTicklabel', [],'xtick',0:20:score.sceneDuration); xlabel('time (sec)') - -set(f,'PaperUnits','centimeters') -set(f,'PaperPositionMode','manual') -set(f,'papersize',[settingFigure.width,settingFigure.height]) -set(f,'paperposition',[0,0,settingFigure.width,settingFigure.height]) -set(findall(f,'-property','FontSize'),'FontSize',settingFigure.FontSize) -set(findall(f,'-property','FontName'),'FontName','Arial') - -print(f,fileName,'-dpng') - +if figuresOption == 1 + set(f,'PaperUnits','centimeters') + set(f,'PaperPositionMode','manual') + set(f,'papersize',[settingFigure.width,settingFigure.height]) + set(f,'paperposition',[0,0,settingFigure.width,settingFigure.height]) + set(findall(f,'-property','FontSize'),'FontSize',settingFigure.FontSize) + set(findall(f,'-property','FontName'),'FontName','Arial') + + print(f,fileName,'-dpng') end + diff -r d0ceb549f734 -r 39399de892ef nonExposed/pleasantnessColormap.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nonExposed/pleasantnessColormap.m Fri Jun 09 16:37:50 2017 +0200 @@ -0,0 +1,52 @@ +function cmap = pleasantnessColormap (sceneObjects) +% returns a colormap following pleasantness indicators +% red: mechanical sounds +% blue: human sounds +% yellow: animal sounds + +% Background sounds will have a saturation of .3, foreground sounds of 1 +% Value is always let to .5, since modifying it would erroneously suggest +% a difference of intensity + +% This program was written by Mathias Rossignol & Grégoire Lafay +% is Copyright (C) 2015 IRCAM +% +% This program is free software: you can redistribute it and/or modify it +% under the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +% for more details. +% +% You should have received a copy of the GNU General Public License along +% with this program. If not, see . + +nbTracks = length(sceneObjects); + +classLabels = {'train' 'crowd' 'schoolyard', 'traffic', 'park', 'stepPark', 'scooter', 'moto', 'bike', 'subway', 'bus', 'streetNoise', 'hammer', 'barrier', 'glassNoise', 'waterNoise', 'cutleryNoise', 'keys', 'music', 'brake', 'pneumaticBlast', 'bip', 'whistle', 'zip', 'voice', 'baby', 'cityCar', 'truck', 'carHorn', 'constructionSite', 'coughing', 'stopCar', 'doorCar', 'siren', 'doorHouse', 'bird', 'dog', 'cityStep', 'bell', 'broom', 'suitcase', 'plane'}; +classType = [0 1 1 0 2 1 0 0 1 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 1 0 0 0 0 1 2 2 1 1 0 1 0]+1; + +% for k=1:length(classLabels) +% fprintf('%s ', [classLabels{k} ' ' num2str(classType(k))]) +% end + +hues = [0 240 66]/360; +% Generate a colormap: +for c=1:nbTracks +% sceneObjects(c).classLabel + idx = find(contains(classLabels, sceneObjects(c).classLabel)); +% classType(idx) + if isempty(idx) +% disp(sceneObjects(c).classLabel) +cmap(c,:) = zeros(1, 3); + else + % if (sceneObjects(c).isBackground) + % cmap(c,:) = hsl2rgb([hues(classType(idx)), .7, .5]); + % else + cmap(c,:) = hsl2rgb([hues(classType(idx)), 1, .5]); + end + % end +end \ No newline at end of file diff -r d0ceb549f734 -r 39399de892ef nonExposed/randomColormap.m --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/nonExposed/randomColormap.m Fri Jun 09 16:37:50 2017 +0200 @@ -0,0 +1,41 @@ +function cmap = randomColormap (sceneObjects) +% returns a colormap with randomly chosen colors somewhat evenly spread in +% the color spectrum, to be used for the graphical representations of a +% synthesized scene. + +% Background sounds will have a saturation of .3, foreground sounds of 1 +% Value is always let to .5, since modifying it would erroneously suggest +% a difference of intensity + +% This program was written by Mathias Rossignol & Grégoire Lafay +% is Copyright (C) 2015 IRCAM +% +% This program is free software: you can redistribute it and/or modify it +% under the terms of the GNU General Public License as published by the Free +% Software Foundation, either version 3 of the License, or (at your option) +% any later version. +% +% This program is distributed in the hope that it will be useful, but +% WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +% or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +% for more details. +% +% You should have received a copy of the GNU General Public License along +% with this program. If not, see . + +nbTracks = length(sceneObjects); + +% Colors for figures +% Choosing color hues evenly spread in the color spectrum, then randomizing their order +hues = (0:1/nbTracks:1); +hues = hues(1:nbTracks); +hues = hues(randperm(nbTracks)); +% Generate a colormap: +for c=1:nbTracks + if (sceneObjects(c).isBackground) + cmap(c,:) = hsl2rgb([hues(c), .3, .5]); + else + cmap(c,:) = hsl2rgb([hues(c), 1, .5]); + end +end +end \ No newline at end of file diff -r d0ceb549f734 -r 39399de892ef nonExposed/timeDomainVisualization.m --- a/nonExposed/timeDomainVisualization.m Mon May 22 10:46:10 2017 +0200 +++ b/nonExposed/timeDomainVisualization.m Fri Jun 09 16:37:50 2017 +0200 @@ -20,7 +20,7 @@ step=0.5; % seconds wStep = round(step*settingFigure.sr); wSize = wStep*2; -for t=1:size(tracks,1); +for t=1:size(tracks,1) for i=0:floor((size(tracks,2)-wSize)/wStep) % Not really power, but more nicely additive, better suited for % this representation I think @@ -29,6 +29,7 @@ end powers(powers