A Genetic Lloyd-Max Image Quantization Algorithm

A Genetic Lloyd-Max Image Quantization Algorithm P. Scheunders Vision Lab, Dept. of Physics, RUCA University of Antwerp, Groenenborgerlaan 171, 2020 A...
Author: Adele Holland
51 downloads 0 Views 66KB Size
A Genetic Lloyd-Max Image Quantization Algorithm P. Scheunders Vision Lab, Dept. of Physics, RUCA University of Antwerp, Groenenborgerlaan 171, 2020 Antwerpen, Belgium

Abstract

This paper is devoted to the study of optimal image quantization and its sensitivity to initial conditions. The optimal mean squared algorithm is elaborated, for gray-level as well as for color images. A genetic quantization algorithm is developed, which is a hybrid technique combining optimal quantization with a genetic algorithm. It is shown that the latter technique is almost insensitive to initial conditions and performs better than the former. In the case of color images, the difference between both techniques clearly affects the visual quality.

KEY WORDS : Lloyd-Max Quantizer, Genetic Algorithm, C-Means Clustering Algorithm, Color Image Segmentation.

Email : [email protected]

1

1. Introduction

Image quantization can be regarded as global image segmentation. Image segmentation techniques can informally be subdivided into three main classes :

1. Statistical classification techniques such as Bayesian approaches and clustering algorithms (Fukunaga, 1979). 2. Edge detection techniques (Marr and Hildreth, 1980). 3. Region growing techniques (e.g. Fu and Mui, 1981).

Global image segmentation belongs to the first category and is widely used as a simple segmentation technique, especially for binarization of images (Otsu, 1978; Weszka, 1978; Ridler and Calvard, 1978; Johanssen and Bille, 1982). It is very useful as a first stage in recognition and characterization systems or as an image compression technique. Also, the smaller amount of gray-levels allows for a crude representation of the image and hence makes it easy to display or print. It can also be used as a preprocessing step for segmentation with local constraints, e.g. as prior probability estimation in Bayesian approaches (Pappas, 1992).

Image gray-level quantization deals with the digitization of the amplitude of an image function f(x,y), and is done by sampling the gray-level probability distribution of the image. If minimal degradation of the original image is a necessary condition, an objective function e.g. the pixel-bypixel mean squared error (MSE) has to be minimized. A well-known algorithm to do so is the optimal mean squared or Lloyd-Max quantizer (LMQ) (Jain, 1989). The discrete version of LMQ 2

reduces the number of gray-levels of an already quantized image by subsampling its gray-level histogram. Comparison of this algorithm with data clustering algorithms, leads to the observation that LMQ is a one-dimensional version of the well-known c-means clustering algorithm (CMA) (Tou and Gonzalez, 1974). CMA is an iterative procedure which subdivides dataspace into C clusters. Initially C cluster centers are generated and each datapoint is assigned to the closest cluster center, after which each cluster center is updated as the weighted average of all datapoints which were assigned to it. This is repeated until convergence. Using LMQ, the datapoints are given by the image gray-level histogram and the cluster centers are the quantized gray-levels.

When using LMQ, one notices that results are higly dependent on initial conditions. This problem is very well known, but neglected by many researchers. We feel that this problem should be investigated in more detail, since the same phenomena occur in all iterative clustering and segmentation algorithms, and in general far from optimal results can be obtained. Therefore we have devoted this study to the investigation of the problem of local optima in clustering algorithms. Gray-level image quantization is chosen as a test case study because it is a fairly simple one-dimensional clustering problem.

In addition we also address color image quantization which is of greater practical importance since: i) color images provide additional information in the image compared to monochrome images. ii) the human vision system is much more sensitive to small differences in color than in intensity. iii) many low-cost color display and printing devices are restricted to a small number of colors that may be displayed or printed simultaneously.

3

On this problem, classical c-means clustering as well as fuzzy c-means clustering has been applied (Celenk, 1990; Shafer and Kanade, 1987; Lim and Lee, 1990). Color image quantization is a much more complex clustering problem because of the three-dimensional histogram involved. Therefore the problem of local optima is expected to become more important.

