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