Upgrade to Pro — share decks privately, control downloads, hide ads and more …

DIP_2_Spatial

Sponsored · Your Podcast. Everywhere. Effortlessly. Share. Educate. Inspire. Entertain. You do you. We'll handle the rest. →

 DIP_2_Spatial

Avatar for Mohammed Hachama

Mohammed Hachama

September 01, 2025

More Decks by Mohammed Hachama

Other Decks in Education

Transcript

  1. Digital Image Processing Spatial Processing (Week 2,3,4) NHSM - 4th

    year - Fall 2026 - Prof. Mohammed Hachama [email protected] hachama.github.io/home
  2. Outline Intensity Transformations Linear Filtering Non-linear filtering NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 2/18
  3. Types of transformations Transforming an image: g = T ◦

    f New pixel value depends only on the input one New pixel value depends on the surrounding input pixels New pixel value depends on the whole input image NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 4/18
  4. Types of transformations Transforming an image: g = T ◦

    f • Point transformations: g(x , y ) = T [f (x , y )] % Import libraries import cv2 as cv import numpy as np % Read data im = cv.imread(’data/lake.jpg’,0) mn, mx, mnx = im.min(), im.max(), mx-mn h,w=im.shape[0], im.shape[1] out =im.copy() % Processing NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 4/18
  5. Types of transformations Transforming an image: g = T ◦

    f • Point transformations: g(x , y ) = T [f (x , y )] • Processing: two approaches • Naive approach: iterate over pixels for i in range(h): for j in range(w): out[i,j] = 255 * (im[i,j]-mn)/mnx out = out.astype(np.uint8) Complexity (# of operations)? NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 4/18
  6. Types of transformations Transforming an image: g = T ◦

    f • Point transformations: g(x , y ) = T [f (x , y )] • Processing: two approaches • Gray level r ∈ [0, 255] is mapped to s ∈ [0, 255] • Using a reference table (lookup table). NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 4/18
  7. Types of transformations Transforming an image: g = T ◦

    f • Point transformations: g(x , y ) = T [f (x , y )] • Processing: two approaches // Initialization of the LUT LUT = 255*(np.array(range(256))-mn)/mnx for i in range(h): for j in range(w): out[i,j] = LUT(im[i,j]) out = out.astype(np.uint8) Complexity (# of operations)? NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 4/18
  8. Point transformations Example 1: Negative (or complement) of images g(x

    , y ) = 255 − f (x , y ) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  9. Point transformations Example 2: Contrast stretching g(x , y )

    = T (f (x , y )) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  10. Point transformations Example 2: Contrast stretching g(x , y )

    = T (f (x , y )) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  11. Point transformations Example 3: Thresholding g(x , y ) ∈

    {0, 1} or {0, 255}. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  12. Point transformations Example 3: Thresholding g(x , y ) ∈

    {0, 1} or {0, 255}. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  13. Point transformations Example 4: Logarithmic transformations s = c log(1

    + r ) • Stretching dark values and compressing light values. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  14. Point transformations Example 5: Exponential transformations s = cr γ

    • γ < 1: Compress light values and stretch dark values. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 5/18
  15. Local Transformations • The intensity of the image output at

    a pixel is obtained as a function of those pixels belonging to the chosen core NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 6/18
  16. Local Transformations • The intensity of the image output at

    a pixel is obtained as a function of those pixels belonging to the chosen core NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 6/18
  17. Local Transformations • The intensity of the image output at

    a pixel is obtained as a function of those pixels belonging to the chosen core NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 6/18
  18. Local Transformations • The intensity of the image output at

    a pixel is obtained as a function of those pixels belonging to the chosen core NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 6/18
  19. Local Transformations • The intensity of the image output at

    a pixel is obtained as a function of those pixels belonging to the chosen core See next (linear and nonlinear filtering, image restoration) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 6/18
  20. Global Transformations (1) Image Histogram • Many global techniques are

    histogram-based. • Histogram = ”graphical” representation of the gray-level distribution of an image. • H(k) = Number of pixels with a gray-level k. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 7/18
  21. Global Transformations (1) Image Histogram NHSM - 4th year: Digital

    Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 7/18
  22. Global Transformations (1) Image Histogram • Histogram provides a good

    indication of the photometric composition of the image: uniform, unimodal, multimodal. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 7/18
  23. Global Transformations (1) Image Histogram • Two different images having

    the same histogram: no information on spatial distribution. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 7/18
  24. Global Transformations (1) Image Histogram • Color image: one histogram

    for each channel, or • Color images → Gray-level images • Mean value: I = 31 (R + G + B) • Luminance: L = 0.299R + 0.587G + 0.114B Weights derived according to the perception of the human eye. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 7/18
  25. Global Transformations (2) Example 1: Histogram Equalization Automatic determination of

    a transformation T to achieve a uniform histogram NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 8/18
  26. Global Transformations (2) Example 1: Histogram Equalization Automatic determination of

    a transformation T to achieve a uniform histogram NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 8/18
  27. Global Transformations (2) Example 1: Histogram Equalization Automatic determination of

    a transformation T to achieve a uniform histogram NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 8/18
  28. Global Transformations (2) Example 1: Histogram Equalization • Step 1:

    Compute the histogram h(k), k ∈ [0, 255] • Step 2: Histogram normalization hn (k) = h(k) , k ∈ [0, 255], N N := #of Pixels • Step 3: Cumulative probability distribution C (k) = k X hn (k), k ∈ [0, 255] j=0 • Step 4: Transformation of the intensities f ′ (x , y ) = 255 × C (f (x , y )) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 8/18
  29. Global Transformations (2) Example 1: Histogram Equalization A 4-bits image

    of size 4 × 4 and the equalized version 13 10 15 15 n ni fi P fi n′ 0 0 0 0 0 1 1 .0625 .0625 1 2 2 .125 .1875 3 14 2 15 8 3 1 .0625 .25 4 2 5 3 13 4 0 0 .25 4 NHSM - 4th year: Digital Image Processing 5 1 .0625 .3125 5 14 9 15 1 6 0 0 .3125 5 9 8 15 15 7 0 0 .3125 5 11 3 15 6 8 1 .0625 .375 6 - Spatial Processing (Week 2,3,4) - 3 5 4 9 11 7 15 1 9 1 .0625 .4375 7 10 1 .0625 .5 8 11 0 0 .5 8 12 0 0 .5 8 13 2 .125 .625 9 14 2 .125 .75 11 M. Hachama ([email protected]) 15 4 0.25 1 15 8/18
  30. Global Transformations (3) Example 2: Adaptive Histogram Equalization (AHE) Input

    image NHSM - 4th year: Digital Image Processing Equalized image - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 9/18
  31. Global Transformations (3) Example 2: Adaptive Histogram Equalization (AHE) Input

    image Equalized image Apply histogram equalization to small regions (tiles) of the image. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 9/18
  32. Global Transformations (3) Example 2: Adaptive Histogram Equalization (AHE) •

    Algorithm Steps 1. Divide the image into tiles (smaller regions, e.g., 8x8 tiles). 2. Compute histograms for each tile. 3. Apply histogram equalization on each tile. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 9/18
  33. Global Transformations (3) Example 2: Adaptive Histogram Equalization (AHE) Input

    image NHSM - 4th year: Digital Image Processing Equalized image (HE) - Spatial Processing (Week 2,3,4) - Equalized image (AHE) M. Hachama ([email protected]) 9/18
  34. Global Transformations (3) Example 2: Adaptive Histogram Equalization (AHE) Input

    image NHSM - 4th year: Digital Image Processing Equalized image (AHE) - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 9/18
  35. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Histogram Equalization and AHE can lead to over-enhancement of noise in homogeneous regions. • → CLAHE (Contrast Limited Adaptive Histogram Equalization) limits the amplification of noise by limiting the contrast of each tile based on a predefined clip limit. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 10/18
  36. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Algorithm Steps 1. Divide the image into tiles (smaller regions, e.g., 8x8 tiles). 2. Compute histograms for each tile. 3. Clip the histograms, i.e., limit the histogram values to the clip limit to prevent noise amplification. 4. Redistribute the clipped pixels uniformly across the histogram. 5. Apply histogram equalization on each tile. 6. Interpolate the pixel values in the tile borders (for smoothness). NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 10/18
  37. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Original Image  52 85   85  52  85   85  52 85 55 70 70 55 70 70 55 70 NHSM - 4th year: Digital Image Processing 61 64 64 61 64 64 61 64 59 59 59 59 59 59 59 59 79 59 59 79 59 59 79 59 61 55 55 61 55 55 61 55 - Spatial Processing (Week 2,3,4) - 76 61 61 76 61 61 76 61  60 79   79  60  79   79  60 79 M. Hachama ([email protected]) 10/18
  38. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 1: Divide the Image into (2 × 2) Tiles    52 55 61 59 79 85 70 64 59 59    Tile 1:   Tile 2:  85 70 64 59 59 52 55 61 59 79  85 85  Tile 3:  52 85 70 70 55 70 NHSM - 4th year: Digital Image Processing 64 64 61 64  59 59   59 59  59 59  Tile 4:  79 59 - Spatial Processing (Week 2,3,4) - 61 55 55 61 76 61 61 76  60 79   79 60 55 55 61 55 61 61 76 61  79 79   60 79 M. Hachama ([email protected]) 10/18
  39. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Steps 2+3+4 Intensity 52 55 59 Tile 1: 61 64 70 85 NHSM - 4th year: Digital Image Processing Original freq. 2 2 4 2 2 2 2 Clipped freq. 2 2 2 2 2 2 2 - Spatial Processing (Week 2,3,4) - Redistrib. freq. 2 + 2/7 2 + 2/7 2 + 2/7 2 + 2/7 2 + 2/7 2 + 2/7 2 + 2/7 M. Hachama ([email protected]) 10/18
  40. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Steps 2+3+4 Intensity 55 59 Tile 2: 60 61 76 79 NHSM - 4th year: Digital Image Processing Original freq. 2 2 2 4 2 4 Clipped freq. 2 2 2 2 2 2 - Spatial Processing (Week 2,3,4) - Redistrib. freq. 2 + 4/6 2 + 4/6 2 + 4/6 2 + 4/6 2 + 4/6 2 + 4/6 M. Hachama ([email protected]) 10/18
  41. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Steps 2+3+4 Intensity 52 55 59 Tile 3: 61 64 70 85 NHSM - 4th year: Digital Image Processing Original freq. 1 1 4 1 3 3 3 Clipped freq. 1 1 2 1 2 2 2 - Spatial Processing (Week 2,3,4) - Redistrib. freq. 1 + 5/7 1 + 5/7 2 + 5/7 1 + 5/7 2 + 5/7 2 + 5/7 2 + 5/7 M. Hachama ([email protected]) 10/18
  42. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Steps 2+3+4 Intensity 55 59 Tile 4: 60 61 76 79 NHSM - 4th year: Digital Image Processing Original freq. 3 3 1 4 1 4 Clipped freq. 2 2 1 2 1 2 - Spatial Processing (Week 2,3,4) - Redistrib. freq. 3 3 2 3 2 3 M. Hachama ([email protected]) 10/18
  43. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 5: Apply Histogram Equalization on each tile. Tile 1 Intensity 52 55 59 61 64 70 85 Rela. freq. 0.1429 0.1429 0.1429 0.1429 0.1429 0.1429 0.1429 CDF 0.1429 0.2857 0.4286 0.5714 0.7143 0.8571 1 NHSM - 4th year: Digital Image Processing Tile 2 Equal. val. 32 73 109 146 182 219 255 Intensity 55 59 60 61 76 79 - Spatial Processing (Week 2,3,4) - Real. freq. 0.1667 0.1667 0.1667 0.1667 0.1667 0.1667 CDF 0.1667 0.3333 0.5 0.6667 0.8333 1 Equal. val. 43 85 128 170 213 255 M. Hachama ([email protected]) 10/18
  44. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 5: Apply Histogram Equalization on each tile. Tile 3 Intensity 52 55 59 61 64 70 85 Rela. freq. 0.1071 0.1071 0.2143 0.1071 0.2143 0.2143 0.2143 CDF 0.1071 0.2143 0.4286 0.5357 0.7500 0.9643 1 NHSM - 4th year: Digital Image Processing Tile 4 Equal. val. 27 55 109 137 191 246 255 Intensity 55 59 60 61 76 79 - Spatial Processing (Week 2,3,4) - Real. freq. 0.1875 0.1875 0.125 0.1875 0.125 0.1875 CDF 0.1875 0.375 0.5 0.6875 0.8125 1 Equal. val. 43 85 128 170 207 255 M. Hachama ([email protected]) 10/18
  45. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Resulting Equalized Image (before step 6)  32 73 146 109 255 170 255 219 182 109 144 43   255 219 182 109 144 43   32 73 146 109 255 170  255 246 191 109 85 43   43 255 246 191 109 85   27 55 137 109 255 170 255 246 191 109 85 43 NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - 213 170 170 213 170 170 207 170  128 255   255  128  255   255  128 255 M. Hachama ([email protected]) 10/18
  46. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 6: Interpolate the pixel values in the tile borders. For simplicity, assume the borders are averaged. • Horizontal averaging. 32 255   255   32  255   255   27 255  73 219 219 73 246 246 55 246 NHSM - 4th year: Digital Image Processing 146 182 255 182 127 144 182 182 144 146 109 255 191 97 85 191 97 85 137 182 255 191 97 85 170 43 43 170 43 43 170 43 - Spatial Processing (Week 2,3,4) - 213 170 170 213 170 170 207 170  128 255   255  128  255   255  128 255 M. Hachama ([email protected]) 10/18
  47. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 6: Interpolate the pixel values in the tile borders. For simplicity, assume the borders are averaged. • Vertical averaging. 32  255    255  144   255    255   27 255  73 219 219 160 246 246 55 246 NHSM - 4th year: Digital Image Processing 146 182 255 182 127 144 182 182 144 164 109 170 191 97 85 191 97 85 137 182 255 191 97 85 170 43 43 107 43 43 170 43 - Spatial Processing (Week 2,3,4) - 213 170 170 192 170 170 207 170  128 255    255   192  255    255   128  255 M. Hachama ([email protected]) 10/18
  48. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Step 6: Interpolate the pixel values in the tile borders. For simplicity, assume the borders are averaged. • Corner averaging. 32 255   255  144  255   255   27 255  73 219 219 160 246 246 55 246 NHSM - 4th year: Digital Image Processing 146 182 182 127 182 182 164 140 191 97 191 97 137 182 191 97 255 170 213 144 43 170 144 43 170 170 107 192 85 43 170 85 43 170 255 170 207 85 43 170 - Spatial Processing (Week 2,3,4) -  128 255   255  192  255   255  128 255 M. Hachama ([email protected]) 10/18
  49. Global Transformations (4) Example 3: Contrast Limited Adaptive Histogram Equalization

    • Resulting Equalized Image Original image NHSM - 4th year: Digital Image Processing Equalized image - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 10/18
  50. Global Transformations (5) Example 4: Histogram Specification (matching) The histogram

    of a reference image A is known (hA ), and we would like to modify an image B to produce another image C whose histogram resembles that of A. P 1. Compute the cumulative distribution A: h̄A = hA . P 2. Compute the cumulative distribution B: h̄B = hB . 3. For each value of h̄B , find the minimum value in h̄A such that h̄A ≥ h̄B . The corresponding value of n′ is the new grayscale value in C . NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 11/18
  51. Global Transformations (5) Example 4: Histogram Specification (matching) 13 10

    15 15 14 2 15 8 2 5 3 13 14 9 15 1 11 7 15 15 Reference (A) 13 0 15 4 0 2 1 11 13 5 15 0 13 10 15 15 14 2 15 8 Input (B) 2 5 3 13 14 9 15 2 Output (C ) n P hA 0 0 1 .0625 2 .1875 3 .25 4 .25 5 .3125 6 .3125 7 .3125 8 .375 9 .4375 10 .5 11 .5 12 .5 13 .625 14 .75 15 1 ni hB P hB n′ 3 .1875 .1875 2 1 .0625 .25 3 1 .0625 .3125 5 0 0 .3125 5 1 .0625 .375 8 1 .0625 .4375 9 0 0 .4375 9 1 .0625 .5 10 0 0 0.5 10 0 0 0.5 10 0 0 0.5 10 2 .125 .625 13 0 0 .625 13 2 .125 .75 14 0 0 .75 14 4 .25 1 15 NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 11/18
  52. Global Transformations (5) Example 4: Histogram Specification (matching) • Left/right

    Image NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 11/18
  53. Global Transformations (5) Example 4: Histogram Specification (matching) • Right

    image histogram matched to left image NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 11/18
  54. Global Transformations (5) Example 4: Histogram Specification (matching) • Right

    image histogram matched to left image Source Histogram NHSM - 4th year: Digital Image Processing Target Histogram - Spatial Processing (Week 2,3,4) - Matched Histogram M. Hachama ([email protected]) 11/18
  55. Linear Filtering NHSM - 4th year: Digital Image Processing -

    Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 12/18
  56. Linear Filtering (1) Filtering = Transformation of an image •

    Definition • Filter an electronic, optical, or acoustic device: blocks signals or radiations of certain frequencies while allowing others to pass. • Filter a signal or an image: transform that signal/image. • Applications • Noise reduction (Smoothing, denoising,...) • Enhancing discontinuities, features • Implementation of differential operators: derivatives, ... • Multiresolution analysis • Linear filters • Continuous linear filter invariant in time = convolution • Separable filter: decomposable into two 1D filters applied successively in horizontal and vertical directions. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  57. Linear Filtering (1) Filtering: Masking process • Using values in

    the neighborhood of (x,y) to define the new value • A 3 × 3 pixel mask is common • Applying the pixel mask pixel by pixel across the image • To avoid altering the overall brightness of the image, the sum of the coefficients must be equal to 1 1 2 4 3 10 1 NHSM - 4th year: Digital Image Processing 0 1 2 ⊗ 1 1 1 0 0.1 0 -1 -1 = -1 - Spatial Processing (Week 2,3,4) - 5 M. Hachama ([email protected]) 13/18
  58. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  59. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  60. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  61. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  62. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  63. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  64. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  65. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  66. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  67. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  68. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  69. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  70. Linear Filtering (1) Filtering: Masking process NHSM - 4th year:

    Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  71. Linear Filtering (1) Filtering: Masking process Example NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  72. Linear Filtering (1) Filtering: Masking process Example NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  73. Linear Filtering (1) Filtering: Masking process • Mask vs convolution

    Kernel (g ∗ h)(x , y ) = 1 1 X X h(i, j) f (x − i, y − j) i=−1 j=−1 Kernel coefficients hij × image values at position (-i,-j) • Example: 1  H= 0 −1  2 1 −2  3  0  −3  =⇒ −3  M= 0 3 −2 1 2  −1  0  1 Mask = Kernel flipped horizontally and vertically. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  74. Linear Filtering (1) Boundary Conditions • Do not process pixels

    on the edge: Resulting image is smaller! • Partial mask: Process edge pixels with a small number of neighbors. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  75. Linear Filtering (1) Boundary conditions: Zero-padding H= 1 6 H⊗

    8 9 8 3 8 10 6 11 9 10 NHSM - 4th year: Digital Image Processing 0 1 1 6 0 1 2 1 0 6 0 8 0 →H⊗ 10 0 7 0 0 0 1 0 0 1 6 8 9 0 - Spatial Processing (Week 2,3,4) - 0 8 3 8 10 0 0 6 11 9 10 0 0 6 8 10 7 0 0 0 0 0 0 0 M. Hachama ([email protected]) 13/18
  76. Linear Filtering (1) Boundary conditions: Image Mirror 5 0 H⊗

    5 5 6 6 6 6 7 7 15 7 NHSM - 4th year: Digital Image Processing 8 8 →H⊗ 8 8 5 5 0 5 5 5 5 5 0 5 5 5 - Spatial Processing (Week 2,3,4) - 6 6 6 6 6 6 7 7 7 15 7 7 8 8 8 8 8 8 8 8 8 8 8 8 M. Hachama ([email protected]) 13/18
  77. Linear Filtering (1) Example 1: Mean Filter • Filter where

    all coefficients are equal • Replaces each pixel with the average value of its neighbors • Examples: 3 × 3, 5 × 5 H= 1 9 1 1 1 1 1 1 NHSM - 4th year: Digital Image Processing 1 1 , 1 H= 1 25 1 1 1 1 1 - Spatial Processing (Week 2,3,4) - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 M. Hachama ([email protected]) 13/18
  78. Linear Filtering (1) Example 1: Mean Filter • Smooths the

    image • Reduces noise and non-essential details • Blur the image (blur edges) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  79. Linear Filtering (1) Example 2: Gaussian Filter • Weighted average

    filter: gives more importance to the central pixel and its nearby neighbors. • The weights are determined by the values of a Gaussian. • Separable filter: 2D Gaussian = product of two 1D Gaussians. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  80. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  81. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  82. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  83. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  84. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  85. Linear Filtering (1) Example 2: Gaussian Filter NHSM - 4th

    year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  86. Linear Filtering (1) Evaluation of the denoising • Mean Squared

    Error (MSE ): MSE = N 1 X (Ii − Îi )2 N i=1 where N is the # of pixels, I, Î are the original and denoised image. • Root Mean Squared Error (RMSE ): same unit as the pixel values √ RMSE = MSE • Normalized Mean Squared Error (NMSE): MSE NMSE = Var(I) where Var(I) is the variance of the original image. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  87. Linear Filtering (1) Evaluation of the denoising • Peak Signal-to-Noise

    Ratio (PSNR): derived from MSE  2  R PSNR = 10 · log10 MSE where R is the maximum possible pixel value (e.g., 255 for 8-bit images). NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  88. Linear Filtering (1) Evaluation of the denoising • Structural Similarity

    Index (SSIM): SSIM(I, Î) = (2µI µÎ + C1 )(2σI Î + C2 ) 2 (µI + µ2Î + C1 )(σI2 + σÎ2 + C2 ) where µ and σ are the mean and variance/covariance values. C1 and C2 are constants to stabilize the division. 2µ µ +C 1 I Î • Luminance µ2 +µ 2 +C = Similarity of the average brightness. 1 I • Î 2σI Î +C2 Contrast σ2 +σ 2 +C : Covariance based criterion. 2 I Î High SSIM (∼ 1) indicates better denoising with preserved image quality. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 13/18
  89. Linear Filtering (2) Example 3: Derivation Filters - Gradient •

    The gradient at a point (x,y) is a two-dimensional vector. • The gradient is a vector perpendicular to the contour. • The norm of the gradient is often referred to as the gradient. • Approximation of the first derivative (Taylor’s formula) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 14/18
  90. Linear Filtering (2) Example 3: Derivation Filters - Gradient •

    Prewitt (k = 1) and Sobel operators (k = 2) -1 0 1 -k 0 k -1 0 1 -1 -k -1 0 0 0 -1 0 0 1 0 1 -1 0 1 k 1 • Roberts Operators NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 14/18
  91. Linear Filtering (2) Example 3: Derivation Filters - Gradient •

    Gradient representations NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 14/18
  92. Linear Filtering (2) Example 4: Derivation Filters - The Laplacian

    • The Laplacian is the simplest isotropic derivative operator. It is a scalar linear operator. 0 1 0 1 -4 1 0 1 0 1 1 1 1 -8 1 1 1 1 Isotropic with respect to rotations of 90 or 45 degrees. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 14/18
  93. Linear Filtering (3) Example 5: Enhancement Filters - Laplacian -

    g = f − ∆f , NHSM - 4th year: Digital Image Processing 0 -1 0 -1 5 -1 - Spatial Processing (Week 2,3,4) - 0 -1 0 M. Hachama ([email protected]) 15/18
  94. Linear Filtering (3) Example 5: Enhancement Filters - Laplacian -

    NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 15/18
  95. Linear Filtering (3) Example 5: Enhancement Filters - Laplacian g

    = f + λ(f − fb ) where fb is a regularized version (median, gaussian, ...) NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 15/18
  96. Linear Filtering (3) Example 5: Enhancement Filters - Laplacian -

    NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 15/18
  97. Linear Filtering (3) Example 5: Enhancement Filters - Laplacian -

    NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 15/18
  98. Non-linear filtering NHSM - 4th year: Digital Image Processing -

    Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 16/18
  99. Non-linear filtering Non-linear filtering • Replaces each pixel with a

    value selected based on a criterion, e.g., statistical • Cannot be implemented as a convolution product • Reduces noise with less blurring NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  100. Non-linear filtering Example 1: Max Filter • Replaces each pixel

    with the maximum value of its neighbors • Useful for eliminating ”pepper” noise NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  101. Non-linear filtering Example 2: Min Filter • Replaces each pixel

    with the minimum value of its neighbors • Useful for eliminating ”salt” noise NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  102. Non-linear filtering Example 3: Median Filter • Replaces each pixel

    with the median value of its neighbors • Effective against salt-and-pepper noise NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  103. Non-linear filtering Example 3: Median Filter • Gaussian/Median Filter NHSM

    - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  104. Non-linear filtering Example 4: Mean Shift Filter • Treat each

    pixel as a data point in a high-dimensional space. • Iteratively shifting data points towards regions of high data density. • Shift each pixel towards regions of similar pixel intensities. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  105. Non-linear filtering Example 4: Mean Shift Filter • Treat each

    pixel as a data point in a high-dimensional space. • Iteratively shifting data points towards regions of high data density. • Shift each pixel towards regions of similar pixel intensities. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  106. Non-linear filtering Example 4: Mean Shift Filter • Treat each

    pixel as a data point in a high-dimensional space. • Iteratively shifting data points towards regions of high data density. • Shift each pixel towards regions of similar pixel intensities. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  107. Non-linear filtering Example 4: Mean Shift Filter • Treat each

    pixel as a data point in a high-dimensional space. • Iteratively shifting data points towards regions of high data density. • Shift each pixel towards regions of similar pixel intensities. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  108. Non-linear filtering Example 4: Mean Shift Filter • Treat each

    pixel as a data point in a high-dimensional space. • Iteratively shifting data points towards regions of high data density. • Shift each pixel towards regions of similar pixel intensities. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  109. Non-linear filtering Example 5: Mean Shift Filter • x is

    a vector in R5 : position+colors. • Mean Shift Update x ∈N(x ) K (xi − x )xi P xnew = Pi xi ∈N(x ) K (xi − x ) • N(x ) is the neighborhood of x , • K is the kernel function (e.g., Gaussian kernel). • Update the colors. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  110. Non-linear filtering Example 5: Mean Shift Filter Noisy image NHSM

    - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  111. Non-linear filtering Example 5: Mean Shift Filter Median filtering NHSM

    - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  112. Non-linear filtering Example 5: Mean Shift Filter Mean shift filtering

    NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 17/18
  113. Assignment 2 Write a python code that depends on the

    OpenCV library and that performs all the methods of this lecture: 1. Point transformations 2. Local Transformations 3. Global Transformations: AHE, CLAHE, Histogram Equalization, Histogram Specification 4. Linear Filtering: Mean, Gaussian, Gradient, Laplacian, with applications. 5. Non-linear filtering: Min, Max, Median, and Mean Shift Filters. Simulations should be conducted to evaluate (qualitative and quantitative) and compare the methods with various parameters. NHSM - 4th year: Digital Image Processing - Spatial Processing (Week 2,3,4) - M. Hachama ([email protected]) 18/18