In this paper a quantizer, based on a genetic algorithm (GA), is defined which is more insensitive to initial conditions. Invented in the early 70’s (Holland, 1975) GA’s became more and more popular over the last years. A GA is inspired by biological evolution, and is widely believed to be an effective global optimization algorithm. A genetic algorithm consists of a population of genetic strings, which are evaluated using a fitness function. The fittest strings are then regenerated at the expense of the others. Furthermore genetic operations such as crossover and mutation are defined. The mutation operator changes individual elements of a string, the crossover operation interchanges parts between strings. The combination of these operations is then repeated during several generations. The intrinsic parallelism of a genetic algorithm, i.e. the ability of manipulating in parallel large numbers of strings, and the crossover operation whereby good portions of different strings are combined both help to make the technique efficient for optimization (Davis, 1991). The usefulness of GA’s in pattern recognition and image processing has been demonstrated (for references see Alander, 1994). In the field of image segmentation, genetic algorithms were already introduced (Bhana, 1991; Andrey,Tarroux, 1994; Cagnoni, 1994). Our approach is a hybrid structure between GA and optimal quantization and will henceforth be referred to as genetic Lloyd-Max quantization (GLMQ).

The outline of this paper is as follows: in the next section LMQ is elaborated. In section 3, GLMQ is introduced. In section 4 different experiments are carried out to demonstrate and 4

discuss the performance of the genetic quantizer.

2. Optimal quantization

First, we discuss the gray-level case. We will discuss the discrete quantizer, i.e. we will restrict ourselves to the problem of reducing the total available number of gray-levels of an image. As stated in the introduction, this is done by subsampling the gray-level histogram. Optimal quantization is obtained when the pixel-by-pixel mean squared error (MSE) is minimal. If the

σ

 / ∑L  ∑WNLWL 3 N N  UL

total number of gray-levels N is reduced to a limited number L, MSE is given by : where the function P(k) is the normalized gray-level histogram (ΣkP(k) = 1), ri are the quantized gray-levels of the subsampled histogram and ti are threshold values which define the sampling

W

L

UL

 U U  L 

L

∑WNLW L 3 N N ∑WNLW L 3 N

intervals. This function is minimized with respect to ti and ri, leading to the following conditions: A way to solve this coupled set of nonlinear equations is by first generating an initial set {r1, ... , rL}, then applying (2) and (3) alternatively until convergence is obtained. This iteration algorithm is well-known under the name of optimal mean squared or Lloyd-Max quantization algorithm (LMQ).

5

A problem with this type of iteration scheme is that it depends greatly on the initial conditions, i.e. the initial choice of the set {ri}. Multiple solutions satisfy (2) and (3) and depending on the initial conditions, the algorithm converges to different local optima.

We extend LMQ to color image quantization. Here the goal is to reduce the number of colors from (256)3 for a 24 bit RGB color image to an appropriate amount for displaying or printing (typically between 4 and 256). This reduction can be performed by clustering in the 3dimensional color histogram of the image. The MSE between original and quantized image is now given by the sum of squares of differences between each colorpixel and its closest quantized color, both 3d-vectors in color space. Conditions (2) and (3) become: i) classification of the colorpixels. Hereby the Euclidian distance in color space between a colorpixel and every cluster center (i.e. quantized color) is calculated. The pixel is assigned to the closest cluster center. ii) updating of the quantized colors. Each quantized color is the center of mass of all colorpixels which are assigned to the cluster.

Starting from an initial set of cluster centers, both conditions can be alternatively updated until convergence. Again, the algorithm ends up in local optima, depending on the applied initial conditions.

6

3. The genetic Lloyd-Max quantizer

Since the quantization algorithm described in section 2 is dependent on initial conditions, an independent approach is desireable. Therefore, we have constructed an algorithm which combines optimal quantization with a genetic algorithm approach, and which will be called a genetic Lloyd-Max quantizer (GLMQ). We will discuss the gray-level case. Extension to color images is straightforward. The first step consists of making an initial population of P integervalued strings. Each string {r1 , ... , r L} is created by generating L distinct integer random numbers between 1 and N, and by sorting them. Each string is now used as an initial set of quantized gray-levels. On all of the strings of the population LMQ is applied separately. After convergence a population of locally optimal solutions is obtained. Then genetic operations are applied.

