got colors? Color Quantization Techniques Joo Hyun Song 1 Outline • • • • Overview Implementation Results and Discussion Concluding Remarks 2 Overview • What is color quantization? – “Color quantization is applied when the color information of an image is to be reduced.“ 1 – “The most common case is when a 24-bit color image is transformed into an 8-bit color image.” 1 – Used when high-depth color is not supported or necessary. 1 http://www.dai.ed.ac.uk/HIPR2/quantize.htm 3 Overview (cont’d) • Main issues concerning color quantization – What are the criteria for colors that are retained in the resulting image? (How are the ‘important’ colors selected?) – How ‘accurate’ is the resulting image? (How well are the important features of the image preserved in the resulting image?) – How fast is the quantization process? 4 Implementation • Diversity Algorithm 2 – Color quantization algorithm devised by John Bradley, the creator of the popular UNIX-based imaging software xv. – The algorithm starts by picking the most populous color (the overall color) of the original image. – Then the most ‘distant’ colors from the colors in the new color table are picked until the new color table is filled. – Results in the most ‘diverse’ selection of colors surrounding the overall color. 2 http://www.trilon.com/xv/manual/xv-3.10a/diversity-algorithm.html 5 Implementation (cont’d) • Modified Diversity Algorithm 2 – Improvement over the original Diversity Algorithm suggested by Tom Lane of the Independent JPEG Group. – The modification aims to better balance the allocation between diverse colors and populous colors. – The alternation strategy is subjective – some strategy works better in certain images while not as good in other. – Examples in this presentation use the 10-div-pop/div rule. 6 Implementation (cont’d) • ImageMagickTM 3 libraries and tools – Provides readily available libraries and tools for reading, manipulating and writing most of the popular image formats. • Programming Language of choice: C++ – C++ has std::vector and std::map datatypes that made the histogram and colorMap implementation simpler. – C++ has a built-in optimized sort() function that can be used for sorting elements in std::vector datatypes. – Not Java. ;-) 3 http://www.imagemagick.org/ 7 Test Images 8 Results • Tested Algorithms – Diversity Algorithm – Modified Diversity Algorithm • Tested Color Spaces – – – – – RGB YUV YIQ XYZ U*V*W* (not really) 9 Original Diversity vs. Modified Diversity Original Diversity Algorithm (RGB) Modified Diversity Algorithm (RGB) 10 Original Diversity vs. Modified Diversity (cont’d) Original Diversity Algorithm (RGB) Modified Diversity Algorithm (RGB) 11 Original Diversity vs. Modified Diversity (cont’d) Original Diversity Algorithm (RGB) Modified Diversity Algorithm (RGB) 12 Color Space Comparisons Original YUV RGB XYZ 13 Color Space Comparisons Original YUV RGB XYZ 14 Color Space Comparisons Original YUV RGB XYZ 15 Weird… U*V*W* (supposedly) 16 My U*V*W* Implementation double DecodeUVW(const unsigned int color, const char opt) { double X = DecodeXYZ(color, 'x'); double Y = DecodeXYZ(color, 'y'); double Z = DecodeXYZ(color, 'z'); double x = X/(X+Y+Z); double y = Y/(X+Y+Z); double u = 4*x/(-2*x+12*y+3); double v = 6*y/(-2*x+12*y+3); double W = 25*pow(100*Y, 1/3)-17; // Get reference white X = DecodeXYZ(0xFFFFFF, 'x'); Y = DecodeXYZ(0xFFFFFF, 'y'); Z = DecodeXYZ(0xFFFFFF, 'z'); x = X/(X+Y+Z); y = Y/(X+Y+Z); double u0 = 4*x/(-2*x+12*y+3); double v0 = 6*y/(-2*x+12*y+3); if(opt == 'u') { return 13*W*(u-u0); } if(opt == 'v') { return 13*W*(v-v0); } if(opt == 'w') { return W; } } 17 Future Interest • Investigate more advanced color spaces (such as L*u*v* or IHS). • Investigate other color metrics (e.g. Riemannian color space). • Investigate more advanced color quantization algorithms (such as the Neural Networks color quantization algorithm). 18 Performance of other programs • ImageMagick’s built-in quantizeColors() algorithm 19 Performance of other programs (cont’d) • Gimp 20 What I Have Learned 1. Start EARLY 2. Subjectivity of image quality. 3. Different Color Spaces. 4. Don’t use ImageMagick 21 Any Questions? 22