matthiasm@8: function image_rgb(M) matthiasm@8: % Show a matrix of integers as a color image. matthiasm@8: % This is like imagesc, except we know what the mapping is from integer to color. matthiasm@8: % If entries of M contain integers in {1,2,3}, we map matthiasm@8: % this to red/green/blue matthiasm@8: matthiasm@8: cmap = [1 0 0; % red matthiasm@8: 0 1 0; % green matthiasm@8: 0 0 1; % blue matthiasm@8: 127/255 1 212/255]; % aquamarine matthiasm@8: image(M) matthiasm@8: set(gcf,'colormap', cmap); matthiasm@8: matthiasm@8: if 1 matthiasm@8: % make dummy handles, one per object type, for the legend matthiasm@8: str = {}; matthiasm@8: for i=1:size(cmap,1) matthiasm@8: dummy_handle(i) = line([0 0.1], [0 0.1]); matthiasm@8: set(dummy_handle(i), 'color', cmap(i,:)); matthiasm@8: set(dummy_handle(i), 'linewidth', 2); matthiasm@8: str{i} = num2str(i); matthiasm@8: end matthiasm@8: legend(dummy_handle, str, -1); matthiasm@8: end matthiasm@8: matthiasm@8: if 0 matthiasm@8: [nrows ncols] = size(M); matthiasm@8: img = zeros(nrows, ncols, 3); matthiasm@8: for r=1:nrows matthiasm@8: for c=1:ncols matthiasm@8: q = M(r,c); matthiasm@8: img(r,c,q) = 1; matthiasm@8: end matthiasm@8: end matthiasm@8: image(img) matthiasm@8: end