On Estimation of the Number of Image Principal Colors and Color Reduction through Self-Organized Neural Networks A. Atsalakis, N. Papamarkos, I. Andreadis Division of Electronics and Information Systems Technology, Department of Electrical and Computer Engineering, Democritus University of Thrace, 67100 Xanthi, Greece. Received 11 November 2001; Accepted 1 April 2002
ABSTRACT: A new technique suitable for reduction of the number of colors in a color image is presented in this article. It is based on the use of the image Principal Color Components (PCC), which consist of the image color components and additional image components extracted with the use of proper spatial features. The additional spatial features are used to enhance the quality of the final image. First, the principal colors of the image and the principal colors of each PCC are extracted. Three algorithms were developed and tested for this purpose. Using Kohonen self-organizing feature maps (SOFM) as classifiers, the principal color components of each PCC are obtained and a look-up table, containing the principal colors of the PCC, is constructed. The final colors are extracted from the look-up table entries through a SOFM by setting the number of output neurons equal to the number of the principal colors obtained for the original image. To speed up the entire algorithm and reduce memory requirements, a fractal scanning subsampling technique is employed. The method is independent of the color scheme; it is applicable to any type of color images and can be easily modified to accommodate any type of spatial features. Several experimental and comparative results exhibiting the performance of the proposed technique are presented. © 2002 Wiley Periodicals, Inc. Int J Imaging Syst Technol, 12, 117–127, 2002; Published online in Wiley InterScience (www.interscience.wiley.com). DOI 10.1002/ima.10019
I. INTRODUCTION Computer images occupy an extensive are of the information used in computer technology. Usually, true type color images consist of more than 16 million different colors in a 24-bit full (RGB) color space. Reduction of the image colors, which is also called color quantization, is a process that reduces the image colors to a predefined number of image principal colors. It is a very useful tool for segmentation, compression, presentation, and transmission of images. In most cases, it is easier to process and understand an image with a limited number of colors. Color reduction can be achieved through a color quantization technique. Such a technique consists of two main steps: a palette design step, in which a reduced number of palette colors are specified; and a pixel mapping step, in which each color pixel is assigned to one of the colors in the palette. The color quantization techniques group similar colors and replace them with Correspondence to: N. Papamarkos
© 2002 Wiley Periodicals, Inc.
only a single “quantized” color (Ashdown, 1994; Dekker, 1994; Gervautz and Purgathofer, 1990; Heckbert, 1982). The ultimate goal of the classical color quantization techniques is to reduce the number of colors of an image with minimum distortion (Velho et al., 1997). Therefore, the main objective of computer graphics research in the color quantization area is to select an optimal palette that guarantees minimization of a perceived difference between the original and the quantized images (Wan et al., 1990). The problem can be considered an unsupervised classification of the three-dimensional (3D) color space, each class being represented by one palette color. Since an RGB image can contain millions of distinct colors, the classification problem involves a large number of data points in a low dimensional space. Several techniques have been proposed for color quantization. First, there is the class of splitting algorithms that divide the color space into disjoint regions, by consecutively splitting up the color space. From each region, a color is chosen to represent it in the color palette. In this case belong the median-cut algorithm (Heckbert, 1982), the octree quantization (Ashdown, 1994; Gervautz and Purgathofer, 1990), and the variance-based algorithm (Wan et al., 1990). Other splitting algorithms, which incorporate techniques that take into account the human visual system, were introduced (Balasubramanian and Allebach, 1990; Balasubramanian et al., 1994). A good comparison of color quantization techniques is given in Scheunders (1997). Another class of quantization techniques considers the problem as a clustering approach and performs clustering of the color space to construct the color palettes. Usually, the centers of the obtained color classes are taken as the principal image colors. In this category, the classifiers used can be based on statistical or neural networks approaches. In the first category belongs the quantization technique based on the C-means clustering algorithms (Shafer and Kanade, 1987). In the second category belong methods such as those based on self-organizing feature maps (SOFM) neural networks (Dekker, 1994; Papamarkos, 1999; Papamarkos et al., 2000, 2002; Papamarkos and Atsalakis, 2000). In general, the color quantization techniques are suitable for eliminating uncommon colors in an image by examining only the contribution of the image colors in the color space. However, they are ineffective for image analysis and segmentation. The quality of the resultant image varies depending on the number of the final
colors and the algorithm intelligence. Color quantization techniques are usually used for the reduction of the colors in an image to a relatively large number of colors. These techniques are not good enough to produce images with a very limited number of colors. Also, the color quantization techniques do not consider any specifications associated with the texture (i.e., the spatial characteristics of the final image). In addition, none of the color quantization techniques offer a simple procedure for estimation of the optimal number of the image principal colors. This is important, especially for segmentation tasks, in which the image color tones are well separated. For example, in complex color documents, the colors of text regions may not be solid but are well separated from background. The color reduction technique proposed in this article considers the color space as a union of the image color components and additional components extracted from suitable spatial features. We consider all these components as the image primary color components (PCC). For example, if the RGB color scheme is used, then the PCC correspond to the R, G, and B images, and additional grayscale images obtained by the extracted spatial features in the image color components. Thus, every pixel corresponds not only to the image color components but also to a set of suitable spatial features, which are extracted from neighboring pixels. These features are associated with spatial image characteristics, such as min, max, gradient values, entropy values, and so on. Through this, the color reduction process can be considered an unsupervised technique that classifies the content of the image PCC into a limited number of classes. The selection of suitable spatial features leads to quantized images that approximate the texture defined by the features used. In comparison to the previous techniques, the proposed approach offers an unsupervised estimation of the image principal colors and requires significantly less memory and computation time. As mentioned above, the proposed color reduction technique requires initial estimation of the number of principal colors for every PCC. In spite of the fact that the problem of estimation of the number of principal color values in an image is of the utmost importance, only a few techniques have been proposed so far (Papamarkos and Gatos, 1994; Shafarenko et al., 1998; Chang et al., 1994). To solve the problem of estimation of the number of principal colors in an image, three techniques have been developed and tested. In the next stage, the image principal colors or each PCC and frame are estimated by clustering the image histograms with SOFM neural networks. The number of output neurons that correspond to the number of principal colors for each color component is defined by using the piecewise histogram approximation (PWHA) algorithm. In order to reduce both storage requirements and computation time, the training set can be a representative sample of the image pixels. In our approach, the subsampling is performed via a fractal scanning technique based on the Hilbert’s space-filling curve (Sagan, 1994). The proposed method was tested with a variety of images and the results are compared to other color reduction techniques. In comparison to previous techniques based on Kohonen SOFM, the proposed technique offers a method for estimating the optimal number of image principal colors without any requirement for an adaptive procedure. Also, because it decomposes a large classification problem, it is faster, offers the flexibility of different feature sets in each PCC, and is suitable for reduction of the image colors to a small number. To demonstrate the advantages of the proposed technique, characteristic examples are presented. The entire technique has been
118
Vol. 12, 117–127 (2002)
implemented in a visual environment and the program can be downloaded from the site: http://ipml.ee.duth.gr/⬃papamark/. II. DESCRIPTION OF THE METHOD A color image can be considered as a set of n ⫻ m pixels, in which the color of each pixel is a point in the color space. There are many color spaces used for color images. However, the proposed method can be applied to any type of color space. A color space can be considered a 3D vector space, in which each pixel (i, j) is associated with an ordered triplet of color components [c1(i, j), c2(i, j), c3(i, j)]. Therefore, a general color image function can be defined by the relation
再
c 1共i, j兲,if k ⫽ 1 I k共i, j兲 ⫽ c2 共i, j兲, if k ⫽ 2 . c3 共i, j兲, if k ⫽ 3
(1)
Each PCC represents an intensity that varies from zero to a maximum value. For example, in the RGB space, color allocation is defined over a domain consisting of a cube, with opposite vertices at (0, 0, 0) and (C r_max, C g_max, C b_max). Usually, C r_max ⫽ C g_max ⫽ C b_max ⫽ 255. According to the above analysis, each PCC gives a histogram; therefore, a color image has three independent 1D histograms: H k, j , k ⫽ 1, 2, 3, and j ⫽ 0, . . . , 255. Let also N(i, j) represent the local neighboring region of pixel (i, j). Usually, N(i, j) is considered to be a 3 ⫻ 3 or a 5 ⫻ 5 mask, in which the pixel (i, j) is the center pixel of the mask. We assume that every pixel (i, j) belongs to its neighborhood N(i, j). It can be considered that the color of each pixel is associated with the colors of the neighboring pixels and the local texture of the image. Therefore, the PCCs of each pixel (i, j) can be associated with local image characteristics extracted from the region N(i, j). In each PCC, the local characteristics can be considered local spatial features of the image, and this is helpful for the color reduction process; that is, by using the values of N(i, j), f k , k ⫽ 2, 3, . . . , K ⫹ 1, local features can be defined, each one extracted from every PCC that are next considered as image spatial features. This approach transforms the 3D color feature space of the classical color quantization techniques to a new one of 3K ⫹ 3 dimensions. No restrictions are implied regarding the type of the local features. However, features must represent simple spatial characteristics, such as min, max, entropy, median values of the neighboring masks, and so on. According to the previously stated concepts, the color quantization problem can be considered a color reduction problem that best transforms the original color image into a new one, with only J colors, so that the final image approximates not only the principal color values but also the local characteristics used. An effective approach to tackle this problem is to consider it as a clustering problem and solve it through a suitable classification technique. In the various stages of the proposed color quantization technique, we use as classifier a powerful Kohonen SOFM (Kohonen, 1997; Haykin, 1994). The color quantization technique consists of the following summarized stages: Stage 1. Stage 2. Stage 3. Stage 4. Stage 5.
Selection of the color scheme. Definition of the spatial features. Estimation of the optimal number of image colors. Training of the neural classifiers. Estimation of the final colors and image conversion into these colors.
Figure 1.
Flowchart of the entire technique.
Figure 1 shows a complete flowchart of the proposed technique. Next, a detailed analysis of the above stages is provided. A. Selection of the Color Scheme. The proposed technique can be used with any color space. In our implementation we have used the RGB, HSI, and YIQ color spaces (Russ, 1994). However, we have found that the RGB color scheme provides the best results. The HSI scheme, and more specifically the Hue component, can be used for the estimation of the final image colors. B. Definition of the Spatial Features. In this stage, we must define the spatial features that will be used with each PCC. The proposed color quantization technique uses not only the PCC but also features associated with the additional spatial characteristics. In practice, these features correspond to additional image frames. For example, the application of the median operation to R component produces a new image, the content of which defines the values for this feature. Therefore, if we use the RGB color model and specify that in the R, G, and B color components, N R , N G , and N B features will be used as additional features, respectively, then the system has to deal with N R ⫹ N G ⫹ N B spatial features. The appropriate selection of the spatial features is important because the system utilizes these features in such a way that the final image approximates the image spatial characteristics provided by them. For example, features based on edge extraction mask (such as Prewitt, Laplace, etc.) enhance the edges of the final image and are thus suitable when the original image represents a complex document with poorly illuminated regions. Also, for blurred images, we can use sharpening features (i.e., features extracted by using sharpening masks) such as
冉
0 ⫺1 0
⫺1 0 5 ⫺1 ⫺1 0
冊冉 ,
⫺1 ⫺1 ⫺1 ⫺1 9 ⫺1 ⫺1 ⫺1 ⫺1
冊冉 ,
1 ⫺2 1 ⫺2 5 ⫺2 1 ⫺2 1
冊
Finally, for noisy images, we can use features associated with linear or nonlinear filters, such as mean and median filters.
C. Estimation of the Optimal Number of Image Colors. As mentioned above, the proposed color quantization technique uses not only the PCC but also features associated with additional spatial characteristics. The proposed technique requires the estimation of the optimal number of the principal gray-scale values (ONPGV) for each PCC constructed by the spatial features (considering these as gray-scale images). Also, the proposed technique requires the estimation of the optimal number of the image principal colors, that is, the number of unique colors in the final image that must be initially given or estimated. This problem is not an easy task, and the majority of color quantization or reduction schemes do not solve it. In our approach, the ONPGV can be estimated initially by applying the same procedure as in the case of PCC, in a selected image component. Usually, the Hue or gray-scale component of the color image is used for the estimation of the number of the image principal colors. The ONPGV can be introduced arbitrarily, or even better, can be estimated through an automatic procedure. The automatic estimation of the ONPGV in an image is an important but not a simple task. The literature in this field is poor. Such techniques can be based on cluster analysis and cluster validation testing. In our approach, we have developed and used the following three techniques for the estimation of the ONPGV in a gray-scale image: 1. A piecewise histogram approximation. 2. A histogram-smoothing algorithm. 3. Approximation of the histogram by a Kohonen SOFM. A detailed description of these techniques is given in Section III. D. Training of the Neural Classifiers. In the previous stage, we have estimated the ONPGV for each one of the PCC and for every image frame associated with the spatial features used. In this stage, we use Kohonen SOFM neural networks to obtain the principal gray-scale values for these images; that is, every PCC and frame image is considered as an independent gray-scale image.
Vol. 12, 117–127 (2002)
119
Figure 2.
(a) Hilbert’s curve-constructing rule; (b) subsampling example.
However, for normalization reasons, the values of the image frames can be mapped in the range [0, 255]. The Kohonen SOFM neural network used in every image has one input neuron, whereas the number of the output neurons is equal to the ONPGV for this image, obtained in the previous stage. The main goal of the Kohonen SOFM neural network is to classify a set of vectors into one- or twodimensional matrices. It transforms the input space of arbitrary dimension into a one- or two-dimensional discrete map, subject to topological (neighborhood preserving) constraints. Each neuron in the output competition layer represents one feature class. By adjusting the number of the output neurons, we can define the number of the colors of the images. In general, the output J neurons of a Kohonen SOFM neural network are related to the input N neurons via the q j,i , i ⫽ 1, . . . , N, and j ⫽ 1, . . . , J coefficients. The SOFM is competitively trained according to the following weight update function:
再
a共y i ⫺ q ji兲,if 兩c ⫺ j兩 ⱕ d ⌬q ji ⫽ 0, otherwise for
i ⫽ 1, . . . , N and j ⫽ 1, . . . , J
(2)
where y j is the input values, a is the learning parameter, d is the neighboring parameter (a typical initial value is less than 0.8N), and c is the winner neuron. The values of parameters a and d are reduced during the learning process. This learning algorithm is referred to as Kohonen’s learning. After training, the optimal color values correspond to the centers of the classes obtained by the neural network. Next, the image (the PCC or the frame image) is rescanned and by using the neural network, we construct a new image having only the J values obtained through the neural network. This procedure is applied independently to each one of the PCC and frame images. Thus, after this stage, the original PCC and frame images are mapped to new images having only the principal colors. 1. Image Subsampling. The Kohonen SOFM color reduction technique can be applied to images without any subsampling. However, in the case of large-size images, and in order to achieve reduction of the computational time and memory size, it is advan-
120
Vol. 12, 117–127 (2002)
tageous to employ a subsampling version of the original image. In order for the subsampled image to be a better representation (to capture more precisely the image texture) of the original one, we have chosen a fractal scanning process, based on the well-known Hilbert’s space filling curve (Sagan, 1994). This technique of fractal scanning is much more efficient in capturing features in a digital image than the commonly used techniques of raster scanning, which do not maintain the adjacency of the features in the image, because their scanning direction is usually not identified with the one that the features specify. Feature extraction is more substantial when we succeed in retaining the neighborhood relationship between the pixels. Thus, it is desirable that a technique scan one area of the image completely before moving to the next. To generate the Hilbert curve, we must start with the basic staple-like shape, as depicted in Figure 2(a). The rest of the Hilbert curve is created sequentially, with the same algorithm. Starting with the basic Hilbert curve in each step, we increase the grid size by the factor of two. Then, we place four copies of the previous curve on the grid. The lower two copies are placed directly as they are. The upper-left quarter is rotated 90° counterclockwise and the upperright quarter by 90° clockwise. Finally, the four pieces are connected with short, straight segments to obtain the next step curve. An example of the subsampling process is illustrated in Figure 2(b). A complete description of the Hilbert’s curve can be found in Sagan (1994). E. Estimation of the Final Colors and Image Conversion. In this final stage, the principal colors of the PCC, obtained in the previous stage, are fed into a new Kohonen SOFM neural network and obtain the final colors of the original color image. Specifically, let us assume that the RGB color space is used and we have N r , N g , and N b image frames. This means that we have 3 ⫹ N r ⫹ N g ⫹ N b , gray-scale–like images, having J r , J g , J b , J 1,r , . . . , J 1, Nr , J 1,g , . . . , J 1, Ng , and J 1b , . . . , J 1, Nb reduced number of values, respectively. As shown in Figure 1, these images feed a Kohonen SOFM neural network constructed of 3 ⫹ N r ⫹ N g ⫹ N b input neurons and J op output neurons. The structure of the SOFM is shown in Figure 3; that is, in the subsampling procedure described
ing approaches (Papamarkos and Gatos, 1994). The histogram based multithresholding techniques are used for reduction of the image gray-scale values to a pre-defined number. However, they cannot estimate the optimal number of thresholds, and consequently, the final ONPGV of the image. Only a few techniques have been reported in the literature for the estimation of the ONPGV. The hill-clustering technique (Papamarkos and Gatos, 1994) is an iterative process that can be used for the determination of the histogram hills if their number is less or equal to a heuristic value. Unfortunately, since the process terminates when the heuristic value is reached, it does not converge to appropriate ONPGV values. The problem of estimation of the ONPGV can be solved as a clustering problem. A clustering validation test or a self-convergence classification technique can be used. To solve the problem of estimation of the ONPGV, we have developed and used the following three techniques:
Figure 3. Structure of the Kohonen SOFM neural network.
above, every sampling point corresponds to a vector of distance (3 ⫹ N r ⫹ N g ⫹ N b ) having the pixel values of the images (the inputs to the first three neurons are the components of the image color values). The value of J op is equal to the optimal values of the image colors initially estimated. The neural network is trained according to the procedure described in the previous section, and after training, the output neurons provide the centers of the feature classes. The optimal color values correspond to the centers of the features classes obtained by the neural network. Specifically, the values of the three color components are equal to the first three elements of the vectors: c ⫽ wT q共j兲 ,
j ⫽ 1, . . . , Jop.
(3)
Next, the original image is rescanned and its colors are substituted by the nearest colors obtained. Thus, the final image is formed with only J op color values. F. Final Color Conversion. As an optional postprocessing stage, we can convert the RGB colors obtained with spatial features to the RGB colors derived when only the RGB components are used. Let I 1 and I 2 be the images obtained by using spatial and nonspatial features, respectively. The color conversion can be easily implemented by checking the colors of the pixels in I 1 and I 2 that have the same coordinates. Specifically, let 1 Cm ⫽ (r m , g m , b m ), m ⫽ 1, . . . J: the set of RGB colors in I 1 . 2 Cm ⫽ (r m , g m , b m ), m ⫽ 1, . . . J: the set of RGB colors in I 2 . 2 Sm , m ⫽ 1, . . . J: the set of pixels in I 2 that have the same color 2 Cm . 1 S m , m ⫽ 1, . . . J: the set of pixels in I 1 that have the same 2 coordinates with the pixels of the set S m in I 2 . 1 p nm : the percentage of pixels in I 1 that belong to set S m and have 1 color C n .
Starting from the pixels having the maximum percentage, convert 2 color C 1n to the corresponding color C m . This optional stage provides an aesthetically better image, especially when we have a small number of final colors (small value of J). III. ESTIMATION OF THE ONPGV IN GRAY-SCALE IMAGES The estimation of the ONPGV in a gray-scale image is very useful in many applications. This problem is important in multithreshold-
1. A piecewise histogram approximation. 2. A histogram-smoothing algorithm. 3. Approximation of the histogram by a Kohonen SOFM. Detailed description and comparative results for these techniques are given in the next. A. The Piecewise Histogram Approximation. This technique is based on the curve-fitting algorithm of Duda and Hart (1973), which can be considered a linear piecewise histogram approximation (PWHA) procedure. Specifically, the histogram curve is approximated by a set of straight-line segments. Fitting and convergence criteria are applied to control the entire procedure. According to the PWHA algorithm, the shape of a histogram can be approximated through a set of straight-line segments that are determined by means of a simple iterative process. This technique is relatively immune to small histogram bin variation (due to noise) by a suitable choice of the fitting parameters. At the end of the fitting process, the principal peaks of the histogram are obtained, and their number specifies the ONPGV of the image. If h( j), with j ⫽ j 0 . . . j 1 , j 0 ⫽ 0, and j 1 ⫽ 255 is the histogram function, then h( j) can be approximated as follows: Initially h( j) is approximated by the straight-line ⑀1, which passes through points [ j 0 , h( j 0 )] and [ j 1 , h( j 1 )]. Then, the histogram point [ j 2 , h( j 2 )], with j 0 ⬍ j 2 ⬍ j 1 having the maximum distance from ⑀, is obtained and the histogram curve is now approximated by lines ⑀2 and ⑀3, defined by the points [ j 0 , h( j 0 )] ⫺ [ j, h( j)] and [ j 2 , h( j 2 )] ⫺ [ j 1 , h( j 1 )], respectively. This fitting procedure is repeated until some convergence conditions are satisfied. At the end of the PWHA procedure, the histogram scheme is approximated by a set of line segments. The procedure convergence only to 6 peaks means that, in this case, the image principal colors are equal to 6. The convergence conditions for the PWHA algorithm are as follows: 1. A line is not divided if the maximum distance is smaller than a predefined threshold d 0 . 2. A line segment [k 1 , h(k 1 )] ⫺ [k 2 , h(k 2 )] is not split more if k 3 ⫺ k 1 ⬍ d 1 and 兩h(k 3 ) ⫺ h(k 1 )兩 ⬍ d 2 or k 2 ⫺ k 3 ⬍ d 1 and 兩h(k 2 ) ⫺ h(k 3 )兩 ⬍ d 2 , where [k 3 , h(k 3 )] is the point with the maximum distance. The threshold d 2 is defined as a percentage of the maximum value of the histogram. In order to have an acceptable limited number of histogram peaks, a histogram-smoothing procedure can
Vol. 12, 117–127 (2002)
121
Figure 4. (a) Image histogram: determination of the optimal number of the principal gray-scale values using the methods of (b) PWSHA, (c) HSA, and (d) Kohonen SOFM neural network.
be applied. According to this technique, every value of the histogram is substituted by the mean value in a neighborhood: h共k兲 ⫽ average兵h共k ⫺ 0.5N ⫹ 0.5兲, . . . , h共k兲, . . . , h共k ⫹ 0.5N ⫹ 0.5兲其,
(4)
where N usually equals 5. We call this piecewise smoothing-histogram approximation (PWSHA) and, as the experimental results show, this technique probably provides the best results. Figure 4(b) provides an example of histogram approximation by the PWSHA. In this example, the ONPGV obtained equals 4. B. The Histogram-Smoothing Algorithm. The histogramsmoothing algorithm (HSA) is a simple, fast, reliable procedure. It starts by defining the number of equal-spaced bins in which the histogram will be mapped; that is, if B is the number of bins then k ⫽ 1,2, . . . B. The bin k is located at position Tk ⫽
冋
册
256 k . B⫹1
h n共k兲 ⫽
冦
共Tk⫹Tk⫹1兲/2
h共j兲,
if k ⫽ 1
j⫽0
共T k ⫹T k⫹1 兲/2
h共j兲,
if
k 僆 关2,3, . . . ,B ⫺ 1兴
h共j兲,
if
k ⫽ B.
(6)
j⫽共T k ⫹T k⫺1 兲/2 255
Stage 1. Define the total number of output neurons. Stage 2. Use subsampling via the Hilbert’s curve and train the neural network with the gray-scale values of the sampling points. Stage 3. Classify all image pixels with the SOFM neural network. Stage 4. Construct the approximated histogram. Stage 5. Obtain the peaks of the approximated histogram. The total number of peaks is equal to the optimal number of the image gray-scale values.
j⫽共T k ⫹T k⫺1 兲/2
The new histogram is a smoothed version of the initial one, with significantly fewer peaks. A bin k is defined as a peak if h n (k) is
122
C. Histogram Approximation by a Kohonen SOFM. The Kohonen SOFM can be used to approximate the histogram of an image. Specifically, if an SOFM like the one shown in Figure 3, but with one input neuron, is fed by the image gray-scale values, then, after training, the output neurons correspond to the centers of the gray-scale classes. Usually, the total number of the output neurons equals 25. Thus, using the trained neural network, we classify each gray-scale value into one of the obtained classes. The total number of the members of each class gives the amplitudes (height) of the approximated histogram. After this, we can obtain easily the number of peaks in the approximated histogram. This number is equal to the ONPGV. The main stages of the algorithm are as follows:
(5)
The smoothed histogram is constructed using the following formula:
冘 冘 冘
greater than h n (k ⫺ 1) and h n (k ⫹ 1). The number of peaks is taken as the ONPGV of the image. Notice that a suitable value for B is 25. Figure 4(c) demonstrates the application of HSA to the histogram of Figure 4(a). In this example, B ⫽ 25 and, as can be observed, the HSA leads to only six principal gray-scale values.
Vol. 12, 117–127 (2002)
Figure 4(d) demonstrates the results obtained by using this algorithm. In this example, 25 output neurons are used, and the ONPGV is obtained equal to 5.
Figure 5.
Comparison of the ONPGV methods.
D. Comparison of the ONPGV Estimation Techniques. The three ONPGV estimation techniques analyzed above give similar results in most cases. However, we must mention the following:
1. The histogram-smoothing algorithm is faster. Also, this technique requires only one arbitrary value (i.e., the number B).
Figure 6. (a) Original image; (b) document with two colors and without using spatial features. Color reduction: (c) median-cut, (d) Dekker, and (e) Wu methods. (f) Image obtained using the proposed method with spatial features. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley.com.]
Vol. 12, 117–127 (2002)
123
Figures 7 & 8.
124
Vol. 12, 117–127 (2002)
2. The PWSHA technique is fast and leads to good histogram fitting. However, the several arbitrary values significantly influence the efficiency of the histogram fitting process. 3. The Kohonen SOFM-based approach approximates the histogram satisfactorily. However, it is a time-consuming algorithm. In order to test the ONPGV estimation techniques, we apply them using the default parameters in a number of images. Figure 5 depicts graphically the results obtained for 100 test images. In order to decide which method gives better results, let (for N ⫽ 100) G i,j, i ⫽ 1, . . . , N
and j ⫽ 1, . . . , 4,
(7)
the ONPGV obtained by HSA, PWHA, PWSHA, and Kohonen SOFM, respectively, M i ⫽ average共Gi,1 , Gi,2 , Gi,3 , Gi,4 兲,
Ej ⫽
1 N
冑冘
i ⫽ 1, . . . , N
j ⫽ 1, . . . , 4
A. Experiment 1. This example demonstrates the application of the proposed method to color reduction of the color document shown in Figure 6(a). The size of the original image is 1,780 ⫻ 485 pixels with 300 dpi resolution. A shadow can be observed on the left side of this image. With the following specifications: 1. RGB color space, 2. no spatial features, 3. the PWSHA technique used with a smoothing value equal to five, and 4. the estimation of optimal number of image final colors obtained using the Hue color component,
(8)
N
共G i,j ⫺ M i兲 2,
attempt to present characteristic cases that make optically obvious that the results obtained by the proposed method are useful and superior compared to other, well-known color quantization schemes.
(9)
i⫽1
The E j obtained from Eq. (9) corresponds to the sum of Euclidean distances between G i, j and M i values. For the specific test, the following results are obtained for E j : E 1 ⫽ 0.64, E 2 ⫽ 0.995, E 3 ⫽ 0.615, and E4 ⫽ 0.8 Therefore, it can be concluded that the PWSHA can be satisfactorily used for ONPGV estimation. IV. EXPERIMENTAL RESULTS The proposed method has been implemented in a visual environment. The SOFM neural networks are implemented and tested with the developer version 3.02 of the neural network package NeuralSolution (NeuroDimension, Inc.). Due to space limitations, only two characteristic experimental results are presented. However, the program implementing the proposed color reduction technique can be downloaded from the site: http://ipml.ee.duth.gr/⬃papamark/Index. html. It should be noticed that the proposed method, due to its flexibility to exploit additional spatial characteristics, cannot be considered a classical color quantization technique. An important goal of a color quantization technique is to minimize the perceived difference between the original and its quantized representation. The perceived difference can be considered also as perceived image quality or perceived image similarity. In general, it is very difficult to define and calculate such measures objectively. In fact, there is not a good-enough objective criterion available, and we can state that the quality of the images is associated with the application. For these reasons, in the examples provided in the next section, we
the proposed technique results in the image shown in Figure 6(b) with only the (119, 88, 50) and (251, 229, 191) RGB colors. It should be noticed that the application of the PWSHA technique leads to 3, 3, 3 and 2 ONPGV for the R, G, B, and Hue components, respectively. Unfortunately, the shadow of the image results in a large black area on the left side of the final image. This effect appears if we use any of the classical color reduction techniques. For example, Figures 6(c) and (d) depict the results obtained through the median-cut by Dekker and Kohonen (1994) and Wu (1992). Finally, the proposed method is applied again, with the same specifications as above, and the additional use as spatial features for each PCC those obtained from the following masks:
冉
⫺3 ⫺3 ⫺3 0 ⫺3 5
⫺3 5 5
冊
,
冢
⫺1 ⫺1 ⫺1 ⫺1 ⫺1
⫺1 ⫺1 ⫺2 ⫺2 ⫺2 35 ⫺2 ⫺2 ⫺1 ⫺1
⫺1 ⫺2 ⫺2 ⫺2 ⫺1
⫺1 ⫺1 ⫺1 ⫺1 ⫺1
冣
.
The first mask is a Kirsch’s edge detection mask (Sonka et al., 1999) and the other can be considered a sharpening one. The final image obtained, shown in Figure 6(f), has only the (119, 89, 51) and (251, 229, 191) RGB colors, and it is important to observe that the image shadow is eliminated without significant degradation of text characters. Also, notice that the results obtained with the proposed technique are not unique. Different color reduction results can be obtained if the system is fed with different spatial features. B. Experiment 2. This experiment demonstrates the application of the proposed method to the natural image of Figure 7(a), whose size is 945 ⫻ 630 pixels with 150 dpi and 182,028 unique colors. Using the PWSHA technique for the Hue PCC, the optimal number of image colors obtained is equal to 30. More specifically, for d 0 ⫽ 0.002 and a smoothing value equal to 1, the PWSHA technique results in 33, 25, and 21 ONPGV, respectively, for the R, G, and B
Figure 7. (a) Original image; (b) image with 30 colors without using spatial features; (c) image with 30 colors using spatial features; (d) result of median-cut technique for 30 colors; (e) result of Dekker’s technique for 30 colors. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley.com.] Figure 8. (a) Image with 10 colors without using spatial features; (b) image with 10 colors using spatial features. [Color figure can be viewed in the online issue, which is available at www.interscience.wiley.com.]
Vol. 12, 117–127 (2002)
125
Table I. Comparative color quantization results for Experiment 2. Proposed (Without Spatial Features)
Proposed (With Spatial Features)
Papamarkos et al. (2002)
Dekker’s
Median-cut
30 colors MAD AQE NED ADC SNR PSNR
90 9.73 0.017 14.16 26.25 31.27
127 16.00 0.027 24.28 21.44 26.45
84 9.590 0.015 14.612 26.469 31.485
169 11.04 0.018 17.34 24.65 29.67
88 18.26 0.025 20.55 21.93 26.94
10 colors MAD AQE NED ADC SNR PSNR
127 15.81 0.025 23.27 22.07 27.08
145 22.46 0.0368 33.02 18.81 23.83
117 15.29 0.0247 22.80 22.27 27.29
170 17.41 0.028 26.16 20.98 25.99
93 31.47 0.044 30.97 17.25 22.27
color components. Initially, the algorithm runs without applying any spatial feature and results to the image shown in Figure 7(b). Next, we run the color reduction procedure using spatial features in each PCC extracted from the following mask:
冉
0 ⫺1 0
⫺1 0 5 ⫺1 ⫺1 0
冊
The image obtained is shown in Figure 7(c). We can optically observe that the application of the above spatial features lead to a sharper image. For comparison reasons, we apply the median-cut and the technique of Dekker for reduction of image colors to 30. The results obtained are shown in Figures 7(d) and (e), respectively. We can easily observe that the colors of the images obtained are not smoothly distributed [Figure 7(d) and (e)]. Therefore, we can claim that the results obtained by the proposed method outperform the results given by the median-cut and Dekker’s methods. This effect becomes more obvious when we try to reduce the number of image colors to less than 10. Figure 8 depicts the quantization results obtained for 10 colors. For statistical comparison, here, we use the following six criteria (Papamarkos et al., 2002): ● ● ● ● ● ●
The The The The The The
maximum absolute difference (MAD). average quantization error (AQE). normalized Euclidean distance (NED). average distortion per color (ADC). signal-to-noise ratio (SNR). peak signal-to-noise ratio (PSNR).
Table I, summarizes the comparative results obtained for this experiment. As we can observe, the proposed technique (without using spatial features) gives superior results to those in the methods of Dekker and the median-cut. Also, in comparison to the adaptive color reduction technique, the proposed approach results in similar statistical indices. However, it offers additional capabilities, such as faster operation and use of separable spatial features for each PCC. V. CONCLUSIONS In this article, we propose a new color reduction technique that is applicable to any color image. The proposed technique uses the
126
Vol. 12, 117–127 (2002)
image principal color components, which consist of the image color components and additional image components extracted with the use of proper spatial features. In each PCC, a technique is applied that provides us the optimal number of image colors for the specific PCC. This number specifies the number of output neurons of a Kohonen SOFM, which is then trained by fractal subsampling image values of the PCC. After training, the output neurons of the SOFM specify the centers of the color classes and the principal values for every PCC. In order to calculate the optimal number of principal colors for the entire image, the same procedure is applied directly into a predefined PCC (usually in the Hue component). Finally, a Kohonen SOFM is used in the final stage combining the color reduction results obtained from the PCC images to estimate the principal colors of the entire image. The proposed method requires the determination of the optimal number of principal values for each PCC. To solve this problem, three techniques were developed and tested. The PWSHA has been selected as the most effective technique. Notice that the spatial features used to describe image local characteristics. Therefore, the color of each pixel is related to the colors and the texture of the neighboring pixels. Therefore, the final image has not only the proper colors but also its structure approximates the local characteristics used. This is important in many applications, especially in segmentation and recognition techniques. In comparison to previous techniques based on the Kohonen SOFM, the proposed technique offers a method for estimation of the optimal number of image principal colors without any requirement for an adaptation procedure. Also, it is faster, offers the flexibility of different feature sets in each PCC, and is suitable for reduction of the image colors to a small number. REFERENCES I. Ashdown, “Octree color quantization,” Radiosity: A programmer’s perspective, Wiley, New York, 1994. R. Balasubramanian and J.P. Allebach, A new approach to palette selection for color images, J Imaging Technol 17 (1990), 284 –290. R. Balasubramanian, J.P. Allebach, and C. Bouman, Color-image quantization with use of a fast binary splitting technique, J Opt Soc Amer 11 (1994), 2777–2786. M.M. Chang, M.I. Sezan, and A.M. Tekalp, Adaptive Bayesian segmentation of color images, J Electron Imaging 3 (1994), 404 – 414.
A.H. Dekker, Kohonen neural networks for optimal color quantization, Network: Computation in Neural Systems 5 (1994), 351–367.
J.C. Russ, The image processing handbook, 2nd ed., CRC Press, Boca Raton, FL, 1994.
R.O. Duda and P.E. Hart, Pattern recognition and scene analysis, Wiley, New York, 1973.
H. Sagan, Space-filling curves, Springer-Verlag, New York, 1994.
M. Gervautz and W. Purgathofer, A simple method for color quantization: Octree Quantization, A.S. Glassner (Editor), Graphics Gems, Academic Press, San Diego, 1990, pp. 287–293. S. Haykin, Neural networks: A comprehensive foundation, MacMillan College Publishing, New York, 1994. P. Heckbert, Color image quantization for frame buffer display, Comput Graphics 16 (1982), 297–307. T. Kohonen, Self-organizing maps, Springer-Verlag, New York, 1997. N. Papamarkos, Color reduction using local features and a SOFM neural network, Int J Imag Syst Tech 10 (1999), 404 – 409. N. Papamarkos and A. Atsalakis, Gray-level reduction using local spatial features, Comput Vis Image Und 78 (2000), 336 –350. N. Papamarkos, A. Atsalakis, and C. Strouthopoulos, Adaptive color reduction, IEEE Syst Man and Cybernetic–Part B 32 (2002), 44 –56. N. Papamarkos and B. Gatos, A new approach for multithreshold selection, Comput Vision Graphics-Graphic Models and Image Process 56 (1994), 357–370. N. Papamarkos, C. Strouthopoulos, and I. Andreadis, Multithresholding of color and color images through a neural network technique, Image Vision Comput 18 (2000), 213–222.
P. Scheunders, A comparison of clustering algorithms applied to color image quantization, Pattern Recogn Lett 18 (1997), 1379 –1384. L. Shafarenko, M. Petrou, and J. Kittler, Histogram-based segmentation in a perceptually uniform color space. IEEE Trans Image Process 7 (1998), 1354 –1358. S.A. Shafer and T. Kanade, “Color vision,” S.C. Shapiro and D. Eckroth (Editors), Encyclopedia of artificial intelligence, Wiley, New York, 1987, pp. 124 –131. M. Sonka, V. Hlavac, and R. Boyle, Image processing, analysis, and machine vision, 2nd ed., Brooks/Cole, Pacific Grove, CA, 1999. L. Velho, J. Gomes, and M.V.R. Sobreiro, “Color image quantization by pair wise clustering,” L.H. de Figueiredo and M.L. Netto (Editors), X Brazilian Symposium of Computer Graphics and Image Processing, Campos do Jordao, SP, Conference Proceedings, 1997, pp. 203–210. O. Verevka, The local K-means algorithm for color image quantization, MSc. thesis, University of Alberta, 1995. S.J. Wan, P. Prusinkiewicz, and S.K.M. Wong, Variance based color image quantization for frame buffer display, Color Res Applic 15 (1990), 52–58. X. Wu, Color quantization by dynamic programming and principal analysis, ACM Trans Graphics 11 (1992), 348 –372.
Vol. 12, 117–127 (2002)
127