Presentation is loading. Please wait.

Presentation is loading. Please wait.

Digital Image Processing Image Enhancement in the Spatial Domain.

Similar presentations


Presentation on theme: "Digital Image Processing Image Enhancement in the Spatial Domain."— Presentation transcript:

1 Digital Image Processing Image Enhancement in the Spatial Domain

2 2 Contrast Enhancement Example Original image with low contrast Enhanced image

3 3 Contrast Enhancement Example before after Iris Recognition

4 4 Contrast Enhancement Example before after

5 5 Contrast Enhancement Example before after Microarray Techniques

6 6 Image Enhancement Enhancement Technique Input Image Better Looking Image Application specific No general theory

7 7 Principle Objective of Enhancement Process an image so that the result will be more suitable than the original image for a specific application. The suitableness is up to each application. A method which is quite useful for enhancing an image may not necessarily be the best approach for enhancing another image

8 8 Approaches Spatial Domain: (image plane) –Techniques are based on direct manipulation of pixels in an image Transform Domain: (Fourier or Wavelets) –Techniques are based on modifying the transform coefficients of an image There are some enhancement techniques based on various combinations of methods from the two categories, such as Multiscale techniques.

9 9

10 10 Good Images? For human visual –The visual evaluation of image quality is a highly subjective process. –It is hard to standardize the definition of a good image. For machine perception –The evaluation task is easier. –A good image is one which gives the best machine recognition results. A certain amount of trial and error usually is required before a particular image enhancement approach is selected.

11 11 Spatial Domain Procedures that operate directly on pixels. g(x,y) = T[f(x,y)] where –f(x,y) –f(x,y) is the input image –g(x,y) –g(x,y) is the processed image –T f (x,y) –T is an operator on f defined over some neighborhood of point (x,y)

12 12 Mask/Filter Neighborhood of a point (x,y) can be defined by using a square/rectangular (common used) or circular subimage area centered at (x,y) The center of the subimage is moved from pixel to pixel starting at the top of the corner (x,y)

13 13 Point Processing Neighborhood = 1×1 Mask gf(x,y) g depends on only the value of f at (x,y) T T = gray level (or intensity or mapping) transformation function s = T(r) where r f(x,y) r = gray level of f(x,y) s g(x,y) s = gray level of g(x,y)

14 14 Contrast Stretching Produce higher contrast than the original by –darkening the levels below m in the original image –Brightening the levels above m in the original image

15 15 Produce a two-level (binary) image Thresholding

16 16 Mask Processing or Filtering NBHD is bigger than 1x1 pixel Use a function of the values of f in a predefined NBHD of (x,y) to determine the value of g at (x,y) The value of the mask coefficients determine the nature of the process Used in techniques –Image Sharpening –Image Smoothing

17 17 Three basic gray-level transformations Linear Transformation –Negative –identity Logarithm Transformation –Log –inverse-log (exp) Power-law function –n th power –n th root transformations Input gray level, r Output gray level, s Negative Log nth root Identity nth power Inverse Log

18 18 Identity Function Output intensities identical to input intensities. Included in the graph for completeness, only Input gray level, r Output gray level, s Negative Log nth root Identity nth power Inverse Log

19 19 Image Negatives [0, L-1]L = 2 nAn image with gray level in the range [0, L-1] where L = 2 n ; n = 1, 2,… Negative transformation : s = L – 1 –r Reversing the intensity levels of an image. Suitable for enhancing white or gray detail embedded in dark regions of an image, especially when the black area dominants in size. Input gray level, r Output gray level, s Negative Log nth root Identity nth power Inverse Log

20 20 Digital Negative L x 0 L

21 21 Example of Negative Images Original mammogram showing a small lesion Negative Image : a better vision to analyze the mage

22 22 Logarithmic Transformations (Nonlinear Stretching) s = c log (1+r) c is a constant and r  0 Log curve maps a narrow range of low gray-level values in the input image into a wider range of output levels. Used to expand the values of dark pixels in an image while compressing the higher-level values.

23 23 Log Transformations Compressing the dynamic range of images with large variations in pixel values –Stretches dark region, suppresses bright region Example of image with dynamic range: Fourier spectrum image –It can have intensity range from 0 to 10 6 or higher. –We can not see the significant degree of detail as it will be lost in the display.

