Digital Image Pocessing CP-7008 Lectue # 04 Image Enhancement in Spatial Domain Fall 2011
2 domains Spatial Domain : (image plane) Techniques ae based on diect manipulation of pixels in an image Fequency Domain : Techniques ae based on modifying the Fouie tansfom of an image Thee ae some enhancement techniques based on vaious combinations of methods fom these two categoies. CP-7008: Digital Image Pocessing Lectue # 4 2
Good images Fo human visual The visual evaluation of image quality is a highly subjective pocess. It is had to standadize the definition of a good image. Fo machine peception The evaluation task is easie. A good image is one which gives the best machine ecognition esults. A cetain amount of tial and eo usually is equied befoe a paticula image enhancement appoach is selected. CP-7008: Digital Image Pocessing Lectue # 4 3
Spatial Domain Pocedues that opeate diectly on pixels. g(x,y) = T[f(x,y)] whee f(x,y) is the input image g(x,y) is the pocessed image T is an opeato on f defined ove some neighbohood of (x,y) CP-7008: Digital Image Pocessing Lectue # 4 4
Mask/Filte (x,y) Neighbohood of a point (x,y) can be defined by using a squae/ectangula (common used) o cicula subimage aea centeed at (x,y) The cente of the subimage is moved fom pixel to pixel stating at the top of the cone CP-7008: Digital Image Pocessing Lectue # 4 5
Point Pocessing Neighbohood = 1x1 pixel g depends on only the value of f at (x,y) T = gay level (o intensity o mapping) tansfomation function s = T() Whee = gay level of f(x,y) s = gay level of g(x,y) CP-7008: Digital Image Pocessing Lectue # 4 6
Contast Stetching Poduce highe contast than the oiginal by dakening the levels below m in the oiginal image Bightening the levels above m in the oiginal image CP-7008: Digital Image Pocessing Lectue # 4 7
Thesholding Poduce a two-level (binay) image CP-7008: Digital Image Pocessing Lectue # 4 8
Mask Pocessing o Filte Neighbohood is bigge than 1x1 pixel Use a function of the values of f in a pedefined neighbohood of (x,y) to detemine the value of g at (x,y) The value of the mask coefficients detemine the natue of the pocess Used in techniques Image Shapening Image Smoothing CP-7008: Digital Image Pocessing Lectue # 4 9
3 basic gay-level tansfomation functions Negative Log Identity nth oot nth powe Invese Log Linea function Negative and identity tansfomations Logaithm function Log and invese-log tansfomation Powe-law function n th powe and n th oot tansfomations Input gay level, CP-7008: Digital Image Pocessing Lectue # 4 10
Identity function Negative Log nth oot nth powe Output intensities ae identical to input intensities. Is included in the gaph only fo completeness. Identity Invese Log Input gay level, CP-7008: Digital Image Pocessing Lectue # 4 11
Image Negatives Negative nth oot Log nth powe Identity Invese Log Input gay level, An image with gay level in the ange [0, L-1] whee L = 2 n ; n = 1, 2 Negative tansfomation : s = L 1 Revesing the intensity levels of an image. Suitable fo enhancing white o gay detail embedded in dak egions of an image, especially when the black aea dominant in size. CP-7008: Digital Image Pocessing Lectue # 4 12
Example of Negative Image Input Image Negative Image : gives a bette vision to analyze the image CP-7008: Digital Image Pocessing Lectue # 4 13
Log Tansfomations Negative Log Identity nth oot nth powe Invese Log Input gay level, s = c log (1+) c is a constant and 0 Log cuve maps a naow ange of low gay-level values in the input image into a wide ange of output levels. Used to expand the values of dak pixels in an image while compessing the highe-level values. CP-7008: Digital Image Pocessing Lectue # 4 14
Log Tansfomations It compesses the dynamic ange of images with lage vaiations in pixel values Example of image with dynamic ange: Fouie spectum image It can have intensity ange fom 0 to 10 6 o highe. We can t see the significant degee of detail as it will be lost in the display. CP-7008: Digital Image Pocessing Lectue # 4 15
Example of Logaithm Image CP-7008: Digital Image Pocessing Lectue # 4 16
Invese Logaithm Tansfomations Do opposite to the Log Tansfomations Used to expand the values of high pixels in an image while compessing the dakelevel values. CP-7008: Digital Image Pocessing Lectue # 4 17
Powe-Law Tansfomations s = c γ c and γ ae positive constants Powe-law cuves with factional values of γ map a naow ange of dak input values into a wide ange of output values, with the opposite being tue fo highe values of input levels. c = γ = 1 Identity Input gay level, function Plots of s = c γ fo vaious values of γ (c = 1 in all cases) CP-7008: Digital Image Pocessing Lectue # 4 18
Gamma coection Gamma coection Monito Monito γ =1/2.5 = 0.4 γ = 2.5 Cathode ay tube (CRT) devices have an intensity-to-voltage esponse that is a powe function, with γ vaying fom 1.8 to 2.5 The pictue will become dake. Gamma coection is done by pepocessing the image befoe inputting it to the monito with s = c 1/γ CP-7008: Digital Image Pocessing Lectue # 4 19
Anothe example : MRI a c b d (a) a magnetic esonance image of an uppe thoacic human spine with a factue dislocation and spinal cod impingement The pictue is pedominately dak An expansion of gay levels ae desiable needs γ < 1 (b) esult afte powe-law tansfomation with γ = 0.6, c=1 (c) tansfomation with γ = 0.4 (best esult) (d) tansfomation with γ = 0.3 (unde acceptable level) CP-7008: Digital Image Pocessing Lectue # 4 20
Effect of deceasing gamma When the γ is educed too much, the image begins to educe contast to the point whee the image stated to have vey slight wash-out look, especially in the backgound CP-7008: Digital Image Pocessing Lectue # 4 21
Anothe example (a) image has a washed-out appeaance, it needs a compession of gay levels needs γ > 1 (b) esult afte powe-law tansfomation with γ = 3.0 (suitable) (c) tansfomation with γ = 4.0 (suitable) (d) tansfomation with γ = 5.0 (high contast, the image has aeas that ae too dak, some detail is lost) a c b d CP-7008: Digital Image Pocessing Lectue # 4 22
Piecewise-Linea Tansfomation Advantage: Functions The fom of piecewise functions can be abitaily complex Disadvantage: Thei specification equies consideably moe use input CP-7008: Digital Image Pocessing Lectue # 4 23
Contast Stetching incease the dynamic ange of the gay levels in the image (b) a low-contast image : esult fom poo illumination, lack of dynamic ange in the imaging senso, o even wong setting of a lens apetue of image acquisition (c) esult of contast stetching: ( 1,s 1 ) = ( min,0) and ( 2,s 2 ) = ( max,l-1) (d) esult of thesholding CP-7008: Digital Image Pocessing Lectue # 4 24
Gay-level slicing Highlighting a specific ange of gay levels in an image Display a high value of all gay levels in the ange of inteest and a low value fo all othe gay levels (a) tansfomation highlights ange [A,B] of gay level and educes all othes to a constant level (b) tansfomation highlights ange [A,B] but peseves all othe levels CP-7008: Digital Image Pocessing Lectue # 4 25
Bit-plane slicing One 8-bit byte Bit-plane 7 (most significant) Bit-plane 0 (least significant) Highlighting the contibution made to total image appeaance by specific bits Suppose each pixel is epesented by 8 bits Highe-ode bits contain the majoity of the visually significant data Useful fo analyzing the elative impotance played by each bit of the image CP-7008: Digital Image Pocessing Lectue # 4 26
Example The (binay) image fo bitplane 7 can be obtained by pocessing the input image with a thesholding gaylevel tansfomation. Map all levels between 0 and 127 to 0 Map all levels between 129 and 255 to 255 An 8-bit factal image CP-7008: Digital Image Pocessing Lectue # 4 27
8 bit planes Bit-plane 7 Bit-plane 6 Bitplane 5 Bitplane 2 Bitplane 4 Bitplane 1 Bitplane 3 Bitplane 0 CP-7008: Digital Image Pocessing Lectue # 4 28
Histogam Pocessing Histogam of a digital image with gay levels in the ange [0,L-1] is a discete function Whee k : the k th gay level h( k ) = n k n k : the numbe of pixels in the image having gay level k h( k ) : histogam of a digital image with gay levels k CP-7008: Digital Image Pocessing Lectue # 4 29
Nomalized Histogam dividing each of histogam at gay level k by the total numbe of pixels in the image, n Fo k = 0,1,,L-1 p( k ) = n k / n p( k ) gives an estimate of the pobability of occuence of gay level k The sum of all components of a nomalized histogam is equal to 1 CP-7008: Digital Image Pocessing Lectue # 4 30
Histogam Pocessing Basic fo numeous spatial domain pocessing techniques Used effectively fo image enhancement Infomation inheent in histogams also is useful in image compession and segmentation CP-7008: Digital Image Pocessing Lectue # 4 31
Example h( k ) o p( k ) Dak image Components of histogam ae concentated on the low side of the gay scale. Bight image Components of histogam ae concentated on the high side of the gay scale. k CP-7008: Digital Image Pocessing Lectue # 4 32
Example Low-contast image histogam is naow and centeed towad the middle of the gay scale High-contast image histogam coves boad ange of the gay scale and the distibution of pixels is not too fa fom unifom, with vey few vetical lines being much highe than the othes CP-7008: Digital Image Pocessing Lectue # 4 33
Histogam Equalization As the low-contast image s histogam is naow and centeed towad the middle of the gay scale, if we distibute the histogam to a wide ange the quality of the image will be impoved. We can do it by adjusting the pobability density function of the oiginal histogam of the image so that the pobability spead equally CP-7008: Digital Image Pocessing Lectue # 4 34
Pobability Density Function The gay levels in an image may be viewed as andom vaiables in the inteval [0,1] PDF is one of the fundamental desciptos of a andom vaiable CP-7008: Digital Image Pocessing Lectue # 4 35
Histogam Equalization The intensity levels in an image may be viewed as andom vaiables in the inteval [0, L-1]. Let p ( ) and p ( s) denote the pobability density s function (PDF) of andom vaiables and s. CP-7008: Digital Image Pocessing Lectue # 4 36
Histogam Equalization s = T ( ) 0 L 1 a. T() is a stictly monotonically inceasing function in the inteval 0 L -1; b. 0 T ( ) L -1 fo 0 L -1. Lectue # 4 CP-7008: Digital Image Pocessing Lectue # 4 37
Histogam Equalization s = T ( ) 0 L 1 a. T() is a stictly monotonically inceasing function in the inteval 0 L -1; b. 0 T ( ) L -1 fo 0 L -1. T ( ) is continuous and diffeentiable. p ( s) ds = p ( ) d s CP-7008: Digital Image Pocessing Lectue # 4 38
2 Conditions of T() Single-valued (one-to-one elationship) guaantees that the invese tansfomation will exist Monotonicity condition peseves the inceasing ode fom black to white in the output image thus it won t cause a negative image 0 T() 1 fo 0 1 guaantees that the output gay levels will be in the same ange as the input levels. The invese tansfomation fom s back to is = T -1 (s) ; 0 s 1 CP-7008: Digital Image Pocessing Lectue # 4 39
Applied to Image The PDF of the tansfomed vaiable s is detemined by the gay-level PDF of the input image and by the chosen tansfomation function p (s) = s p () d ds CP-7008: Digital Image Pocessing Lectue # 4 40
Tansfomation function A tansfomation function is a cumulative distibution function (CDF) of andom vaiable : s = T ( ) = ( L 1) 0 p ( w) dw whee w is a dummy vaiable of integation Note: T() depends on p () CP-7008: Digital Image Pocessing Lectue # 4 41
Cumulative Distibution function CDF is an integal of a pobability function (always positive) is the aea unde the function Thus, CDF is always single valued and monotonically inceasing Thus, CDF satisfies the condition (a) We can use CDF as a tansfomation function CP-7008: Digital Image Pocessing Lectue # 4 42
Histogam Equalization s = T ( ) = ( L 1) p ( w) dw ds dt ( ) d = = ( L 1) p ( ) 0 w dw d d d = ( L 1) p ( ) 0 p ( s) s p ( ) d p ( ) ( ) 1 p = = = = ds ds (( L 1) p ( ) ) L 1 d CP-7008: Digital Image Pocessing Lectue # 4 43
p s (s) Called p s (s) as a unifom pobability density function p s (s) is always a unifom, independent of the fom of p () CP-7008: Digital Image Pocessing Lectue # 4 44
Example Suppose that the (continuous) intensity values in an image have the PDF p ( ) 2, fo 0 L-1 2 = ( L 1) 0, othewise Find the tansfomation function fo equalizing the image histogam. CP-7008: Digital Image Pocessing Lectue # 4 45
Example s = T ( ) = ( L 1) p ( w) dw = ( L 1) 2 = L 1 0 0 2w ( L 1) 2 dw CP-7008: Digital Image Pocessing Lectue # 4 46
Histogam Equalization Continuous case: s = T ( ) = ( L 1) p ( w) dw 0 Discete values: k s = T ( ) = ( L 1) p ( ) k k j j= 0 k n k j L 1 = ( L 1) = n j k=0,1,..., L-1 MN MN j= 0 j= 0 CP-7008: Digital Image Pocessing Lectue # 4 47
Discete tansfomation function The pobability of occuence of gay level in an image is appoximated by nk p ( k ) = whee k = n 0, 1,..., L-1 The discete vesion of tansfomation s k = T( k = j= 0 k n j n ) = k j= 0 p CP-7008: Digital Image Pocessing Lectue # 4 48 ( j ) whee k = 0, 1,..., L-1
Histogam Equalization Thus, an output image is obtained by mapping each pixel with level k in the input image into a coesponding pixel with level s k in the output image In discete space, it cannot be poved in geneal that this discete tansfomation will poduce the discete equivalent of a unifom pobability density function, which would be a unifom histogam CP-7008: Digital Image Pocessing Lectue # 4 49
Example befoe afte Histogam equalization CP-7008: Digital Image Pocessing Lectue # 4 50
Example befoe afte Histogam equalization The quality is not impoved much because the oiginal image aleady has a boaden gay-level scale CP-7008: Digital Image Pocessing Lectue # 4 51
Example No. of pixels 2 3 3 2 6 5 4 2 4 3 4 3 2 3 5 3 2 4 2 4 4x4 image Gay scale = [0,9] 2 1 0 1 2 3 4 5 6 7 8 9 histogam Gay level CP-7008: Digital Image Pocessing Lectue # 4 52
Gay Level(j) s No. of pixels j= 0 = k k n j j= 0 n j n 0 1 2 3 4 5 6 7 8 9 0 0 6 5 4 1 0 0 0 0 0 0 6 11 15 16 16 16 16 16 0 0 s x 9 0 0 6 / 16 3.3 3 11 / 16 6.1 6 15 / 16 8.4 8 16 / 16 16 / 16 16 / 16 16 / 16 16 9 9 9 9 9 / 16 CP-7008: Digital Image Pocessing Lectue # 4 53
Example No. of pixels 3 6 6 3 8 3 8 6 6 3 6 9 3 8 3 8 6 5 4 3 2 1 Output image Gay scale = [0,9] 0 1 Gay level Histogam equalization CP-7008: Digital Image Pocessing Lectue # 4 54 2 3 4 5 6 7 8 9
Note It is clealy seen that Histogam equalization distibutes the gay level to each the maximum gay level (white) because the cumulative distibution function equals 1 when 0 L-1 If the cumulative numbes of gay levels ae slightly diffeent, they will be mapped to little diffeent o same gay levels as we may have to appoximate the pocessed gay level of the output image to intege numbe Thus the discete tansfomation function can t guaantee the one to one mapping elationship CP-7008: Digital Image Pocessing Lectue # 4 55
Histogam Matching (Specification) Histogam equalization has a disadvantage which is that it can geneate only one type of output image. With Histogam Specification, we can specify the shape of the histogam that we wish the output image to have. It doesn t have to be a unifom histogam CP-7008: Digital Image Pocessing Lectue # 4 56
Histogam Matching Histogam matching (histogam specification) geneate a pocessed image that has a specified histogam Let p ( ) and p ( z) denote the continous pobability z density functions of the vaiables and z. p ( z) is the specified pobability density function. Let s be the andom vaiable with the pobability s = T ( ) = ( L 1) p ( w) dw 0 0 Define a andom vaiable z with the pobability G( z) = ( L 1) p ( t) dt = s z z z CP-7008: Digital Image Pocessing Lectue # 4 57
Histogam Matching s = T ( ) = ( L 1) p ( w) dw G( z) = ( L 1) p ( t) dt = s 0 z 0 z 1 ( ) 1 [ ( )] z = G s = G T CP-7008: Digital Image Pocessing Lectue # 4 58
Histogam Matching: Pocedue Obtain p () fom the input image and then obtain the values of s Use the specified PDF and obtain the tansfomation function G(z) Mapping fom s to z s = ( L 1) p ( w) dw 0 z G( z) = ( L 1) pz ( t) dt = s z = G 1 ( s) 0 CP-7008: Digital Image Pocessing Lectue # 4 59
Histogam Matching: Example Assuming continuous intensity values, suppose that an image has the intensity PDF 2, fo 0 L -1 2 p ( ) = ( L 1) 0, othewise Find the tansfomation function that will poduce an image whose intensity PDF is 2 3z, fo 0 z ( L -1) 3 pz ( z) = ( L 1) 0, othewise CP-7008: Digital Image Pocessing Lectue # 4 60
Histogam Matching: Example Find the histogam equalization tansfomation fo the input image 2w s = T ( ) = ( L 1) p ( ) ( 1) 0 w dw = L dw 0 2 ( L 1) 2 = L 1 Find the histogam equalization tansfomation fo the specified histogam 2 3 z z 3t z G( z) = ( L 1) p ( ) ( 1) 0 z t dt = L dt s 0 3 2 ( L 1) = ( L 1) = The tansfomation function 2 1/3 2 1/3 2 2 1/3 z = ( L 1) s = ( L 1) = ( L 1) L 1 CP-7008: Digital Image Pocessing Lectue # 4 61
Histogam Matching: Discete Cases Obtain p ( j ) fom the input image and then obtain the values of s k, ound the value to the intege ange [0, L-1]. k k ( L 1) s = T ( ) = ( L 1) p ( ) = n k k j j j= 0 MN j= 0 Use the specified PDF and obtain the tansfomation function G(z q ), ound the value to the intege ange [0, L-1]. G( z ) = ( L 1) p ( z ) = s q q z i k i= 0 Mapping fom s k to z q z = G 1 ( s ) q k CP-7008: Digital Image Pocessing Lectue # 4 62
Example Assume an image has a gay level pobability density function p () as shown. P () 2 p ( ) = 0 2 + 2 ;0 1 ;elsewhee 1 0 1 2 0 p ( w ) dw = 1 CP-7008: Digital Image Pocessing Lectue # 4 63
Example We would like to apply the histogam specification with the desied pobability density function p z (z) as shown. P z (z) 2 p z ( z ) = 2z 0 ;0 z 1 ;elsewhee 1 0 1 2 z z 0 p z ( w ) dw = 1 CP-7008: Digital Image Pocessing Lectue # 4 64
Step 1: Obtain the tansfomation function T() s=t() 1 One to one mapping function 0 1 s = T( ) = = 0 = w = ( 2w + 2 )dw 2 2 0 + 2w + 2 p 0 ( w )dw CP-7008: Digital Image Pocessing Lectue # 4 65
Step 2: Obtain the tansfomation function G(z) G( z ) z = 0 ( 2w )dw = z = z 2 z 0 2 CP-7008: Digital Image Pocessing Lectue # 4 66
Step 3: Obtain the invesed tansfomation function G -1 G( z ) = T( ) z 2 = 2 + 2 z = 2 2 We can guaantee that 0 z 1 when 0 1 CP-7008: Digital Image Pocessing Lectue # 4 67
Example Image of Mas moon Image is dominated by lage, dak aeas, esulting in a histogam chaacteized by a lage concentation of pixels in pixels in the dak end of the gay scale CP-7008: Digital Image Pocessing Lectue # 4 68
Image Equalization Tansfomation function fo histogam equalization Histogam of the esult image Result image afte histogam equalization The histogam equalization doesn t make the esult image look bette than the oiginal image. Conside the histogam of the esult image, the net effect of this method is to map a vey naow inteval of dak pixels into the uppe end of the gay scale of the output image. As a consequence, the output image is light and has a washed-out appeaance. CP-7008: Digital Image Pocessing Lectue # 4 69
Note Histogam specification is a tial-and-eo pocess Thee ae no ules fo specifying histogams, and one must esot to analysis on a case-by-case basis fo any given enhancement task. CP-7008: Digital Image Pocessing Lectue # 4 70
Note Histogam pocessing methods ae global pocessing, in the sense that pixels ae modified by a tansfomation function based on the gay-level content of an entie image. Sometimes, we may need to enhance details ove small aeas in an image, which is called a local enhancement. CP-7008: Digital Image Pocessing Lectue # 4 71
Local Histogam Pocessing Define a neighbohood and move its cente fom pixel to pixel At each location, the histogam of the points in the neighbohood is computed. Eithe histogam equalization o histogam specification tansfomation function is obtained Map the intensity of the pixel centeed in the neighbohood Move to the next location and epeat the pocedue CP-7008: Digital Image Pocessing Lectue # 4 72
Local Histogam Pocessing: Example CP-7008: Digital Image Pocessing Lectue # 4 73