changeset 34:39399de892ef

better handling of displays with pleasantness colors
author Mathieu Lagrange <mathieu.lagrange@cnrs.fr>
date Fri, 09 Jun 2017 16:37:50 +0200
parents d0ceb549f734
children 5d19c2254677
files nonExposed/checkClassPresence.m nonExposed/coloredSpectrumVisualization.m nonExposed/generateColormap.m nonExposed/generateScene.m nonExposed/pianoRollVisualization.m nonExposed/pleasantnessColormap.m nonExposed/randomColormap.m nonExposed/timeDomainVisualization.m
diffstat 8 files changed, 186 insertions(+), 78 deletions(-) [+]
line wrap: on
line diff
--- 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
     
 
--- 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
 
--- 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 <http://www.ircam.fr>
-%
-% 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 <http://www.gnu.org/licenses/>.
-
-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
--- 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
--- 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
 
+
--- /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 <http://www.ircam.fr>
+%
+% 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 <http://www.gnu.org/licenses/>.
+
+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
--- /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 <http://www.ircam.fr>
+%
+% 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 <http://www.gnu.org/licenses/>.
+
+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
--- 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<max(powers(:))/500) = 0;
+powers = gaussianSmoothing(powers', 15)';
 
 switch figuresOption
     case 1
@@ -39,19 +40,46 @@
 
 
 clf;
-area(powers,'LineWidth', 1/1.6, 'EdgeColor', [.3, .3, .3]);
+h = area(powers,'LineWidth', 2, 'EdgeColor', [.2, .2, .2]);
+for t=1:size(tracks,1)
+    h(t).FaceColor = settingFigure.cmap(t, :);
+end
+
 xlim([0 size(powers,1)])
 xtick=0:round(20/step):size(powers,1); % every 20 sec
 set(gca,'YTick', [],'YTicklabel', [],'xtick',xtick,'xticklabel',xtick*step);
 xlabel('time (sec)')
+% ylabel('amplitude')
 
-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')
 
+box off %// remove outer border
+set(gca,'ycolor', [1 1 1]);
+ax1 = gca;
+yruler = ax1.YRuler;
+yruler.Axle.Visible = 'off';
+
+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(gca,'ycolor', [1 1 1]);
+    print(f,fileName,'-dpng')
 end
+
+
+function as = gaussianSmoothing(as, factor)
+
+if ~exist('factor', 'var'), factor = 200; end
+
+% gaussian filtering for smooth display
+g = gausswin(ceil(size(as, 2)/factor)); % shall adapt the size to the length of the file
+g = g/sum(g);
+for k=1:size(as, 1)
+    as(k, :) = conv(as(k, :), g, 'same');
+end
+
+