List Info

Thread: Re: Perl code and median cut palettizing




Re: Perl code and median cut palettizing
country flaguser name
United States
2007-03-02 18:06:13
From: Adrian McMenamin
> Currently my code goes through the colour space
repeatedly cutting the
> boxes up - ie going from 1 to 2 to 4 to 8 to 16 to ...
256 boxes, but it
> seems that somewhere along the way I am always likely
to end up with a box
> with just one point in the colourspace in it and that,
obviously, is not
> susceptible to redivision.

See Graphics Gems volume 1, but, in general, I've found that
algorithms like
median cut tend (with at least some images) to produce
colour tables which
are difficult to dither to.  That's because the algorithms
tend not to span
the colour space of the image - i.e. there are some colours
in the image
which are beyond the bounding cube of all the colours in the
palette.  I
generally put in the 8 corners of the colour cube (i.e.
(0,0,0)->(1,1,1)) to
avoid problems with this.

I've also found that using the 'optimal' 6x6x6 (216 colour)
palette
frequently works as well as an optimised palette,
particularly if the
remaining entries are used for grey levels (dithering greys
out of colours
tends to look bad.)  Here are a couple of rules I think are
useful, though
I've never properly tested them:

1) Ensure that the values at the 8 corners of the bounding
box of the
colours are present.  If you want, divide the colours up
first and apply the
restriction to the sub-groups of colours.

2) Always dither the ouput unless you know for sure that all
the colours you
need are present.  (Either all the colours are in the
palette, or you happen
to know which image pixels are solid colours and which are
continuous tone -
which is only likely if you have control over the software
generating the
image.)

If you don't dither you get bad, very noticeable, aliasing
in the form of
bands in any region of slowly varying colour.  If the
palette is a bad
choice from the point of view of human perception then such
areas will show
obvious dithering, in the form of obvious dither patterns
(because the
dithered colours contrast too much with each other.)

John Bowler <jbowleracm.org>


------------------------------------------------------------
-------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the
chance to share your
opinions on IT & business topics through brief
surveys-and earn cash
http://www.techsay.com/default.
php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
png-mng-implement mailing list
png-mng-implementlists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/png-m
ng-implement

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )