ΠΑΝΕΠΙΣΤΗΜΙΟ ΙΩΑΝΝΙΝΩΝ ΑΝΟΙΚΤΑ ΑΚΑΔΗΜΑΪΚΑ ΜΑΘΗΜΑΤΑ Ψηφιακή Επεξεργασία Εικόνας Μετασχηματισμοί έντασης και χωρικό φιλτράρισμα Διδάσκων : Αναπληρωτής Καθηγητής Νίκου Χριστόφορος Άδειες Χρήσης Το παρόν εκπαιδευτικό υλικό υπόκειται σε άδειες χρήσης Creative Commons. Για εκπαιδευτικό υλικό, όπως εικόνες, που υπόκειται σε άλλου τύπου άδειας χρήσης, η άδεια χρήσης αναφέρεται ρητώς.
Digital Image Processing Intensity Transformations (Histogram Processing) Christophoros Nikou cnikou@cs.uoi.gr University of Ioannina - Department of Computer Science 2 Contents Over the next few lectures we will look at image enhancement techniques working in the spatial domain: Histogram processing Spatial filtering Neighbourhood operations 1
Frequencies 3 Image Histograms The histogram of an image shows us the distribution of grey levels in the image Massively useful in image processing, especially in segmentation Grey Levels 4 Histogram Examples (cont ) 2
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 5 Histogram Examples (cont ) 6 Histogram Examples (cont ) 3
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 7 Histogram Examples (cont ) 8 Histogram Examples (cont ) 4
9 Histogram Examples (cont ) A selection of images and their histograms Notice the relationships between the images and their histograms Note that the high contrast image has the most evenly spaced histogram 10 Contrast Stretching We can fix images that have poor contrast by applying a pretty simple contrast specification The interesting part is how do we decide on this transformation function? 5
11 Histogram Equalisation Spreading out the frequencies in an image (or equalising the image) is a simple way to improve dark or washed out images. At first, the continuous case will be studied: r is the intensity of the image in [0, L-1]. we focus on transformations s=t(r): T(r) is strictly monotonically increasing. T(r) must satisfy: 0 T( r) L 1, for 0 r L 1 12 Histogram Equalisation (cont...) The condition for T(r) to be monotonically increasing guarantees that ordering of the output intensity values will follow the ordering of the input intensity values (avoids reversal of intensities). If T(r) is strictly monotonically increasing then the mapping from s back to r will be 1-1. The second condition (T(r) in [0,1]) guarantees that the range of the output will be the same as the range of the input. 6
13 Histogram Equalisation (cont...) a) We cannot perform inverse mapping (from s to r). b) Inverse mapping is possible. 14 Histogram Equalisation (cont...) We can view intensities r and s as random variables and their histograms as probability density functions (pdf) p r (r) and p s (s). Fundamental result from probability theory: If p r (r) and T(r) are known and s=t(r) is continuous and differentiable, then 1 ps ( s) pr ( r) pr ( r) ds dr dr ds 7
15 Histogram Equalisation (cont...) The pdf of the output is determined by the pdf of the input and the transformation. This means that we can determine the histogram of the output image. A transformation of particular importance in image processing is the cumulative distribution function (CDF) of a random variable: r s T( r) ( L 1) pr ( w) dw 0 16 Histogram Equalisation (cont...) It satisfies the first condition as the area under the curve increases as r increases. It satisfies the second condition as for r=l-1 we have s=l-1. To find p s (s) we have to compute r ds dt () r d ( L 1) pr ( w) dw dr dr ( L 1) pr ( r) dr 0 8
17 Histogram Equalisation (cont...) Substituting this result: ds ( L 1) pr ( r) dr to dr ps( s) pr( r) ds Uniform pdf yields 1 ps( s) pr( r) ( L 1) p ( r ) r 1, 0 s L 1 L 1 18 Histogram Equalisation (cont...) The formula for histogram equalisation in the discrete case is given k s T( r ) ( L 1) p ( r ) k k r j j 0 where r k : input intensity s k : processed intensity n j : the frequency of intensity j MN: the number of image pixels. ( L 1) k n j MN j 0 9
19 Histogram Equalisation (cont...) Example A 3-bit 64x64 image has the following intensities: k s T( r ) ( L 1) p ( r ) k k r j j 0 Applying histogram equalization: 0 s T( r ) 7 p ( r ) 7 p ( r ) 1.33 0 0 r j r 0 j 0 1 s T( r ) 7 p ( r ) 7 p ( r ) 7 p ( r ) 3.08 1 1 r j r 0 r 1 j 0 20 Histogram Equalisation (cont...) Example Rounding to the nearest integer: s 1.33 1 s 3.08 3 s 4.55 5 s 5.67 6 0 1 2 3 s 6.23 6 s 6.65 7 s 6.86 7 s 7.00 7 4 5 6 7 10
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 21 Histogram Equalization (cont ) Example Notice that due to discretization, the resulting histogram will rarely be perfectly flat. However, it will be extended. 22 Equalisation Transformation Function 11
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 23 Equalisation Examples 1 24 Equalisation Transformation Functions The functions used to equalise the images in the previous example 12
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 25 Equalisation Examples 2 26 Equalisation Transformation Functions The functions used to equalise the images in the previous example 13
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 27 Equalisation Examples (cont ) 3 4 28 Equalisation Transformation Functions The functions used to equalise the images in the previous examples 14
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 29 Histogram Specification Histogram equalization does not always provide the desirable results. Image of Phobos (Mars moon) and its histogram. Many values near zero in the initial histogram 30 Histogram Specification (cont...) Histogram equalization 15
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 31 Histogram specification (cont.) In these cases, it is more useful to specify the final histogram. Problem statement: Given p r (r) from the image and the target histogram p z (z), estimate the transformation z=t(r). The solution exploits histogram equalization. 32 Histogram specification (cont ) Equalize the initial histogram of the image: s T( r) ( L 1) pr ( w) dw Equalize the target histogram: s G( z) ( L 1) pz ( w) dw Obtain the inverse transform: z G 1 () s G In practice, for every value of r in the image: get its equalized transformation s=t(r). perform the inverse mapping z=g -1 (s), where s=g(z) is the equalized target histogram. r 0 r 0 1 ( T( r)) G( z) T( r) 16
33 Histogram specification (cont ) The discrete case: Equalize the initial histogram of the image: k s T( r ) ( L 1) p ( r ) k k r j j 0 ( L 1) k n j MN j 0 Equalize the target histogram: q sk G( zq) ( L 1) pz ( ri ) i 0 G( z) T( r) Obtain the inverse transform: 1 zq G ( sk) G 1 ( T( r k )) 34 Histogram Specification (cont...) Example Consider again the 3-bit 64x64 image: It is desired to transform this histogram to: p ( z ) 0.00 p ( z ) 0.00 p ( z ) 0.00 p ( z ) 0.15 z 0 z 1 z 2 z 3 p ( z ) 0.20 p ( z ) 0.30 p ( z ) 0.20 p ( z ) 0.15 z 4 z 5 z 6 z 7 with z 0, z 1, z 2, z 3, z 4, z 5, z 6, z 7. 0 1 2 3 4 5 6 7 17
35 Histogram Specification (cont...) Example The first step is to equalize the input (as before): s 1, s 3, s 5, s 6, s 6, s 7, s 7, s 7 0 1 2 3 4 5 6 7 The next step is to equalize the output: G( z ) 0 G( z ) 0 G( z ) 0 G( z ) 1 0 1 2 3 G( z ) 2 G( z ) 5 G( z ) 6 G( z ) 7 4 5 6 7 Notice that G(z) is not strictly monotonic. We must resolve this ambiguity by choosing, e.g. the smallest value for the inverse mapping. 36 Histogram Specification (cont...) Example Perform inverse mapping: find the smallest value of z q that is closest to s k : s T ( r ) G( z ) k i q s 1 G( z ) 0 0 0 s 3 G( z ) 0 s s s s s s 1 1 5 G( z ) 0 2 2 6 G( z ) 1 3 3 6 G( z ) 2 4 4 7 G( z ) 5 5 5 7 G( z ) 6 6 6 7 G( z ) 7 7 7 s k z q 1 3 3 4 5 5 6 6 7 7 e.g. every pixel with value s 0 =1 in the histogramequalized image would have a value of 3 (z 3 ) in the histogram-specified image. 18
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 37 Histogram Specification (cont...) Example Notice that due to discretization, the resulting histogram will rarely be exactly the same as the desired histogram. 38 Histogram Specification (cont...) Original image Histogram equalization 19
Images taken from Gonzalez & Woods, Digital Image Processing (2002) 39 Histogram Specification (cont...) Histogram equalization 40 Histogram Specification (cont...) Specified histogram Transformation function and its inverse Resulting histogram 20
41 Local Histogram Processing Image in (a) is slightly noisy but the noise is imperceptible. HE enhances the noise in smooth regions (b). Local HE reveals structures having values close to the values of the squares and small sizes to influence HE (c). 42 Summary We have looked at: Different kinds of image enhancement Histograms Histogram equalisation Histogram specification Next time we will start to look at spatial filtering and neighbourhood operations 21
Τέλος Ενότητας Χρηματοδότηση Το παρόν εκπαιδευτικό υλικό έχει αναπτυχθεί στα πλαίσια του εκπαιδευτικού έργου του διδάσκοντα. Το έργο «Ανοικτά Ακαδημαϊκά Μαθήματα στο Πανεπιστήμιο Ιωαννίνων» έχει χρηματοδοτήσει μόνο τη αναδιαμόρφωση του εκπαιδευτικού υλικού. Το έργο υλοποιείται στο πλαίσιο του Επιχειρησιακού Προγράμματος «Εκπαίδευση και Δια Βίου Μάθηση» και συγχρηματοδοτείται από την Ευρωπαϊκή Ένωση (Ευρωπαϊκό Κοινωνικό Ταμείο) και από εθνικούς πόρους.
Σημειώματα Σημείωμα Ιστορικού Εκδόσεων Έργου Το παρόν έργο αποτελεί την έκδοση 1.0. Έχουν προηγηθεί οι κάτωθι εκδόσεις: Έκδοση 1.0 διαθέσιμη εδώ. http://ecourse.uoi.gr/course/view.php?id=1126.
Σημείωμα Αναφοράς Copyright Πανεπιστήμιο Ιωαννίνων, Διδάσκων : Αναπληρωτής Καθηγητής Νίκου Χριστόφορος. «Ψηφιακή Επεξεργασία Εικόνας. Μετασχηματισμοί έντασης και χωρικό φιλτράρισμα». Έκδοση: 1.0. Ιωάννινα 2014. Διαθέσιμο από τη δικτυακή διεύθυνση: http://ecourse.uoi.gr/course/view.php?id=1126. Σημείωμα Αδειοδότησης Το παρόν υλικό διατίθεται με τους όρους της άδειας χρήσης Creative Commons Αναφορά Δημιουργού - Παρόμοια Διανομή, Διεθνής Έκδοση 4.0 [1] ή μεταγενέστερη. [1] https://creativecommons.org/licenses/by-sa/4.0/