diff --git a/colorLabels.m b/colorLabels.m new file mode 100644 index 0000000000000000000000000000000000000000..f8b7029b1aa55f6de5301d429705a287cd7040c8 --- /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