[Keith Vetter] 2006-07-22 : is a technique used in computer graphics to create the illusion of color depth in images with a limited color palette (color quantization). In a dithered image, colors not available in the palette are approximated by a diffusion of colored pixels from within the available palette. [http://en.wikipedia.org/wiki/Dither] Here some code that implemenents some dithering algorithms, along with the requisite demo code. The code here is only for gray-scaled images but could easily be extended to color images. Also, another improvement would be to use an optimized paletter before dithering (see [Reduce Colour Depth - Median Cut]). This was a really fun project. To save space in the wiki, I didn't include a sample image in the demo. Instead, I tried linking to tcl demo images and images from the web (I included some famous image processing images such as Lena). For fun, try out some of the various web images I included links for and see a) how many colors are needed by the various algorithms to look good, and b) how badly some algorithms are with certain images at different color depths. For example, try the tcl demo code image of the teapot at just 2 colors and then 3 colors. ---- ##+########################################################################## # # dither.tcl -- Plays with various types of dithering # by Keith Vetter, May 2006 # # image source: http://sipi.usc.edu/database/database.cgi?volume=misc # dithering overview: http://www.visgraf.impa.br/Courses/ip00/proj/Dithering1/algoritmos_desenvolvidos.htm # package require Tk package require http package require Img if {! [catch {package require tile 0.7.2}]} { ;# Use tile if present namespace import -force ::ttk::button } set S(title) "Dithering" set S(numShades) 2 set S(status) blank set lenaURL http://www.visgraf.impa.br/Courses/ip00/proj/Dithering1/image/lena.gif set teapotImg [file join $tk_library demos images teapot.ppm] set images {} lappend images [list Lena $lenaURL] lappend images [list "Lena (full size)" http://sipi.usc.edu/services/database/misc/4.2.04.tiff] lappend images [list "Mandrill" http://sipi.usc.edu/services/database/misc/4.2.03.tiff] lappend images [list "Sailboat on lake" http://sipi.usc.edu/services/database/misc/4.2.06.tiff] lappend images [list "Elaine" http://sipi.usc.edu/services/database/misc/elaine.512.tiff] lappend images [list "Gray Scale" http://www.sput.nl/images/grey2.gif] lappend images [list "Gray Scale 2" http://support.sas.com/techsup/technote/ts688/gray.gif] lappend images {- -} lappend images [list Teapot $teapotImg] lappend images [list Earth [file join $tk_library demos images earth.gif]] lappend images [list "Active Tcl Splash" [file join $tk_library images activetclsplash.gif]] lappend images [list "Bliss Wallpaper" [file join $env(windir) Web/Wallpaper/Bliss.bmp]] ---- [Category Graphics] | [Category Image Processing] | [Category Algorithm]