annotate toolboxes/FullBNT-1.0.7/KPMtools/image_rgb.m @ 0:e9a9cd732c1e tip

first hg version after svn
author wolffd
date Tue, 10 Feb 2015 15:05:51 +0000
parents
children
rev   line source
wolffd@0 1 function image_rgb(M)
wolffd@0 2 % Show a matrix of integers as a color image.
wolffd@0 3 % This is like imagesc, except we know what the mapping is from integer to color.
wolffd@0 4 % If entries of M contain integers in {1,2,3}, we map
wolffd@0 5 % this to red/green/blue
wolffd@0 6
wolffd@0 7 cmap = [1 0 0; % red
wolffd@0 8 0 1 0; % green
wolffd@0 9 0 0 1; % blue
wolffd@0 10 127/255 1 212/255]; % aquamarine
wolffd@0 11 image(M)
wolffd@0 12 set(gcf,'colormap', cmap);
wolffd@0 13
wolffd@0 14 if 1
wolffd@0 15 % make dummy handles, one per object type, for the legend
wolffd@0 16 str = {};
wolffd@0 17 for i=1:size(cmap,1)
wolffd@0 18 dummy_handle(i) = line([0 0.1], [0 0.1]);
wolffd@0 19 set(dummy_handle(i), 'color', cmap(i,:));
wolffd@0 20 set(dummy_handle(i), 'linewidth', 2);
wolffd@0 21 str{i} = num2str(i);
wolffd@0 22 end
wolffd@0 23 legend(dummy_handle, str, -1);
wolffd@0 24 end
wolffd@0 25
wolffd@0 26 if 0
wolffd@0 27 [nrows ncols] = size(M);
wolffd@0 28 img = zeros(nrows, ncols, 3);
wolffd@0 29 for r=1:nrows
wolffd@0 30 for c=1:ncols
wolffd@0 31 q = M(r,c);
wolffd@0 32 img(r,c,q) = 1;
wolffd@0 33 end
wolffd@0 34 end
wolffd@0 35 image(img)
wolffd@0 36 end