24 24 Example of Log Image Result after apply the log transformation with c = 1, range = 0 to 6.2 Fourier Spectrum with range = 0 to 1.5 x 10 6

25 25 Range Compression L x 0 c=100 y

26 26 Inverse Logarithm Transformations (exp) Do opposite to the Log Transformations –Expanding bright regions –Compressing the darker-level values.

27 27 Popular Nonlinear Stretching Functions

28 28 Power-Law Transformations s = cr  c and  are positive constants Power-law curves with fractional values of  map a narrow range of dark input values into a wider range of output values, with the opposite being true for higher values of . c =  = 1  Identity function Input gray level, r Output gray level, s s = cr  Plots of s = cr  for various values of  (c = 1 in all cases)

29 29 Gamma Correction Cathode ray tube (CRT) devices have an intensity- to-voltage response that is a power function, with  varying from 1.8 to 2.5 The picture becomes darker. s = cr 1/ Gamma correction is done by preprocessing the image before displaying it in the monitor with s = cr 1/  Monitor Gamma correction  = 2.5  =1/2.5 = 0.4

30 30 Gamma Correction: MRI (a) a magnetic resonance image of an upper human spine with a fracture dislocation and spinal cord impingement (اصابت) –The picture is predominately dark –An expansion of gray levels are desirable  needs  < 1 (b) result after power-law transformation with  = 0.6, c=1 (c) transformation with  = 0.4 (best result) (d) transformation with  = 0.3 (under acceptable level) ab cd

31 31 Effect of Decreasing Gamma When the  is reduced too much, the image begins to reduce contrast to the point where the image started to have very slight “wash- out” look, especially in the background. –Why background?

32 32 Another example (a) image has a washed-out appearance, it needs a compression of gray levels  needs  > 1 (b) correction with  = 3.0 (suitable) (c) correction with  = 4.0 (suitable) (d) correction with  = 5.0 (high contrast, the image has areas that are too dark, some detail is lost) ab cd Original image

33 33 Linear Stretching

34 34 Illustration of Linear Stretching

35 35 Piecewise Linear Stretching

36 36 Piecewise-Linear Transformation Functions Advantage: –The form of piecewise functions can be arbitrarily complex Disadvantage: –Their specification requires considerably more user specified inputs (parameters)

37 37 Contrast Stretching (a) increase the dynamic range of the gray levels in the image (b) a low-contrast image: result from poor illumination, lack of dynamic range in the imaging sensor, or even wrong setting of a lens aperture of image acquisition (c) result of contrast stretching: (r 1,s 1 ) = (r min,0) and (r 2,s 2 ) = (r max,L-1) (d) result of thresholding r 1 =r 2 and s 1 =0 and s 2 =L-1

38 38 Contrast Stretching L x 0 ab yaya ybyb y

39 39 Clipping L x 0 ab

40 40 Gray-level slicing Highlighting a specific range of gray levels in an image –Display a high value of all gray levels in the range of interest and a low value for all other gray levels (a) transformation highlights range [A,B] of gray level and reduces all others to a constant level (b) transformation highlights range [A,B] but preserves all other levels Brighten in the range

41 41 Bit-plane slicing Highlighting the contribution made to total image appearance by specific bits Suppose each pixel is represented by 8 bits Higher-order bits contain the majority of the visually significant data Useful for analyzing the relative importance played by each bit of the image Bit-plane 7 (most significant) Bit-plane 0 (least significant) One 8-bit byte

42 42 Example The (binary) image for bit-plane 7 can be obtained by processing the input image with a thresholding gray-level transformation. –Map all levels between 0 and 127 to 0 –Map all levels between 129 and 255 to 255 An 8-bit fractal image

43 43 Eight-bit Planes Bit-plane 7Bit-plane 6 Bit- plane 5 Bit- plane 4 Bit- plane 3 Bit- plane 2 Bit- plane 1 Bit- plane 0

44 44 Summary of Point Operations So far, we have discussed various forms of f(x) that leads to different enhancement results The natural question is: How to select an appropriate f(x) for an arbitrary image? One systematic solution is based on the histogram information of an image

