comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:e9a9cd732c1e
1 function image_rgb(M)
2 % Show a matrix of integers as a color image.
3 % This is like imagesc, except we know what the mapping is from integer to color.
4 % If entries of M contain integers in {1,2,3}, we map
5 % this to red/green/blue
6
7 cmap = [1 0 0; % red
8 0 1 0; % green
9 0 0 1; % blue
10 127/255 1 212/255]; % aquamarine
11 image(M)
12 set(gcf,'colormap', cmap);
13
14 if 1
15 % make dummy handles, one per object type, for the legend
16 str = {};
17 for i=1:size(cmap,1)
18 dummy_handle(i) = line([0 0.1], [0 0.1]);
19 set(dummy_handle(i), 'color', cmap(i,:));
20 set(dummy_handle(i), 'linewidth', 2);
21 str{i} = num2str(i);
22 end
23 legend(dummy_handle, str, -1);
24 end
25
26 if 0
27 [nrows ncols] = size(M);
28 img = zeros(nrows, ncols, 3);
29 for r=1:nrows
30 for c=1:ncols
31 q = M(r,c);
32 img(r,c,q) = 1;
33 end
34 end
35 image(img)
36 end