CONTRAST ENHANCE~mNT AND EDGE DETECTION TECHNIQUE Ghalib H. Mizaal -assistant researcher- And Rehab H. Alwan -Scientific researcher- Remote Sensing Department, Space & Astronomy Research Center Scientific Research Council, Baghdad, P.O. Box 2441, IRAQ. Commission number 3 ABSTRACT: This paper proposes a technique for locally finding edges in gray level digital images, and enhance the edge and non-edge pixels. The technique starts by dividing the image into partitions based on the amount of spatial activity in a neighbourhood of a pixel, extracting the edges in the partition and enhance the edge and non edge pixels by stretching. This method is illustrated by application to a digital image consist of a rectangle on a lighter surround, both with constant gray level. This technique easily detects and extracts the edges depending on the edge location, the rate of change of brightness and the average brightness. Moreover it enhances the entire non edge pixels to obtain an accurate enhanced image. 547 INTRODUCTION: Image enhancement is one of the important operations in image processing, where it is used for multi purposes and in many situations. The objective of image enhancement is to improve picture quality, more specificaly, it is employed to remove noise, deblur edges and highlight specific features. The application of image enhancement techniques, in general improves human viewing ability and may increase the distance of success in picture processing [1]. Noise in an image generally has a higher spatial frequency spectrum than the normal image components because of its spatial decorrelatedness. Many methods have been proposed to remove noise and enhance the digital images such as Wiener filtering, simple low-pass spatial filtering, other approaches include the constrained least square filter, optimal recursive filters, and variations and extensions of these filters. All of the methods evaluated are devised to preserve edge sharpness while achieving some degree of noise cleaning, they are unweighted neighbour averaging (AVE),K-nearest neighbour averaging (KAVE), the edge and line weights method (EDLN), gradient inverse weighted smoothing (GRADIN), maximum homogeneity smoothing (MAXH),slope facet model smoothing (FACET), and median filtering (MEDIAN),each method has its own algorithm, and as a result all mentioned algorithms observed that are very good for preserving edges but they increase CPU run time [2]. Concerning the contrast enhancement, the transform processing such as the Fourier and Hadamard transforms which provide a spectral decomposition of an image into coefficients that tend to isolate certain features of an image [3]. The histogram specification method which can often be improved by amplitude rescaling of each pixel [4], and many other methods which all perform a computational requirement. The most significant features in any image are the edges: Many different edge detection shemes have been advanced and analysed, (see Refs (3,5) for surveys and Refs (6,7,8) for comparisons of some well known techinques). SHIOZAKI (6) extracted the edge using the entropy operator which calculates the entropy of brightness in a local region of an image [6], and yields low values in the regions where brightness is changing rapidly. The entropy operator as well as the Laplacian is apt to be affected by noise, so noise must be removed beforehand. The paper presents an approach used to enhance the contrast and detect the edges by partitioning the image to reduce the computation and to do local processing which is summarized as follows: 548 a. Defining the partition, which means dividing the picture into specific number of partitions. b. Extracting the edge picture. c. Enhancing the detected edge obtain an enhanced picture. edge from the defined partition and give an pixels and the rest pixels to 2. ALGORITHM The 1. proposed technique is described as follows Partitioning the image: In order to get a very accurate description of spatial activity which defined as a rate of change of intensity from one pixel to its neghboring pixels, meanwhile working with small number of pixels leads to computer time reduction: For these reasons, partioning of the image becomes necessary. Basically, the signal model contained two regions, regions with high spatial activity containing the edges, and regions with low spatial activity containing the non edges.The partitioning and the local processing on the image looks like filtering the image by many bandpass filters depending on the spatial frequency contents. Partition size is taken as 4x4, pixels. 2. Edges and non edges pixels discrimination: The whole image is divided into L subsets or partitions and each partition is represented by ki , where i l, ••• ,L. Discrimination of regions ki are based on the following criteria: = - Calculation p(ki ) the mean value of the partition ki 1 = N ~l N ---... ----.... (1) X(kij) Where N= size of partition ki Calculation of the maximum and minimum partition (Max X(ki), and Min X(ki». - Finding the rate of change R(ki) decision R(ki) Max X(ki) of the standard intenSity value in the which is Min X(ki) = calulation partition: using: deviation 549 used of the for the region mean in the tf == 1 N SQRT [ ----N j==l L. ( X( kij ) 2 f (ki» ] -------- (2) Since the homogeneity is represented by the reciprocal of the variance [8], the standard deviation is used to measure the homogeneity and to define the dispersion of intensity in the partition. Each region in the image has an upper and lower limit of intensity with specific homogeneity and the whole regions of the image are seperated by the edges, so the rate of change R(ki) is used to decide the existance of more than one region common in the current partition ki H < R(ki) where H is a flexible threshold depending on the user purposes, when H increase, the detected edge decrease and homogeneity of regions increase and vice-versa, that means H decide the height of the detected edges. see figure-l \L i r mean) ------""--- -- - --- f ( )( ) h(X}:;:f(x) -f.n(x} h(X) Figure 1- shows that the partition is divided into two parts the higher which contains pixels greater than the mean value f;and the lower one. As a result, there are two types of partitions: al The edged partition • bl The non - edged partition. 550 a. The local processing on the edged partition; In this partition where the edge does exist, the definition of the edge pixels and their locations are allocated by taking each pixel the partition ki to satisfy the following value X(ki) in conditions: 1. X(ki) > P(ki) and 2. at least one neighbour X(ktp < f(ki) for J f= i If only the first step is satisfied or If X(ki) is unique and not located on one of the four sides of the partition then X(ki) is considered as a noise, and substituted by the mean gray level of the partition. i.e .. X(ki) r == (ki) otherwise the minimum value of the edge pixels is found -MinEand their mean value is calculated: re( 1>.i) D == l ±. 1 :::: _ __ E E==l, ••• number of edge pixels X(kij) J==l (ki) - MinE where D is the difference to be compared with lower and upper limit values taken to enhance the edge. i.e. IF D > FU ~ fe ( ki) == re e k i) + FU IF D < FL --.,.. fee ki) == fe( ki) + FL where FU & FL are the upper and lower limit values taken to get the proper stretching enhancement. Finally the edge pixels are enhanced as follows: if edge if if pixel == == == == X( ki) > re( ki) ~ XC ki) == fee ki) X (ki) + 51 < fee ki) -+ X( Ki)== f( ki) X (ki) + 52 <f ---7 X(Ki)== (ki) + 51 X(ki) + 52 where 51 and 52 are an adaptive thresholds taken to enhance the edge pixels and remove the effect of the noise on it. The non - edge pixels in the same partition are enhanced depending on the calculated mean value wen- of the non-edge pixels: IF x (ki) >rn( ki) X (ki) <f ---+ X( ki) (ki)~ == rn( ki) X(ki) == X (ki) + t 551 --------(3) -------... -(4) where t is a variable threshold given by the user interactively and un is the mean value of the non edge pixels in the partition. b. The local processing on the non-edge partition; The non-edge pixels are enhanced by stretching and treated just like the non-edge pixels in the local processing on the edge partition. Equations 3 and 4 The technique described above is in terms of gray level distribution. Elementary operation, such as enhancement, noise suppression, derivation of textures, can be performed without blurring edges of object; On the contray edgs are extracted and defined by their locations. Regarding the noisy pixels which appear as edges, they are easily recognized and enhanced by substituting the mean gray level of the partition for the gray level of the noisy pixel. The (4x4 pixels) partition is scanned over the image only once, as a result the set of the values of all pixels forms the enchanced picture with detected edges. c. If the current and next partitions do not contain an edge pixels, then an additional step is done by taking intermediate 4x4 partition as shown below, which is composite of last half of 2 3 4 1 '2 1 2 3 ... Formgr parti tion 3 4 4 - Intermediat Later partHion partition first partition and first half of the later partition. Then the new partition is checked for the existence of an edge pixels*. 3. Evaluation of the algorithm based on a test image To assess the performance of the above mentioned algorithm, test images are generated containing edge signals which are characterized numerically. Two test images wher used, one consists of rectangle on a lighter surround both with constant gray level 5 and 20 (see figure 2.a) and second consists of two *Other probability is taken when one of the current or the next partition contains an edge pixels, then the difference between the mean value of the two partitions is compared with the taken rate of change to decide if the adjacent side of the two partitions contains an edge pixels. 552 SAftPIE ~f GRAY SHAtfS 1 2 J 4 5 II 7 t: 9 10 11 12 1l 1q 15 III 17 18 19 20 21 22 23 2Q 25 26 ------....... H») 111ZZZXXXAAAIl1ln8t18COItUUUUU . . . . . . . UUU.UUIIIIII1II. - c- -b- -a- ZZZZZZZZZZZ7.ZZ2ZZZZZ ZIIIIIIIIIIIIIIIIIIIII IIIIIII1III11111I1111 1111I111111I1I1111111 1I111111111II11111111 11I111111I11111111111 111111111111111111111 II1I11111111111111111 1I11II11II11111111111 1II111111111111111111 I11III11111I111111111 1I111I1I11I1111111111 1I111II11111111111111 111111111.11111111111 1II1111I1I11111111111 1II111111111111111111 111111111111111111111 111111111111111111111 111111111111111.11111 III1II1I1I1I111I11111 1I11II11111I111111111 III111111111I11111111 1I111I1I1I1I111111111 EEEEIEEEE1EfEt~EEEEEE ZIXX'~f.~,~t'~~&~!'~~=~ ZIX j(ajlJ;If.41Ujf.d~~141fj~td:::;'f ZI~~ilflttlltillai~iXI22 ZI~&lltilittlililia'XIZ2 ZI~&III!lltlfiff~iIIXI2Z ZI~&ltllltlliaiiilliXl2Z Zll~lli'lliil~iiflliXIZZ ZI~~iiii!lllillllfiIXI2Z ZI~~'tllllif'tlttttiXIL2 E F F E E E E E E E E E F E E E E E E E E E ZI~~fiia!tliitliljl!XI~Z E Zl4&lillllfllilllltlXIZZ E ZI~&illjiftiittlllliXIL~ E ZI~~lilllfifiitl~'~IXIZZ F 1: ZI~~llltf'flial~!tI5XI~Z E E ZI&~'tf51IilltltltliXI2Z ZI~~ltiilalifi~tiltiXI2Z ZI!~!llf~la«ft!il'I~XI~Z ZI~~i~~lli!t!iltfif~~IZZ 1==lXXXXXXXXXXXiXXX a iillllllllllllllllill E E E F F E E F E EEEEEFEEEEEfE1EEEEEEE z:.:Z"ZZZZZZ22ZlZZ ZZZZlZZZ2ZZ2.2ZZZ II~ /I - II d- II • II II II II /I • I II II II II . /I~~~"~H8Ht"~KIIHlllllllllln""ftr~lIn811 11 ')111111111 ~1Ir.llli 111111111111/11111 foil!' ~ 1\ !!1I1111 .-- ••••••• ++ •••••• IInKIIIIMMII~~"~~HKnll~n811"~!~"nllnll 1Ir.1I1I.1l""IIIIIIr./lI'.II~ 1Ir.1I1!r.I!/lII/lM II I! II II II 1111 ~ IIr.H!11! r. r: r.t'./lr. ~r.t: 1Il1l1l1illlllf.1l11f1 r.!I .-;.+++ ..................... , • .04 I--.f.' ••••••• f IIII~n/llinl1lif~~III\II~lItnnllllllllnllllllllll tBI\""flllll1~II •• all •• II.~KMIIIIIIIIr:1I 1I'/\III1I1r.11I1I\.UIIIIIIIUlnp.IIIIIIMIIIII I1I1I1HhM~MII"al'I' ••• 'II~~e~rll~MII . - - . HI 1 •• ::::::=~:::::~:::::::::::::::: /I . II '--R lrllt.III1I1/1lll11 I. t It I"" H.. 1. t L '--1 . I ................... f .--. ------------------------ ------------------------ II • II II II II • I, E I: f f !: E fL'ltl~t2FE k I: E E f f F. f. f E f l J: £ • ! ! First original test image with gray level (5, 20) Enhanoed image Enhanced edge image of (a) with rate=15 STD= 2.4 Second original test image with gray level (5,7,10) Enhanced image Enhanced edge image of (d) with rate =2 and STD = 0.4 553 ~ e f f f k t l: f II II f t E I: I: E II II r. HtHHHEF. ! E F E r: HHHHffHr~eHFHHfHi!HU • 1/ • II a. b. c. d. e. f. f. E t IlUII . . . . IIII . . . U . . . . . . . UIIIIIU . . /I Figure 2, E l: f 1: E f f .-- . . . . . . . . . . . . . . . . . . . . . . . . --111 11--' " ' 1 " • • • • • • • • , •• If< •• II " .f." +...... --11 I--t ... ++ ............. ,t H I - - . 11.- ••••••••• f t . I t . " l l i •••• --1 II II t f ... - - . .--............. ,...........--. .--.i .................. ,.,.--. 1--" I l f \11--" +•••• .--H ...... "KnI\E~/1I\"hI!MREMMII~I\III1""8I1fMII~1I ~""""nl\/lHr~~~IIIIHllllnanllr.IIIIMnllr.1I IIIHIMI! r.llllllt!1 nt.!1nnlil1/1I1I1I1I1I1r.IIII!I~1I IIM~lIlInlllll!l1l1r./1118KlIlIl\lIl1ftllll~MII~lIn 1I111111r.l11l 'III ~ ~ III! 11 !'I I! II t./I ""/lIIM/I /1/111/1 """XnH/I"II~~II~l1nHIIIIH"~1I113nnnKIIII II~ nr.lI11 1111 PlMi "II~ II 1'1 11/1 11'/1 II M ~, 11/1/111/1 k E E 11--11++ .. 'IM~~r'.!'I:Jllt; 18"" "--II 1I-- •• H •••• r.n;I1I1l':III11S •••••• --. 11I;1r.t:i1IMl1S ,--1 ,1 n 1111.11' +--11 11111111111\/1 hI! ~II ••• I. I •• IUIII ~ II IIH/I 1111 "tlll!~~Mlllld •• " I ' •••• ~lIrl\~~~1I1\1I llro II lit 1\1111111'.1.1 1.11 ••• III /111/1 /111/11111 I': II II II 1I111111 11 MI II .ac ..... I1I1I1/l r.1I1I1l1I III\HII/1~MKII~ ••••• I •• I.IMIII\I'.IIIIII"ft 1\ N1111111111 nMII ~r. '\ (111 nti 11M/! Ii !I II e1111 roll /j II II I'! II MI! ~ nil/! 1\11 nil f.11I111111111 nllll ~II el111 til f f £ ~ •• - - . .-- •••••• H ••• a •••••••••••• --1 . - - •••• t ••• M~r~~"~Mll1 •••• +t--. .-- •••••• fllit,~/I/lilll!'\ 1.i.f .. t--I .-- •••••• +1I~.HI1I'I1r.lIl1.'. t • • - - . .-- ••••••• In!\!1~Ml1l\lIlII'.' ••• --. II II 1111 1Ii111 r.IH r. ... ~, ~ r. 11 1111 nil" r:1I1!1I II 1111 Il II 1111 ~1I1'Ir.1\1I11 ~;a. '111I"1I"!1~ 111111 IHI II II II ~t~tk~~E&LElttct£t~tE~E£f!E£EE .. - - . . . . . . . . . . . . . . . . . . . . 1 • • • • - - . r.lIlIlIl\rft""lInK~II'"~~MM"~II'l\lill~1I1I E ~ E 1-- ••• " " ••••••••••••••• H--II II-- ••••• fl • • • • • • • • • • • • • • • • • - - . 1I1\1Ir.IIII/I~p.r.r.M~rIlIlM/lr.~lIl\a/lr.nIlI1MII II l.tH H f fE -----------------------a--I-----------------------••• I. "I.".'.' •••• 111.--1 IIIIIIIIIIIIKr.llhllll""1I1I1I1I1I1I1I1Ir.8MP.llllftll 11 - •• • • . • l u •• I U n •••••• IIII . . . . . . IIII8I II /I II -e- t E E k E E rectangles one inside the other with spcific modification to measure the ability of technique in orientation detection, gray level used in the second image is 5, 7 and 10 (see figure 2.d). Many types of noise cause image degradation. A model which is widely accepted as accurate for noise is that of additive random gaussian noise, which is generally represented as a random stationary sequence added to the ideal image grey levels in the form of h = f + n, where h is the corrupted image, f is the ideal image, and n is the noise. A set of test images are generated at different signal to noise ratios using different formulas: r1 - r 2 a. SNR = ( 2 ) ~ where pl background ~ p2 & are the respectively mean value for the foreground and is the standard deviation of additive noise. This formula of edge detection. ds b. SNR = _____ was defined by [5] and used in the evaluation dN where dS is the standard deviation of the signal 6N = = = = = = = noise This formula was defined by [9] and applied on the test image for the evaluation of contrast enhancement & edge detection. DEFINITION: Let f= uall; Ri be the noise - free image partitioned into k disjoint regions Ri characterized by i pairs (Xi, Ti), where Xi = {Xl is a set of pixel locations X € Region Ri and where Ti is the thresholding range specifying the partitioning criterion, i=l, ••• k. Then a set of performance indices {€i }, i=l, ••• ,k based on the mean - square error is computed as [2]: €i = 1 2 h(x)}- f(x)] L where hex) is the intensity at x of the noisy image. Q is a smoothing operator to clean noise & preserve edge. L is a normalized factor used for scaling. These measures €i characterize the departure of the processed image from the ideal image at different levels of spatial activity. Figure 3 is a block diagram describing this evaluation method. The smoothing algorithm is applied to the set of simulated test images and computing their performance indices. First the test image was partitioned into two regions regions RI, and R2, a region with low spatial acitivity (homogeneous areas) and region with high spatial activity (edges), respectively. The choice of K=2 is based on the fact that the test image has two major levels of spatial activity (see figure 4a). To study the effects of noise, iterative processing, and the ability to preserve different types of edges, several simulation runs were made using different combinations of signal -to noise ratios and iteration. Some of the results were plotted as shown in fig. 4. It is worthy to note that edge detection using this algorithm is independent of the edge slop and orientation but edge location, so it is not necessary to take thresholding of the image to get the edges because their locations are already defined. This is an example of smoothing algorithm that is designed not only to preserve edges but also to enhance edges and making a contrast enhancement for the whole image • n Q(h) Fig. 3 Block diagram of the image evaluation system using image partitioning f = ideal image; n = additive noise; h = noisy image; Q = noise cleaning operater: Q(h) = restored image; Ri = partitioned regions of f such that UiRi = f; Pi = partitioned regions of Q(h) such that UiPi = Q(h). 555 a b 1. 3 1. a- _-* 1. k X ,0 -- \ L I L L W Q) '" .7 > .6 "7 +> It! * -- • ..J;- o .5 Q) a:: . 4 .2~ . li0 '. '\•.. , " \ .3~ 1 -------- 1 .3 \ I -*I X 1 1 .2r 1. 0 Rate=l ,STD=.41 Rate=2 ,STD=. 4! Rate=4 , STD=. 41 "\ \ 9 ~L 81 Q) • .7 .4 \ .3 ~ .2 \ e 45 10 25 Signa 1 to Noise Ratio t1-i:,2 0' \ 2 100 I I 0 I I I I \\ \\ \ *-- 1 25 10 45 5 i gn a 1 to Noise Ratio A ..Q .p -,-t ::: H 0 H H i%l Q) ~ 6. !i til II ~ I \ 1 .,-t I I I Q) \ ~' \ \ ~.5 H Q) ~ ~ II \ +> fL 't ~* \\ > 6 ...... \ SN? == (-----------) " L· ~Q) Rate=2 ,STD=.2 Rate=2 ,STD=.4 Rate=2 ,STD=. 8\ X W \ ~ til I I 100 § ..q • ~ -,-t Pee (0 l() l() 4. DISCUSSION AND CONCLUSION Edges regions are the regions which involve abrupt changes of brightness. Although there is a considerable and growing body of literature devoted to edge detection and image enhancement. Here, we have introduced a technique that detect the edge and enhance the region locally by working on a partition of the image. The technique decides first if the partition has an edge pixels or not, depending not only on the rate of change of brightness, but also on the average brightness in the partition and on its standard deviation. Then the edge pixels are extracted and enhanced as well as the non-edge pixels. We can get a smooth Wedge picture- with noise reduction and an edge extraction, depending on edge locations, and independent on edge slop and orientation which is the most important step in the known edge - preserving noise smoothing techniques (AVE, KAVE, EDLN, GRADIN, MAXH, FACET, MEDIAN). The stretching contrast enhancement used for the non edge pixels defined on basis of a threshold which is selected interactively corresponding to the user purpose. An evaluation procedure is performed which involves: (1) the division of an image into partitions based on the amount of spatial activity, and (2) the measuring of mean square errors for each partition. Evaluation studies on simulated images were made under the effects of different noise levels. The evaluation measures were used to compare the effectiveness of the proposed technique taking different standard deviations and rate of changes. They perform well in both homogeneous areas and edge domianated areas. Results also show that, using iteration, the technique achieve additional noise reduction and converge to their corresponding error measures. Regarding the proposed algorithm with other algorithms. First the algorithm discussed above deals with the three types of image enhancement simultaneously which are 11 Edge detection,21 Edge enhancement and 31 Contrast enhancement, other algorithms deal with one of the above three types. Second the use of (4x4) partition and accessing the 16 pixels at a time to enhance an (nxn) image, reduce the computational time by n2 divided by the size of partition, in which the iteration is done by shifting one partition at a time to cover the whole image; other methods use partitionining to enhance one pixel at a time, and iteration is done by shifting one pixel to cover the whole image. Thus to enhance an (nxn) image using this method needs n2 step which leads to higher computational time. Third, in trms of relative error, the proposed algorithm gives significant noise reduction in the edge and contrast enhancement in comparision with other methods which use one of the mentioned functions. (see ref.2, the curves of relative error with SNR). 557 REFRENCES: 1- A. DE ~~BUQUERQUE ARAUJO, Slliu obsolute grey level differences M1 edge preserving smoothing approach, electronics letters 5th dec. 1985. vol.21 ~o. 25/26. 2- nOLAND T. CHIl·j AND CAL2\. - LUHG YEH, Quantitative Evaluation of some edge - preserving noise - smoothing techniques, NOTE, computer vision, Graphics and processing, 23, 67 - 91 (1983). 3- A ROSEnFELD AND A.C. K.A:Z, Digital ed., Academic press New York, 1932. 4- B. CHMIDA, B.B CHAUDHURT and D.DUTTA I-Il0U:1DER, On image enhancement and threshold selection using the gray level co-occurence matrix, Pattern recognition letters 3 (j uly, 1935) 243-251. 5- H.K. PRATT, Digital Image Processing, \'lily, l1eH York, 1978. 6- N(IRA SHIOZAKI, Edge Extraction Using Entropy Operator, Computer vision, Graphics and image processing 36, 1-9 (1987). 7- N.A. FURST AND P.E. CAINES Edge Detection \.;ith iIJage Enhancement via Dynamic prograa~ing, Computer vision, Graphics, and image processing, 33,263 -279 (1986). 8- ZBII:1GNIEH E. nOJCIK, Z'-!;. natural approach in image processing and Pattern recognition: rotating neighbourhood technique, self -adapting threshold, Segmentation and shape recognition, pattern recognition, Vol 18 No.5. PP 299-326 1985. 9- OPPE~lHEllI, picture Processing, 2nd A.V. (1978): Application of digital Processing, prentice hall, INC, NevJjersey - U.S.A 558 Signal