45 45 How to Enhance the Contrast Low contrast –image values concentrated near a narrow range (mostly dark, or mostly bright, or mostly medium values) Contrast enhancement –change the image value distribution to cover a wide range Contrast of an image can be revealed by its histogram

46 46 Histogram Based Enhancement Histogram of an image represents the relative frequency of occurrence of various gray levels in the image MATLAB function >imhist(x)

47 47 Why Histogram? Histogram information reveals that image is under-exposed It is a baby in the cradle!

48 48 Another Example Over-exposed image

49 49 Histogram Processing Histogram of a digital image with gray levels in the range [0,L-1] is a discrete function h(r k ) = n k where –r k : the k th gray level –n k : the number of pixels in the image having gray level r k –h(r k ): histogram of a digital image with gray levels r k

50 50 Normalized Histogram r k nDividing each of histogram at gray level r k by the total number of pixels in the image, n p(r k ) = n k / n For k = 0,1,…,L-1 p(r k ) r kp(r k ) gives an estimate of the probability of occurrence of gray level r k The sum of all components of a normalized histogram is equal to 1

51 51 Histogram Histogram of an image with L possible gray levels, f = 0, 1, …, L-1. –P(1) = nl / n n1 is the number of pixels with gray level l. n is the total number of pixels in the image.

52 52 Examples of Histograms

53 53 Histogram Processing Applications Basic for numerous spatial domain processing techniques Used effectively for image enhancement Information inherent in histograms also is useful in image compression and segmentation

54 54 Example Dark image Bright image Components of histogram are concentrated on the low side of the gray scale. Components of histogram are concentrated on the high side of the gray scale.

55 55 Example Low-contrast image High-contrast image histogram is narrow and centered toward the middle of the gray scale histogram covers broad range of the gray scale and the distribution of pixels is not too far from uniform, with very few vertical lines being much higher than the others

56 56 Histogram Equalization As the low-contrast image’s histogram is narrow and centered toward the middle of the gray scale, if we distribute the histogram to a wider range the quality of the image will be improved. We can do it by adjusting the probability density function of the original histogram of the image so that the probability spreads equally

57 57 Histogram Equalization

58 58 01rkrk s k = T(r k ) s r T(r) Histogram Transformation s = T(r) Where 0  r  1 T(r) satisfies –(a). T(r) is single- valued and monotonically increasingly in the interval 0  r  1 –(b). 0  T(r)  1 for 0  r  1

59 59 Two Conditions of T(r) Single-valued (one-to-one relationship) guarantees that the inverse transformation will exist Monotonicity condition preserves the increasing order from black to white in the output image thus it won’t cause a negative image 0  T(r)  1 for 0  r  1 guarantees that the output gray levels will be in the same range as the input levels. The inverse transformation from s back to r is r = T -1 (s) ; 0  s  1

60 60 The probability density function (pdf or shortly called density function) of random variable x is defined as the derivative of the cdf: Random Variables

61 61 Random Variables The pdf satisfies the following properties:

62 62 If a random variable x is transformed by a monotonic transformation function T(x) to produce a new random variable y, the probability density function of y can be obtained from knowledge of T(x) and the probability density function of x, as follows: Random Variables Valid if T(x) is an increasing or decreasing monotonic function.

63 63 Random Variables A function T(x) is monotonically increasing if T(x 1 ) < T(x 2 ) for x 1 < x 2, and A function T(x) is monotonically decreasing if T(x 1 ) > T(x 2 ) for x 1 < x 2. The preceding equation is valid if T(x) is an increasing or decreasing monotonic function.

64 64 Applied to an Image Let –p r (r) –p r (r) denote the PDF of random variable r –p s (s) –p s (s) denote the PDF of random variable s p r (r)T(r)T -1 (s) p s (s)If p r (r) and T(r) are known and T -1 (s) satisfies condition (a) then p s (s) can be obtained using a formula : The PDF of the transformed variable s is determined by the gray-level PDF of the input image r and by the chosen transformation function

65 65 Transformation function A transformation function is a cumulative distribution function (CDF) of random variable r : Note: T(r) depends on p r (r)

66 66 Cumulative Distribution function CDF is an integral of a probability function (always positive) is the area under the function Thus, CDF is always single valued and monotonically increasing Thus, CDF satisfies the condition (a) We can use CDF as a transformation function

