Digital Image Processing Part 2: Image Enhancement Digital Image Processing Course Introduction in the Spatial Domain Lecture AASS Learning Systems Lab, Teknik Room T26 achim.lilienthal@tech.oru.se Course Book Chapter 3
Contents. Image Enhancement in the Spatial Domain 2. Grey Level Transformations 3. Histogram Processing 4. Operations Involving Multiple Images 5. Spatial Filtering
Contents Image Enhancement in the Spatial Domain
Image Enhancement in the Spatial Domain Image Enhancement image processing the result is supposed to be "more suitable" "more suitable" according to a certain application more suitable for visual interpretation
Image Enhancement in the Spatial Domain We want to create an image which is "better" in some sense. helps visual interpretation (brightening, sharpening ) subjective pre-processing for a subsequent image analysis algorithm performance metric (performance of a task) make the image more "specific" application dependent T f(x,y) g(x,y) original image (or set of images) new image
Image Enhancement in the Spatial Domain Spatial Domain versus Frequency Domain spatial domain direct manipulation of the pixels discussed in this lecture three types of transformations in the spatial domain: pixel brightness transformations, point processing (depend only on the pixel value itself) spatial filters, local transformations or local processing (depend on a small neighbourhood around the pixel) geometric transformations frequency domain: modifications of the Fourier transform discussed in the next lectures
Image Enhancement in the Spatial Domain Transformations in the Spatial Domain g ( x, y) = T[ f ( x, y)] standard approach: T is applied to a sub-image centred at (x,y) sub-image is called mask (kernel, filter, template, window) mask processing or filtering
Contents Gray Level Transformations
2 Grey Level Transformations Grey Level Transformations simplest case: each pixel in the output image depends only on the corresponding pixel in the input image x neighbourhood (point processing) examples (contrast stretching) s = T (r) s = T (r)
2 Grey Level Transformations Grey Level Transformations contrast stretching thresholding
2 Grey Level Transformations Common Grey Level Transformations (Single Image) linear identity inverse power law n. power n. root logarithmic... with more than one input image sum, mean statistical operations (variance, t-test )
2 Grey Level Transformations Common Grey Level Transformations (Single Image) linear identity inverse (negative) power law n. power n. root logarithmic
2 Grey Level Transformations Common Grey Level Transformations (Single Image) inverse transform
Contents Histogram Processing
3 Histogram Processing Grey Scale Histogram shows the number of pixels per grey level
3 Histogram Processing Grey Scale Histogram neutral transform
3 Histogram Processing Grey Scale Histogram neutral transform inverse transform
3 Histogram Processing Grey Scale Histogram neutral transform inverse transform logarithmic transform
3 Histogram Processing Grey Scale Histogram brightness (addition / subtraction)
3 Histogram Processing Grey Scale Histogram brightness (addition / subtraction) contrast (histogram stretching)
3 Histogram Processing Grey Scale Histogram brightness (addition / subtraction) contrast (histogram stretching)
2 Grey Level Transformations Contrast Stretching piecewise linear function
2 Grey Level Transformations Contrast Stretching piecewise linear function power law transformation (gamma transformation) γ s = cr
3 Histogram Processing Histogram Equalization contrast / brightness adjustments sometimes need to be automatised "optimal" contrast for an image? flat histogram histogram normalization to get a given shape for the histogram (see GW 3.3.2)
3 Histogram Processing Histogram Equalization consider the continuous case: probability density functions (PDFs) of s and r are related by transformation function = cumulative density function (CDF) ds dr p s ( s) = p r ( r) dr ds r T ( r) = p r ( ω) dω = s, r [,] p r ( r) T ( s) r d = T ( r) = pr ( ω) dω = pr ( r) p s ( s) = dr
Histogram Processing 3 Histogram Equalization discrete case does not generally produce a uniform PDF tends to spread the histogram enables automatic contrast stretching = = = = = k j j k j j r k k n n r p r T s ) ( ) ( n n r p k k r = ) (
3 Histogram Processing Histogram Equalization CDF
3 Histogram Processing Histogram Equalization
3 Histogram Processing Adaptive / Localized Histogram Equalization transform a single pixel by histogram equalization calculated over a square or rectangular neighbourhood original image global histogram equalization
3 Histogram Processing Adaptive / Localized Histogram Equalization transform a single pixel by histogram equalization calculated over a square or rectangular neighbourhood original image local histogram equalization (radius = )
3 Histogram Processing Adaptive / Localized Histogram Equalization transform a single pixel by histogram equalization calculated over a square or rectangular neighbourhood original image local histogram equalization (radius = 5)
3 Histogram Processing Adaptive / Localized Histogram Equalization transform a single pixel by histogram equalization calculated over a square or rectangular neighbourhood original image local histogram equalization (radius = 25)
3 Histogram Processing Adaptive / Localized Histogram Equalization transform a single pixel by histogram equalization calculated over a square or rectangular neighbourhood original image local histogram equalization (radius = 2)
3 Histogram Processing Use of Histogram Statistics for Image Enhancement idea: instead of using the image histogram directly, we can instead use statistical parameters derived from it mean: measure of average grey level in the image / neighbourhood variance: measure of average contrast in the image / neighbourhood example in GW (see chapter 3.3.4) compare local with global mean and variance and decide whether the pixel is processed or not g( x, y) = E f f ( x, y) ( x, y) if m k m AND k σ otherwise σ S x, y G G S x, y 2 G k σ
Contents Operations Involving Multiple Images
4 Operations Involving Multiple Images Operations Between Two or More Images image subtraction Angiography tracking
4 Operations Involving Multiple Images Image Subtraction DSA (Digital Subtraction Angiography) mask image live image DSA image
4 Operations Involving Multiple Images Image Subtraction tracking with a stationary camera background image live image difference image
4 Operations Involving Multiple Images Operations Between Two or More Images image subtraction Angiography tracking image averaging (GW 3.4.2) noise reduction background modeling
Contents Spatial Filtering
5 Spatial Filtering Neighbourhood Relations Between Pixels a pixel has 4 or 8 neighbours in 2D depending on the neighbour definition: 4-neighborhood each neighbor must share an edge with the pixel 8- neighborhood each neighbor must share an edge or a corner with the pixel
5 Spatial Filtering Basics of Spatial Filtering the pixel value in the output image is calculated from a local neighbourhood in the input image the local neighbourhood is described by a mask with a typical size of 3x3, 5x5, 7x7, pixels filtering is performed by moving the mask over the image the centre pixel in the output image is given a value that depends on the input image and the weights of the mask
5 Spatial Filtering Basics of Spatial Filtering filter subimage defines coefficients w(s,t) used to update pixel at (x,y)
5 Spatial Filtering Linear Spatial Filtering filter subimage defines coefficients w(s,t) response of the filter at point (x,y) is given by a sum of products a g ( x, y) = w( s, t) f ( x + s, y + t) s= at= b also called convolution (convolution mask) b (-,-) (-,) (-,) (,-) (,) (,) (,-) (,) (,)
5 Spatial Filtering Linear Spatial Filtering Implementation generic code: How to Deal With the Border? for P(x,y) in image for F(u,v) in filter Q(x,y) += F(u,v) P(x-u,y-v) end end limit excursion of the centre of the mask smaller image set outside pixel value zero border effects mirroring border pixel values border effects modify filter size along the border slower
5 Spatial Filtering Smoothing Spatial Filters (Averaging Filters) for blurring removal of small (irrelevant) details, bridging smallgaps for noise reduction Smoothing Spatial Filters Mean Filter need for normalization to conserve the total energy of the image (sum of all greylevels) quick results in severe edge blurring x /9
5 Spatial Filtering Smoothing Spatial Filters Mean Filter original Mean 5x5 Mean x
5 Spatial Filtering Smoothing Spatial Filters Gaussian Filter weighted average 2D Gaussian kernel higher weight in the centre to decrease blurring Why a Gaussian? simple model of blurring in optical systems smooth x /6 2 2 4 2 2
5 Spatial Filtering Smoothing Spatial Filters Median Filter take the values of the input image corresponding to the desired sub-window (3x3, 5x5, ) sort them take the middle value (example: 3x3 the 5th largest) forces pixels with distinct grey levels to be more like their neighbours very good at reduce salt-and-pepper noise less blurring than linear filters of the same size
5 Spatial Filtering Smoothing Spatial Filters Median Filter take the median value over the sub-window X ray image of a circuit board Average 3x3 Median 3x3
5 Spatial Filtering Smoothing Spatial Filters Median Filter take the median value over the sub-window original image mean 3x3 mean 5x5 mean x
5 Spatial Filtering Order Statistics Filters (Fractile Filters) median min, max useful in mathematical morphology percentile generalization of median, min, max 3 7 25% percentile 2 4 5 2 2 3 4 5 7 8 8 2 min (%) median (5%) max (%)
5 Spatial Filtering Order Statistics Filters (Fractile Filters) median min, max useful in mathematical morphology percentile generalization of median, min, max order statistics filters are nonlinear filters order statistics do not have an equivalent in the frequency domain
5 Spatial Filtering Sharpening Spatial Filters highlight fine detail (also noise) enhance edges uses image differentiation Sharpening Spatial Filters D approximation to st Order Derivation equivalent to the D convolution mask f x f ( x + ) f ( x) -
Spatial Filtering 5 Gradient and Magnitude of the Gradient Sharpening Spatial Filters Based on the Gradient Roberts Sobel Prewitt y f x f y f x f f + + = 2 2 = y f x f f,
5 Spatial Filtering Sharpening Spatial Filters Roberts (cross gradient operators) f f f + = G x + G x y 2 masks approximate G x and G y in y - -
5 Spatial Filtering Sharpening Spatial Filters Sobel Operators 2 masks approximate G x and G y in detects horizontal and vertical edges f f f + = G x + G y x y - 2-2 2 - - -2 rotations give the other 6 convolution masks, including diagonal edges
5 Spatial Filtering Sharpening Spatial Filters Sobel Operators weight 2 is supposed to smooth by emphasizing the centre - -2-2 - 2-2
5 Spatial Filtering Sharpening Spatial Filters Sobel Operators detection of vertical dark-light edges - -2 2 -
5 Spatial Filtering Sharpening Spatial Filters Sobel Operators combination of all the directional responses
5 Spatial Filtering Sharpening Spatial Filters Prewitt gradient edge detector f f f + = G x + G x y 2 masks approximate G x and G y in y - - - - -
5 Spatial Filtering Sharpening Spatial Filters comparison between Sobel and Prewitt operator Sobel (~ G x + G y ) Prewitt (~ G x + G y )
5 Spatial Filtering Sharpening Spatial Filters highlight fine detail (also noise) enhance edges uses image differentiation Sharpening Spatial Filters D approximation to st order derivation approximation to 2 nd order derivation 2 f = f ( x + ) + f ( x ) 2 f ( x) 2 x equivalent to the D convolution mask -2
5 Spatial Filtering Sharpening Spatial Filters Laplace Filter Laplacian (second order derivative) 2 2 2 f f = + 2 2 x y thinner edges not so strong response to a step better response to fine details double response to edges rotation independent one mask for all edges
5 Spatial Filtering Sharpening Spatial Filters Laplace Filter Laplacian (second order derivative) 2 = 2 f 2 x + 2 f 2 y 2 f 2 x = f ( x + ) + f ( x ) 2 f ( x) filter masks to implement the Laplacian add the "digital implementation" of the two terms in the Laplacian (9 rotation symmetry) add also diagonal terms (45 rotation symmetry) -4 negative values re-scale -8
5 Spatial Filtering Sharpening Spatial Filters Laplace Filter detection of edges independent of direction isotropic with respect to 9 rotations - - 4 - -
5 Spatial Filtering ] Sharpening Spatial Filters Laplace Filter \ Laplace filter + original image sharpening - - 5 - -
5 Spatial Filtering Sharpening Spatial Filters Laplace filter + original image sharpening
5 Spatial Filtering ] Sharpening Spatial Filters Unsharp Masking \ analog equivalent used in publishing industry \ basic idea: subtract blurred version of an image from original image to generate the edges