recolor an image

Contents

my rgb image

n = 0;
switch n
    case 1
        filename = 'Rosie_and_me.jpg';
    case 2
        filename = 'flowers4.png';
    otherwise
        filename = 'loomis.jpg';
end
rgb = imread(filename);
imshow(rgb);

256 colors

[X map] = rgb2ind(rgb,256);
imshow(X,map);

16 colors

[X2 map2] = rgb2ind(rgb,16);
imshow(X2,map2);

8 colors

[X3 map3] = rgb2ind(rgb,8,'nodither');
imshow(X3,map3);

look at colormap (very boring)

Xd=zeros(32,32*8);
for n=1:7
Xd(:,n*32+(1:32))=n;
end
Xd = int8(Xd);
imshow(Xd,map3);

look at chroma (very uncolorful)

x = map3*[1 -0.5 -0.5]';
y = map3*[0  1 -1]'*sqrt(3)/2;
z = map3*[1 1 1]'/3;
plot(x,y,'k.');
axis square
axis([-1 1 -1 1]);
grid;

pseudo-color

imshow(X3,jet(8));

try imapprox, no dithering

[Y, newmap] = imapprox(X,map,8,'nodither');
imshow(Y,newmap);

imapprox (with dithering)

[Y, newmap] = imapprox(X,map,8);
imshow(Y,newmap);