From 21f7b2280728ff5e013b98dd22607f4031f59bca Mon Sep 17 00:00:00 2001
From: Elian Dib <elian.dib@inria.fr>
Date: Fri, 5 Jul 2019 12:12:26 +0200
Subject: [PATCH] Added function to convert labels to colors

---
 colorLabels.m | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 colorLabels.m

diff --git a/colorLabels.m b/colorLabels.m
new file mode 100644
index 0000000..f8b7029
--- /dev/null
+++ b/colorLabels.m
@@ -0,0 +1,39 @@
+function labels = colorLabels(labels,varargin)
+%COLORLABELS Summary of this function goes here
+%   Detailed explanation goes here
+
+cmap = jet(max(labels(:)));
+shuffle = false;
+gray = ones(size(labels));
+coldim = 3;
+
+p = inputParser();
+
+p.addParameter('cmap'   , cmap   , @isnumeric);
+p.addParameter('shuffle', shuffle, @(x) isnumeric(x)||islogical(x));
+p.addParameter('gray'   , gray   , @isnumeric);
+p.addParameter('coldim' , coldim , @isnumeric);
+
+p.parse(varargin{:});
+
+cmap    = p.Results.cmap;
+shuffle = p.Results.shuffle;
+gray    = p.Results.gray;
+coldim  = p.Results.coldim;
+
+if shuffle
+    rng('default');
+    sigma = randperm(size(cmap,1));
+    cmap = cmap(sigma,:);
+end
+
+order = 1:(ndims(gray)+1);
+order(coldim) = ndims(gray)+1;
+order(ndims(gray)+1) = coldim;
+
+labels = cmap(labels(:),:);
+labels = reshape(labels,[size(gray),3]);
+labels = permute(labels,order);
+labels = labels.*gray;
+
+end
\ No newline at end of file
-- 
GitLab