Regeneration: On each string of the population MSE is calculated using (1). The inverse of MSE is used as fitness function. All strings are pairwise compared. The string with lowest MSE is copied into the other.

Crossover: On each string { ri } one-point crossover is applied with probability Pc (Pc=0.5). Out of the total population a partner string { r’ i } is randomly chosen to form a pair. For that pair an integer random number j between 1 and L is generated. Under the restriction that rj < r’j+1 and r’j < rj+1 both of the strings are cut in two portions at position j and the portions {rj+1, ... , rL} are interchanged. The restriction is necessary to preserve ordered strings of L quantized levels. If 7

the restriction is not met, no crossover is applied.

Mutation: Mutation is performed on each string L times with probability Pm (Pm=0.05). An integer random number j between 1 and L is generated. The value rj is increased or decreased by 1, only if rj±1 belongs to ]rj-1,rj+1[. Again, the restriction is necessary to preserve ordered strings of L quantized levels.

The total of four operations (LMQ, regeneration, crossover and mutation) is called a generation. After a generation, the string with lowest MSE out of the total population is stored. Then the next generation is performed. If after the next generation a string with lower MSE is created, it replaces the stored one. The string which is stored after G generations is chosen as the optimal result.

It is clear that the described algorithm is more computer power demanding than the previously described quantization algorithm. LMQ is applied PxG times. A faster alternative approach applies LMQ during each generation only on the string with lowest MSE, hereby reducing the complexity to O(G). The complexity of the genetic operators remains of O(PxG), but they are extremely suitable for parallel processing. Moreover the number of iterations, required for LMQ to converge, decreases gradually with the number of generations, because strings become fitter. All this limits the execution time of GLMQ. On sequential computers, a run of GLMQ on P strings during G generations is about 10 times faster than PxG independent runs of LMQ (see section 4).

8

4. Results and discussion

In several experiments the performance of GLMQ is compared to that of LMQ. All experiments use 8 bit gray-level images (N=256) of 512x512 pixels. On these images, N is reduced to L (L=8,16,32 and 64) gray-levels. The test images used are ’lena’, ’peppers’ and ’airplane’, which are three commonly used images, available from several image libraries (e.g. WWW at site http://vision.ce.pusan.ac.kr). The middle 128x128 part of the colored version of ‘lena’ is also used. All calculations are performed on a HP9000/730 Unix workstation.

Several strategies are possible to obtain an initial set {r 1 , ... , r L} for starting the optimal quantization algorithm. An obvious choice is a random initial set. Hereby L different integer values ri between 1 and N are generated and then sorted and named r

1

to r

L

. Applying the

quantizer on different initial sets independently allows to study in a statistical way the influence of the initial conditions on the behaviour of LMQ. In a first experiment the influence of random initial conditions on LMQ and GLMQ is studied. A statistically representative number of sets {ri}is constructed and LMQ is applied on each set independently. The distribution of obtained MSE’s is a statistical representation of the distribution of local optima obtained by the quantizer. In figure 1a such distribution is shown for testimage 'lena' reduced to 8 gray-levels, using LMQ. Here 1000 independent runs were performed. The x-axis is the axis of the MSE's, while the yaxis displays the number of times that an MSE is obtained. The same 1000 randomly generated sets were used as an initial population for GLMQ. In figure 1b, 1c and 1d, the distributions of the resulting MSE's are shown after 1, 3 and 5 generations respectively. For comparison other 9

optimization techniques were applied. A hill-climbing type of approach is constructed as follows. A randomly chosen initial set is generated. One of the values rj is chosen at random and is increased or decreased by 1, only if r j±1 belongs to ]rj-1,rj+1[ (cfr. the mutation operator of GLMQ). The mutation is allowed only if the MSE decreases. Then LMQ is applied. The procedure is repeated until convergence. In figure 1e the resulting distribution of obtained MSE’s is shown, using the same 1000 initial sets as before. In a modification of the hill-climbing approach escaping from local optima becomes possible by defining an escape probability Pe. With probability Pe (Pe = 0.1) the mutation is then allowed for increasing MSE. The resulting distribution is shown in figure 1f. Note that in all cases, the use of 10.000 sets reproduced the same distributions.

As can be seen from figure 1a, LMQ is very dependent on the employed initial conditions. A few high peaks show local optima which are very easy to get caught in. MSE's between best and poorest result differed by more than 20%. Figures 1b, 1c and 1d show a distribution which, with increasing number of generations, converges to a narrow peak meaning that the sensitivity of GLMQ to initial conditions is very low. The optimal result obtained was an MSE of 61.13. In figure 1a it was obtained only once. In figure 1c, the optimum was obtained by 3% of the population, in figure 1d by 8%. Figure 1e demonstrates that a hill-climbing type of approach is not sufficient to remove the dependence on initial conditions. Two optima remain visible. By introducing the escape probability, results improve but still two optima, although close to eachother, remain visible.

In the second experiment LMQ and GLMQ were applied on the three test images, for a reduction to L=16, 32 and 64 gray-levels. LMQ was applied 100 times independently, using different initial 10

sets. In table 1, the best MSE out of the 100 runs is shown. Using GLMQ, the alternative approach was used, which applies LMQ after each generation only on the string with lowest MSE. The same 100 initial sets as with LMQ were used to initiate the population. In a first stage 10 generations were performed. In this way, the algorithm consumed about the same cpu-time as the 100 runs of LMQ. In a second stage 500 generations were performed. In this way, a nearby global optimum was found, i.e. repeating the experiments resulted in a reproduction of the result within 1%. The results are shown in table 1. Table 2 shows the consumed cpu-time for the different experiments.

As can be concluded from the tables, applying GLMQ is favorable to applying LMQ different times independently. Results improved during genetic adaption using execution times, comparable to the time needed using LMQ. If genetic adaption proceeds even further, a nearby global optimum is obtained, which is considerably lower than the result obtained by LMQ.

In the last experiment, color images were quantized. Because here clustering in a complex three dimensional space is involved, differences between local optima are expected to become more important. Because the human eye is sensitive to small variations in color, it is likely that these differences affect the image quality. The experiment was performed on the middle 128x128 part of the colored version of ‘lena’. In figure 2, the image is shown after quantization to 32 colors. In figure 2a, the best out of 100 independent runs of LMQ is displayed (MSE=228), in figure 2b, the result of GLMQ is shown for the same 100 sets, after 50 generations (MSE=174). For comparison, in figure 2c and 2d, the resulting image after uniform quantization (which is a commonly used initial condition) is displayed. Here, the red, green and blue images were separately uniform quantized (i.e. the histograms were split into equal parts) into 4, 4 and 2 11

levels respectively. Figure 2c shows the result before (MSE= 1803), and figure 2d after applying LMQ on the uniform quantized image (MSE = 278). The quality of figure 2b is clearly superior to the others. Especially in slowly varying regions, transitions between colors become smoother.

5. Conclusions

In this paper an image quantizer is elaborated which is a hybrid technique combining the optimal mean squared quantizer and a genetic algorithm. For gray-level images it is demonstrated that the optimal quantizer suffers from local optimality. The genetic approach is demonstrated to be less sensitive to local optimality and to perform better using similar execution times. For color images the difference between the optimal and the genetic optimal quantizer is demonstrated to be visibly important. The concept of genetic optimal quantization can easily be extended to a multidimensional dataclustering algorithm (genetic c-means clustering). Extension to local image segmentation procedures is under investigation.

References

Alander J.T. (1994). An indexed bibliography of genetic algorithms: years 1957-1993. Technical Report Series 94-1, University of Vaasa, Dept. of Information Technology and Production Economics, Vaasa, Finland.

Andrey P., P. Tarroux (1994). Unsupervised image segmentation using a distributed genetic 12

algorithm. Pattern Recognition Vol 27, No. 5, pp. 659-673.

Bhanu, B, S. Lee, J. Ming (1991). Self-optimizing image segmentation system using a genetic algorithm. Proc. Fourth Internat. Conf. on Genetic Algorithms pp. 362-369.

Cagnoni S., A.B. Dobrzeniecki, J.C. Yanch, R. Poli (1994). Interactive segmentation of multidimensional medical data with contour-based application of genetic algorithms. Proc. First IEEE Internat. Conf. on Image Processing, Austin, Texas Vol.III, pp. 498-502.

Celenk M. (1990). A color clustering technique for image segmentation, Computer Vision, Graphics and Image Processing. Vol. 52, pp. 145-170.

Davis L. (1991). Handbook of genetic algorithms. Van Nostrand Reinhold, N.Y.

Fu K.S. and J.K. Mui (1981). A survey on image segmentation. Pattern Recognition 13, 3-16.

Fukunaga K. (1979). Introduction to Statistical Pattern Recognition. N.Y. Academic Press.

Holland John H. (1975). Adaption in Natural and Artificial Systems. University of Michigan Press.

Jain A.K. (1989). Fundamentals of digital image processing. Prentice Hall. chapter 4.

Johanssen G. and J. Bille (1982). A threshold selection method using information measures. 13

Proc. of the 6-th Internat. Conf. on Pattern Recognition, Munich, pp. 140-142.

Marr D. and E. Hildreth (1980). Theory of edge detection. Proc. R. Soc London B207, 198-217.

Otsu N. (1978). Discriminant and least squares threshold selection. Proc. of the 4-th IJCPR pp. 592-595.

Pappas Thrasyvoulos N. (1992). An adaptive clustering algorithm for image segmentation. IEEE Transactions on Signal Processing Vol. 40, no. 4.

Ridler T.W. and S. Calvard (1978). Picture thresholding using an iterative selection method. IEEE Transactions on Systems, Man and Cybernetics Vol 8, no. 8, 630-632.

Shafer S.A. and T. Kanade (1987). Color vision, In Encyclopedia of artificial intelligence. S.C. Shapiro, D. Eckroth EDS., Wiley, N.Y., pp. 124-131.

Tou J.T. and R.C. Gonzalez (1974). Pattern Recognition Principles. A. Wesly.

Weszka Joan S. (1978). A survey of threshold selection techniques. Computer Graphics and Image Processing 7, 259-265.

Young Won Lim and Sang Uk Lee (1990). On the color image segmentation algorithm based on the thresholding and the fuzzy c-means techniques, Pattern Recognition, Vol. 23, nr. 9.

14

Figure Captions

Fig. 1: Distribution of obtained MSE’s using random initial conditions for a reduction to L=8 gray-levels on test image ’lena’; 1a: after 1000 independent runs of LMQ; 1b: using GLMQ on a population of 1000 strings after 1 generation; 1c: after 3 generations; 1d: after 5 generations; 1e: after 1000 independent runs of a hill-climbing type of approach; 1f: the same as 1e, but with an escape probability of Pe = 0.1 .

Fig. 2: Color image quantized to 32 colors; 2a: using LMQ, the best out of 100 independent runs is shown (MSE=228); 2b: using GLMQ with a population of 100 strings after 50 generations (MSE=174); 2c: using uniform quantization (r=4, g=4, b=2 levels) (MSE=1803); 2d: after applying LMQ on the uniform quantized image (MSE = 278).

15

Table 1: MSE’s for LMQ and GLMQ. MSE

lena

peppers airplane

L

LMQ

GLMQ

Best out of 100

P=100, G=10

P=100, G=500

16 32 64

17.00

16.74 4.57 1.33

16.45 4.32 1.14

16 32 64

17.73 4.98 1.49

17.34 4.80 1.33

17.25 4.47 1.17

16 32 64

12.04 3.57 1.14

11.70 3.25 0.96

11.57 3.05 0.88

4.80 1.43

Table 2: CPU-times for the experiments of table 1. cpu-time (seconds)

L

LMQ

GLMQ

Best out of 100

P=100, G=10

P=100, G=500

lena

16 32 64

1.08 0.84 0.80

0.60 0.69 0.91

27.8 32.3 41.5

peppers

16 32 64

0.90 0.76 0.75

0.60 0.71 0.97

27.2 33.6 41.7

airplane

16

0.86

0.60

26.8

16

32 64

0.69 0.83

0.70 0.87

17

31.9 42.7