Tuesday, May 31, 2011

How to use matlab to convert a picture to 8 colors (for Threadless.com)

A friend of mine wanted to make a t-shirt design for threadless. But one of the recommendations is that the picture only have 8 colors. It wasn't obvious to us how to do that in a photo editing program, so I tried it in matlab, which turned out to be quite easy if you have the image processing toolbox (for the rgb2ind function).
RGB = imread(filename); % read RGB image file
[IND,map]=rgb2ind(RGB,8,'nodither'); % convert to 8 colors
imwrite(IND,map,filename2); % save new reduced color image file
I tried it with and without the 'nodither' option. Most pictures I tried looked better with the dither. See one example below:
original picture with more than 8 colors
8 colors - dither
8 colors - no dither

No comments:

Post a Comment