67 67 Finding p s (s) from given T(r) Substitute and yield

68 68 p s (s) As p s (s) is a probability function, it must be zero outside the interval [0,1] in this case because its integral over all values of s must equal 1. a uniform probability density functionp s (s): a uniform probability density function p s (s) is always uniform and independent of the form of p r (r)

69 69 A random variable s characterized by a uniform probability function yields 0 1 s P s (s)

70 70 Histogram Equalization

71 71 Discrete Transformation Function The probability of occurrence of gray level in an image is approximated by The discrete version of transformation

72 72 Histogram Equalization r k s kThus, an output image is obtained by mapping each pixel with level r k in the input image into a corresponding pixel with level s k in the output image In discrete space, it cannot be proved in general that this discrete transformation will produce the discrete equivalent of a uniform probability density function, which would be a uniform histogram

73 73 ExampleExample beforeafterHistogram equalization

74 74 Histogram Comparison beforeafter

75 75 Example beforeafterHistogram equalization The quality is not improved much because the original image already has a broaden gray-level scale

76 76 Example

77 Gray Level(j) 0123456789 No. of pixels 0065410000 006111516 00 6/ 16 11 / 16 15 / 16 16 / 16 16 / 16 16 / 16 16 / 16 16 / 16 {s×(9-0) /(1-0)} +0 00 3.3  3 6.1  6 8.4  8 99999

78 78 Example 3663 8386 6369 3838 Output image Gray scale = [0,9] Histogram equalization 01 1 2 2 3 3 4 4 5 5 6 6 789 No. of pixels Gray level 4242 5323 3424 2332 Original

79 79 NOTE! It is clearly seen that –Histogram equalization distributes the gray level to reach the maximum gray level (white) because the cumulative distribution function equals 1 when 0  r  L-1 –If the cumulative numbers of gray levels are slightly different, they will be mapped to little different or same gray levels as we may have to approximate the processed gray level of the output image to integer number –Thus the discrete transformation function can not guarantee the one to one mapping relationship.

80 80 SUMMARY: Discrete Histogram Equalization Given an image of M×N with maximum gray level being L–1: 1. Obtain the histogram H(k), k = 0, 1, …, L-1 2. Compute the cumulative normalized histogram T(k): – T(k) = 3. Compute the transformed intensity: –g k = (L-1) * T(k). 4. Scan the image and set the pixel with the intensity k to g k.

81 81 Histogram Equalization: Example

82 82 Histogram Equalization: Example Histogram Cumulative Normalized Histogram

83 83 Histogram Equalization: Example transformed intensity g k = (L-1) * T(k). To encompass the whole dynamic range.

84 84 Histogram Equalization

85 85 1 2 3 4

86 86 Histogram Matching (Specification) Histogram equalization has a disadvantage which is that it can generate only one type of output image. With Histogram Specification, we can specify the shape of the histogram that we wish the output image to have. It doesn’t have to be a uniform histogram

87 87 Histogram Matching (Specification) Given a desired histogram, the goal is to transform the image intensity such that the transformed image has a histogram matches the desired histogram. Let the initial image histogram be p r, the desired image histogram be p z. Let T be the function that equalizes the original image and G be the function that equalizes the desired image. – r: The initial image intensity. – s: The image intensity after equalization – z: The image intensity of the desired image. – v: The image intensity after equalization of the desired image.

88 88 Consider the continuous domain Let p r (r) denote continuous probability density function of gray-level of input image, r Let p z (z) denote desired (specified) continuous probability density function of gray-level of output image, z Let s be a random variable with the property Histogram equalization of initial image

89 89 Next, we define a random variable z with the property s = T(r) = G(z) We can map an input gray level r to output gray level z thus Histogram equalization Of Desired image Therefore, z must satisfy the condition z = G -1 (s) = G -1 [T(r)] Assume G -1 exists and satisfies the condition (a) and (b)

90 90 Procedure Conclusion 1. Obtain the transformation function T(r) by calculating the histogram equalization of the input image 2.Obtain the transformation function G(z) by calculating histogram equalization of the desired density function

91 91 Procedure Conclusion 3. Obtain the inversed transformation function G -1 4.Obtain the output image by applying the processed gray-level from the inversed transformation function to all the pixels in the input image z = G -1 (s) = G -1 [T(r)]

92 92 Example Assume an image has a gray level probability density function p r (r) as shown. 012 1 2 P r (r) r

93 93 Example We would like to apply the histogram specification with the desired probability density function p z (z) as shown. 012 1 2 P z (z) z

94 94 Step 1: Obtain the transformation function T(r) 0 1 1 s=T(r) r One to one mapping function

95 95 Step 2: Obtain the transformation function G(z); Equalization of the desired pdf

96 96 Step 3: Obtain the inversed transformation function G -1 We can guarantee that 0  z  1 when 0  r  1

97 97 Discrete Formulation

98 98 The Mechanism Behind the Histogram Specification

99 99 Point Processing Methods Histogram Specification Implementation Details: 1.Obtain the histogram Hr(k) of the input image, and Hz(k) of the desired image where k = 0, 1, …, L-1 2.Compute the cumulative normalized histogram (CNH) S k : 3.Precompute Z k for each value of S k using the iterative scheme defined by (G(Z k ) – S k ) >=0, k = 0, 1, …, L-1 4.For each pixel in the original image, if the value of that pixel is r k, map this value to its corresponding level S k ; then map level S k into the final level Z k.

100 100 Example:

101 101 Example: (cont.) rkrk T(r k ) V k =G(z k ) zkzk 0.0833x7= 0.5831~1 SkSk 0.357x7 =0.2499~0

102 102 Some Notes Potential difficulties with histogram specification include –G^-1 may not be unique –Determine the desired histogram Solutions to the potential difficulties: –1. Assign the value that matches the histogram better. –2. Interactively specify a desired PDF (Probability Density Function) and discretize it.

103 103 Histogram Specification

104 104 Example Image is dominated by large, dark areas, resulting in a histogram characterized by a large concentration of pixels in pixels in the dark end of the gray scale Image of Mars moon

105 105 Image Equalization Result image after histogram equalization Transformation function for histogram equalization Histogram of the result image The histogram equalization doesn’t make the result image look better than the original image. Consider the histogram of the result image, the net effect of this method is to map a very narrow interval of dark pixels into the upper end of the gray scale of the output image. As a consequence, the output image is light and has a washed-out appearance.

106 106 Histogram Equalization Histogram Specification Solve the problem Since the problem with the transformation function of the histogram equalization was caused by a large concentration of pixels in the original image with levels near 0 a reasonable approach is to modify the histogram of that image so that it does not have this property

107 107 Histogram Specification (1) the transformation function G(z) obtained from (2) the inverse transformation G -1 (s)

108 108 Result image and its histogram Original image The output image ’ s histogram Notice that the output histogram ’ s low end has shifted right toward the lighter region of the gray scale as desired. After applied the histogram equalization

109 109 Result image and its histogram

110 110 Note Histogram specification is a trial-and-error process There are no rules for specifying histograms, and one must resort to analysis on a case-by-case basis for any given enhancement task.

111 111 Note Histogram processing methods are global processing, in the sense that pixels are modified by a transformation function based on the gray-level content of an entire image. Sometimes, we may need to enhance details over small areas in an image, which is called a local enhancement.

112 112 Local Enhancement define a square or rectangular neighborhood and move the center of this area from pixel to pixel. at each location, the histogram of the points in the neighborhood is computed and either histogram equalization or histogram specification transformation function is obtained. another approach used to reduce computation is to utilize non- overlapping regions, but it usually produces an undesirable checkerboard effect. a)Original image (slightly blurred to reduce noise) b)global histogram equalization (enhance noise & slightly increase contrast but the construction is not changed) c)local histogram equalization using 7x7 neighborhood (reveals the small squares inside larger ones of the original image. (a)(b) (c)

113 113 Explain the result in (c) Basically, the original image consists of many small squares inside the larger dark ones. However, the small squares were too close in gray level to the larger ones, and their sizes were too small to influence global histogram equalization significantly. So, when we use the local enhancement technique, it reveals the small areas. Note also the finer noise texture is resulted by the local processing using relatively small neighborhoods.


Download ppt "Digital Image Processing Image Enhancement in the Spatial Domain."

Similar presentations


Ads by Google