Chapter Three
Spatial Domain Image Processing
                                  1
 3.1. Spatial Processing of Digital
               Images
 The term spatial domain refers to the image
  plane itself, and image processing methods in
  this category are based on direct
  manipulation of pixels in an image.
 Two principal categories of spatial processing
  are intensity transformations and spatial
  filtering.
   Intensity transformations operate on single
    pixels of an image for tasks such as contrast
    manipulation and image thresholding.
                                                2
…cont’d
  Spatial filtering performs operations on the
   neighborhood of every pixel in an image.
   Examples of spatial filtering include image
   smoothing and sharpening.
                                              3
The Basics of Intensity Transformations
         and Spatial Filtering
 The   spatial    domain    processes      are
  mathematically expressed as:
   where f(x,y) is an input image, g(x,y) is the
   output image, and T is an operator on f
   defined over a neighborhood of point (x,y).
 The operator can be applied to the pixels of a
  single image or to the pixels of a set of
  images
                                               4
…cont’d
 Figure shows the basic implementation of the
  above equation on a single image.
                                             5
…cont’d
 The process that the above figure illustrates
  consists of moving the center of the
  neighborhood from pixel to pixel, and
  applying the operator T to the pixels in the
  neighborhood to yield an output value at that
  location.
 Thus, for any specific location (x0,y0), the
  value of the output image g at those
  coordinates is equal to the result of applying
  T to the neighborhood with origin at (x0,y0)in f.
                                                  6
…cont’d
 The smallest possible neighborhood is of size
  1x1.
 In this case, g depends only on the value of f
  at a single point (x,y) and T becomes an
  intensity (also called a gray-level, or
  mapping) transformation function of the form
                  s = T(r)
   where, s and r to denote the intensity of g
   and f respectively at any point (x,y).
                                               7
…cont’d
 For example, contrast         stretching   and
  thresholding function.
        Contrast stretching   Thresholding
                                               8
…cont’d
 Contrast stretching is a linear mapping
  function used to manipulate the contrast of an
  image.
 Thresholding produces a binary image
                                               9
3.2. Basic Intensity Transformation
             Functions
 There are three basic types of intensity
  transformation functions:
   Linear (negative and identity transformations),
   Logarithmic       (log      and        inverse-log
    transformations), and
   Power-law (nth power and nth root
    transformations).
   The identity function is the trivial case in which
    the input and output intensities are identical.
                                                    10
…cont’d
          11
Image Negatives
 The negative of an image with intensity levels
  in the range [ 0, L-1] is obtained by using the
  negative transformation function which has
  the form: s = L – 1 – r
 This type of processing is used, for example,
  in enhancing white or gray detail embedded
  in dark regions of an image, especially when
  the black areas are dominant in size.
                                                12
…cont’d
      Image   Negative Image
                               13
Log Transformations
 The general form of the log transformation in
  is      s = c log(1 + r)
  where c is a constant and it is assumed that r ≥ 0.
 The logarithmic (log) transformation is used to
  compress the dynamic range of an image.
 Log transformation maps a narrow range of
  low intensity values in the input into a wider
  range of output levels and the opposite is true
  for higher values of input grayscale levels.
                                                   14
…cont’d
 In other words, values of dark pixels in an
  image are expanded, while the high
  grayscale values are compressed.
 The inverse log transformation does the
  opposite.
 As shown in Figure, log transformation is
  used to view Fourier transformed images, as
  their dynamic ranges are very high.
 Log transformations show the details that are
  not visible due to a large dynamic range of
  pixel values.                               15
…cont’d
Fourier spectrum displayed as a   Result of applying the log
        grayscale image.          transformation with c = 1
                                                               16
         Power-law (Gamma)
           Transformations
 Power-law transformations have the form
  where c and   are positive constants.
 As with log transformations, 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 input levels.
                                               17
…cont’d
 Power-law transformations are useful for
  general-purpose contrast manipulation.
                                         18
 Piecewise Linear Transformation
            Functions
 Complementary        approach     to    Linear,
  Logarithmic, and Power-law transformations.
 The advantage of these functions is that the
  form of piecewise functions can be arbitrarily
  complex.
 The main disadvantage of these functions is
  that their specification requires considerable
  user input.
 Example: Contrast Stretching, Intensity-Level
  Slicing, Bit-Plane Slicing
                                                19
Contrast Stretching
   Low-contrast images can result from poor
    illumination, lack of dynamic range in the
    imaging sensor, or even the wrong setting of a
    lens aperture during image acquisition.
   Contrast stretching expands the range of
    intensity levels in an image so that it spans the
    ideal full intensity range of the recording
    medium or display device.
                                                   20
…cont’d
Piecewise linear              A     low    contrast Result of
transformation                electron image        contrast stretching.
function.
   Contrast stretching is obtained by setting (r1 , s1) = (rmin, 0) and (r2
   , s2 ) = (rmax, L-1), where rmin and rmax denote the minimum and
   maximum intensity levels in the input image                                21
Intensity-Level Slicing
    Highlight a specific range of intensities in an
     image.
    Intensity-level slicing, can be implemented in
     several ways, but most are variations of two
     basic themes.
    One approach is to display in one value (say,
     white) all the values in the range of interest
     and in another (say, black) all other intensities.
    This transformation, produces a binary image.
                                                     22
…cont’d
  The second approach, brightens (or darkens)
   the desired range of intensities, but leaves all
   other intensity levels in the image unchanged.
 Original           First approach   Second approach
                                                       23
Bit-Plane Slicing
    Pixel values are integers composed of bits.
     For example, values in a 256-level grayscale
     image are composed of 8 bits (one byte).
    Instead of highlighting intensity-level ranges,
     Bit-Plane Slicing highlight the contribution
     made to total image appearance by specific
     bits.
                                                        24
                        Bit-planes of an 8-bit image.
…cont’d
          25
3.3 Histogram Processing
Image Histogram
   An image histogram is a type of histogram that
    acts as a graphical representation of the tonal
    distribution in a digital image.
   It plots the number of pixels for each tonal
    value
   The horizontal axis of the graph represents the
    tonal variations, while the vertical axis
    represents the total number of pixels in that
    particular tone.
                                                  26
…cont’d
     Image
                               27
             Image Histogram
…cont’d
 Let rk, for k = 0 1 2 ,…, L - 1 denote the
  intensities of an L-level digital image, f(x, y).
    The unnormalized histogram of f is defined as
     where nk is the number of pixels in f with
     intensity rk, and the subdivisions of the
     intensity scale are called histogram bins.
    The normalized histogram of f is defined as
     Where, M = image rows and N = image columns     28
…cont’d
  Normalized histogram referred to as
   histograms or image histograms.
  The sum of p(rk) for all values of k is always 1.
  Histogram shape is related to image
   appearance.
                                                  29
Histogram Equalization
 Histogram equalization is used for equalizing
  all the pixel values of an image.
 Transformation is done in such a way that
  uniform flattened histogram is produced.
 Histogram       equalization   increases  the
  dynamic range of pixel values and makes an
  equal count of pixels at each level which
  produces a flat histogram with high contrast
  image.
                                              30
…cont’d
  Before equalization   After equalization
                                             31
 For continuous intensity value, a histogram
  equalization     or     histogram linearization
  transformation is given by:
   where L is the number of possible intensity levels
   in the image and the integral on the right side is
   the cumulative distribution function (CDF) of
   random variable r.
 Recall that the probability of occurrence of
  intensity level rk in a digital image is
  approximated by:
                                                    32
…cont’d
• For discrete intensity value, a histogram
  equalization or histogram linearization
  transformation is given by:
                                          33
3.4 Spatial Filtering
 Filter is the process that moves some
  unwanted components or small details in an
  image.
 Spatial filtering modifies an image by
  replacing the value of each pixel by a function
  of the values of the pixel and its neighbors.
 There are two types of spatial filtering:
   Linear spatial filter – the operation performed
    on the image pixels is linear
   Nonlinear spatial filter the operation performed
    on the image pixels is nonlinear               34
Linear spatial filtering
 A linear spatial filter performs a sum-of-
  products operation between an image f and a
  filter kernel (mask), w.
 The kernel is an array whose size defines the
  neighborhood of operation, and whose
  coefficients determine the nature of the filter.
 The filter mask may be 3x3, 5x5, or 7x7 mask
 At any point (x, y) in the image, the response,
  g(x, y), of the filter is the sum of products of
  the kernel coefficients and the image pixels
  encompassed by the kernel:                     35
…cont’d
 In general, linear spatial filtering of an image
  of size M x N with a kernel of size m x n is
  given by the expression:
 For a kernel of size m x n , we assume that
  m=2a +1 and n=2b+1, where a and b are
  nonnegative integers.                          36
…cont’d
          37
        Spatial Correlation and
             Convolution
 Correlation consists of moving the center of a
  kernel over an image, and computing the sum
  of products at each location.
 Spatial convolution are the same, except that
  the correlation kernel is rotated by 180°.
 The correlation of a kernel w of size m x n
  with an image f(x,y), is given by
                                               38
…cont’d
 In a similar manner, the convolution of a
  kernel w of size m n × with an image f(x,y), is
  defined as
                                                39
Types of Spatial Filter
 Spatial filters can be classified by effect into:
    Smoothing spatial filters – also called lowpass
     filters
    Sharpening spatial filters – also called
     highpass filters
                                                      40
Smoothing spatial filters
 Smoothing filters are used for blurring and for
  nose reduction.
 Blurring used as preprocessing such as
  removal of small details from image.
 Noise reduction is blurring with linear or
  nonlinear filter.
 Smoothing filters include:
   Averaging
   Order statistics(non linear)
                                                41
Lowpass Box Filter Kernels
 The simplest, lowpass filter kernel is the box
  kernel, whose coefficients have the same
  value (typically 1).
 An mxn box filter is an mxn array of 1’s, with
  a normalizing constant in front, whose value
  is 1 divided by the sum of the values of the
  coefficients (i.e., 1/mn when all the
  coefficients are 1’s).
                           3x3 box kernel      42
 …cont’d
Origil Image                       Filtered image 3x3
Filtered Image                      Filtered image
11x11                               21x21
                 Image averaging                     43
Lowpass Gaussian Filter Kernels
 Gaussian kernels is obtained by:
 A 3x3 guassian kernel for K = 1 and
                                        44
…cont’d
(a) A test pattern of size 1024x1024. (b) Result of
lowpass filtering the pattern with a Gaussian kernel of
size 21x21 , with         (c) Result of using a kernel of
size 43x43, with
                                                       45
Order-statistic (Nonlinear) Filters
 Order-statistic filters are nonlinear spatial
  filters whose response is based on ordering
  (ranking) the pixels contained in the region
  encompassed by the filter.
 Smoothing is achieved by replacing the value
  of the center pixel with the value determined
  by the ranking result.
 It includes:
   Median filters
   Min filters
   Max filters                               46
…cont’d
Median filter
    Replaces the value of the center pixel by the
     median of the intensity values in the
     neighborhood of that pixel
    It is best for noise reduction
Max filter
    Useful for finding the brightest points in an
     image or for eroding dark areas adjacent to
     light regions.
    Replaces the value of the center pixel by the
     maximum of the intensity values in the
                                                 47
…cont’d
Min filter
    Replaces the value of the center pixel by the
     minimum of the of the intensity values in the
     neighborhood of that pixel
    Useful for finding the darkest points in an
     image
                                                 48
Sharpening Spatial Filters
 Sharpening highlights transitions in intensity.
 Applicable in:
      Electronic printing,
      Medical imaging,
      Industrial inspection, and
      Autonomous guidance in military systems.
                                                    49
Foundations
 Sharpening filters are based on first- and
  second-order derivatives
First Derivative:
   Must be zero in areas of constant intensity.
   Must be nonzero at the onset of an intensity
    step or ramp.
   Must be nonzero along intensity ramps.
   A basic definition of the first-order derivative of
    a one-dimensional function f(x) is the
    difference
                                                     50
…cont’d
Second Derivatives:
   Must be zero in areas of constant intensity.
   Must be nonzero at the onset and end of an
    intensity step or ramp.
   Must be zero along intensity ramps.
   We define the second-order derivative of f(x )
    as the difference
                                                 51
…cont’d
          52
Image Sharpening – the Laplacian
 This approach uses the second order
  derivatives for constructing a filter mask
  (kernel)
 The Laplacian for the image function f(x,y) is
 In the x-direction, we have
 In the y- direction, we have
                                               53
…cont’d
 It follows from the preceding three equations
  that the discrete Laplacian of two variables is
(a)            (b)        (c)         (d)
             Laplacian Kernels
                                                54
…cont’d
 If a negative center coefficient is used , then
  we subtract the Laplacian image from the
  original to obtain a sharpened result.
 Thus, the basic way in which we use the
  Laplacian for image sharpening is
  where f(x,y) and g(x,y) are the input and
  sharpened images, respectively. We let c = −1 if
  the Laplacian kernels in above figure (a) or (b) is
  used, & c = 1 if either of the other two kernels is
  used.                                            55
  …cont’d
  Original image   Laplacian image
                   using kernel (a)
Image sharpend     Image with
using c = -1       kernel (B)
                                56
Image Sharpening – the Gradient
 First derivatives in image processing are
  implemented using the magnitude of the
  gradient.
 The gradient of an image f at coordinates
  (x,y) is defined as the two dimensional
  column vector
                                          57
…cont’d
 The magnitude (length) of vector , denoted
  as M(x,y) (the vector norm notation is also
  used frequently), where
  is the value at (x,y) of the rate of change in the
  direction of the gradient vector.
 M(x,y) is an image of the same size as the
  original, created when x and y are allowed to
  vary over all pixel locations in f. It is called
  gradient image
                                                   58
          Chapter Four
Frequency Domain Image Processing
                                    1
   4.1 Introduction to Frequency
              Domain
 In spatial domain, we deal with images as it
  is. The value of the pixels of the image
  change with respect to scene.
 Whereas in frequency domain, we deal with
  the rate at which the pixel values are
  changing in spatial domain.
 We use the Fourier transform to go from the
  spatial to the frequency domain; to return to
  the spatial domain we use the inverse Fourier
  transform.
                                              2
4.2 Fourier series
 A function f(t) of a continuous variable, t, that
  is periodic with a period, T, can be expressed
  as the sum of sines and cosines multiplied by
  appropriate coefficients. This sum, known as
  a Fourier series, has the form
  where
  are the coefficients.
                                                  3
For example
 The function at the bottom is the sum of the four
  functions above it
                                                  4
Fourier Transform
 Functions that are not periodic can be
  expressed as the integral of sines and/or
  cosines multiplied by a weighting function.
 This sum, known as a Fourier transform, has
  the form
 Conversely, given     , we can obtain f(t)
  back using the inverse Fourier transform,
  written as
                                            5
…cont’d
 Fourier transformation is used in a wide
  range of application such as image filtering,
  image compression, Image analysis and
  image reconstruction etc.
                                              6
4.3 Frequency Spectrum
 In general, the Fourier transform contains
  complex terms, and it is customary for display
  purposes to work with the magnitude of the
  transform (a real quantity), which is called the
  Fourier spectrum or the frequency spectrum:
                                                                          7
   (a) A box function, (b) its Fourier transform, and (c) its spectrum.
     4.4 Continuous 2-D Fourier
      Transform and Its Inverse
 Let f(t,z) be a continuous function of two
  continuous variables, t and z. The two
  dimensional, continuous Fourier transform is
  given by the expressions
  and its inverse is given by
  where     and    are the frequency variables.
                                                  8
…cont’d
 When referring to images, t and z are
  interpreted to be continuous spatial variables.
 The domain of the variables and defines
  the continuous frequency domain.
                                                9
      4.5 Discrete 2-D Fourier
     Transform And Its Inverse
 The 2-D discrete Fourier transform (DFT) is
  given by:
  where f(x,y) is a digital image of size M x N,
    = 0, 1, 2 ,… M – 1 and = 0, 1, 2 ,… N - 1
                                                   10
…cont’d
 Given the transform         , we can obtain
  f(x,y) by using the inverse discrete Fourier
  transform (IDFT):
  for x = 0, 1, 2 ,…, M - 1 and y = 0, 1, 2 , ..., N - 1
                                                           11
    Fourier Spectrum And Phase
               Angle
 Because the 2-D DFT is complex in general,
  it can be expressed in polar form:
  where the magnitude
  is called the Fourier (or frequency) spectrum,
  and
  is the phase angle or phase spectrum.
                                               12
…cont’d
 Finally, the power spectrum is defined as
 R and I are the real and imaginary parts of ,
  and all computations are carried out for the
  discrete variables u = 0, 1, 2 ,…, M - 1 and
  v = 0, 1, 2 , . …, N - 1
 Therefore,       , , ,   , and are arrays of
  size M x N.
                                              13
   4.6 Frequency Information of
             Images
 Frequency in images is the rate of change of
  intensity values.
 Thus, a high-frequency image is the one
  where the intensity values change quickly
  from one pixel to the next.
 On the other hand, a low-frequency image
  may be one that is relatively uniform in
  brightness or where intensity changes very
  slowly.
 Most images contain both high-frequency and
  low-frequency components.                  14
…cont’d
 Let’s see by an example below
                                  15
…cont’d
 Clearly, in the above image, the zebra pattern
  has a high frequency as the intensity changes
  very rapidly from white to black.
 While the intensity changes very gradually in
  the sky thus it has low frequency.
                                               16
     4.7 Image Enhancement in
         Frequency Domain
 Image enhancement is the process of making
  images more useful.
 The reason for doing this include:
   Highlighting
   Remove nose from images interesting detail in
    images
   Making images more visually appealing
                                                17
Types of enhancement Techniques
 There are two broad categories of image
  enhancement techniques:
   Spatial domain techniques – manipulating
    image pixels directly
   Frequency domain techniques – manipulating
    Fourier transform of images
                                             18
    Frequency Domain Filtering
          Fundamentals
 Filtering in the frequency domain consists of
  modifying the Fourier transform of an image,
  then computing the inverse transform to
  obtain the spatial domain representation of
  the processed result.
 Thus, given (a padded) digital image, f(x,y),
  of size PxQ pixels, the basic filtering equation
  in which we are interested has the form:
  where       is the IDFT,           is DFT of the input
  image , f(x,y),       is a filter transform function19
…cont’d
  (which we often call just a filter or filter function),
  and g(x,y) is the filtered (output) image.
 Functions F, H, and g are arrays of size PxQ,
  the same as the padded input image.
 The product                 is formed using
  elementwise multiplication.
 The filter transfer function modifies the
  transform of the input image to yield the
  processed output, g(x,y).
                                                       20
    Filtering steps in Frequency
               Domain
 The process of filtering in the frequency
  domain can:
  1. Given an input image f(x,y) of size MxN,
     obtain the padding sizes P and Q using
     P=2M and Q=2N.
  2. Form a padded image fp (x,y) of size PxQ
     using zero-, mirror-, or replicate padding
  3. Multiply fp (x,y) by (-1)x+y to center the Fourier
     transform on the PxQ frequency rectangle.
  4. Compute the DFT,              , of the image from
     Step 3.                                         21
…cont’d
 5. Construct a real, symmetric filter transfer
    function,        , of size PxQ with center at
    (P/2, Q/2).
 6. Form the product                       using
    elementwise multiplication; that is,
    for i = 0, 1, 2, …, M – 1, and k = 0, 1, 2, …, N – 1
 7. Obtain the filtered image (of size P × Q) by
    computing the IDFT of       :
                                                           22
…cont’d
 8. Obtain the final filtered result, g (x, y), of the
    same size as the input image, by extracting
    the MxN region from the top, left quadrant of
    gp (x,y)
                                                     23
Example
          Step 1   Step 2   Step 3
          Step 4   Step 5   Step 6
          Step 7   Step 8
                                     24
Frequency Domain Filtering
 Filtering in the frequency domain consists of
  modifying the Fourier transform of an image
  and then computing the inverse transform to
  obtain the processed result.
 There are two types of Frequency domain
  filters:
   Lowpass frequency domain filters and
   Highpass frequency domain filters
                                              25
    Lowpass Frequency domain
            Filtering
 Edges and other sharp intensity transitions
  (such as noise) in an image contribute
  significantly to the high frequency content of
  its Fourier transform.
 Hence, smoothing (blurring) is achieved in
  the frequency domain by high-frequency
  attenuation.
 Attenuating high frequency and passing low
  frequency is know as lawpass filtering.
 Three types of lowpass filters: ideal,
  Butterworth, and Gaussian.                   26
Ideal Lowpass Filters
 A 2-D lowpass filter that passes without
  attenuation all frequencies within a circle of
  radius from the origin, and “cuts off” all
  frequencies outside this circle is called an
  ideal lowpass filter (ILPF); It is specified by
  the transfer function:
  where D0 is a positive constant, and D(u,v) is the
  distance between a point (u,v) in the frequency
  domain and the center of the PxQ frequency
  rectangle; that is,                              27
…cont’d
 The name ideal indicates that all frequencies
  on or inside a circle of radius D0 are passed
  without attenuation, whereas all frequencies
  outside the circle are completely attenuated
  (filtered out).
Perspective plot of an ideal   Function displayed   Radial cross section
lowpass-filter transfer        as an image                                 28
function
…cont’d
 For an ILPF cross section, the point of
  transition between the values H(u,v) = 1 and
  H(u, v) = 0 is called the cutoff frequency.
                           a           b           c
                           d           e            f
(a) Original image. (b)–(f) Results of filtering using ILPFs with cutoff
frequencies set at radii values 10, 30, 60, 160, and 460
                                                                      29
Gaussian Lowpass Filters
 Gaussian lowpass filter (GLPF) transfer
  functions have the form
  where, D(u, v) is the distance from the center of
  the PxQ frequency rectangle to any point, (u,v)
  contained by the rectangle.
 By letting            , we can express the
  Gaussian transfer function
  where D0 is the cutoff frequency.
                                                  30
…cont’d
 When D(u,v) = D0 the GLPF transfer function
  is down to 0.607 of its maximum value of 1.0.
Perspective plot of a GLPF   Function displayed   Radial cross section
transfer function            as an image
                                                                     31
…cont’d
  (a) Original image. (b)–(f) Results of filtering using GLPFs
  with cutoff frequencies                                        32
Butterworth Lowpass Filters
 The transfer function of a Butterworth
  lowpass filter (BLPF) of order n, with cutoff
  frequency at a distance D0 from the center of
  the frequency rectangle, is defined as
                                              33
…cont’d
Perspective plot of a BLPF   Function displayed   Radial cross sections
transfer function            as an image.         of BLPFs of orders 1
                                                  through 4.
                                                                      34
…cont’d
   (a) Original image. (b)–(f) Results of filtering using BLPFs
   with cutoff frequencies and n = 2.5
                                                                  35
Summary
 Ideal, Butterworth, and Gaussian cover the
  range from very sharp (ideal) to very smooth
  (Gaussian) filtering.
 The shape of a Butterworth filter is controlled
  by a parameter called the filter order. For
  large values of this parameter, the
  Butterworth filter approaches the ideal filter.
 For lower values, the Butterworth filter is
  more like a Gaussian filter.
 Thus, the Butterworth filter provides a
  transition between two “extremes.”            36
    Highpass Frequency Domain
             Filtering
 Because edges and other abrupt changes in
  intensities are associated with high-frequency
  components, image sharpening can be
  achieved in the frequency domain by
  highpass filtering, which attenuates low-
  frequencies components without disturbing
  high-frequencies in the Fourier transform.
 Three types of lowpass filters: ideal,
  Butterworth, and Gaussian
                                               37
…cont’d
 Subtracting a lowpass filter transfer function
  from 1 yields the corresponding highpass
  filter transfer function in the frequency
  domain:
  where              is the transfer function of a
  lowpass filter.
                                                 38
         Ideal Highpass Filters
 An ideal highpass filter (IHPF) transfer
  function is given by
  where, as before, D(u,v) is the distance from the
  center of the P x Q frequency rectangle
                                                  39
…cont’d
 Perspective plot, image, and, radial cross
  section of an IHPF transfer function.
                                           40
…cont’d
 Example, image filtered with IHPF transfer
  functions using D0 = 60 ( first row) and D0 =
  160 (second row).
                                              41
Gaussian Highpass Filters
 The transfer function of a Gaussian highpass
  filter (GHPF) transfer function is given by
 Perspective plot, image, and, radial cross
  section of an GHPF transfer function.
                                             42
…cont’d
 Example, image filtered with GHPF transfer
  functions using D0 = 60 ( first row) and D0 =
  160 (second row).
                                              43
Butterworth Highpass Filters
 The transfer function of    a   Butterworth
  highpass filter (BHPF) is
 Perspective plot, image, and, radial cross
  section of an BHPF transfer function.
                                            44
…cont’d
 Example, image filtered with GHPF transfer
  functions using D0 = 60 in all cases (n = 2 for
  the BHPF) ( first row) and D0 = 160 (second
  row).
                                                45
…cont’d
 As before, we see that the BHPF transfer
  function represents a transition between the
  sharpness of the IHPF and the broad
  smoothness of the GHPF transfer function.
                                             46
            Chapter Five
Image Restoration and Reconstruction
                                       1
5.1 Introduction
 The principal goal of restoration techniques is
  to improve an image.
 Image restoration is an objective process but
  image enhancement is largely a subjective
  process.
 Restoration recover an image that has been
  degraded by using a priori knowledge of the
  degradation phenomenon.
 Restoration      techniques      model     the
  degradation and apply the inverse process in
  order to recover the original image.          2
       5.2 A Model of Image
   Degradation/Restoration Process
 Model image degradation as an operator
  that, together with an additive noise term,
  operates on an input image f(x,y) to produce
  a degraded image g(x,y)
 Given g(x,y), some knowledge about           , and
  some knowledge about the additive noise
  term        , the objective of restoration is to
  obtain an estimate         of the original image.
 The more we know about and the closer
       will be to f (x, y)
                                                   3
Degradation and Restoration
          model
                              4
…cont’d
 If    is a linear, position-invariant operator,
  then the degraded image is given in the
  spatial domain by
  where         is the spatial representation of the
  degradation function.
 The degraded image           is   given   in   the
  Frequency domain by
                                                   5
5.3 Noise Models
 The principal sources of noise in digital
  images arise during image acquisition and/or
  transmission.
 In acquiring images, light levels and sensor
  temperature are major factors affecting the
  amount of noise in the resulting image.
 An image transmitted using a wireless
  network might be corrupted by lightning or
  other atmospheric disturbance.
                                             6
Spatial & Frequency Properties Of
              Noise
 Spatial properties define the spatial
  characteristics of noise, and whether the
  noise is correlated with the image.
 Frequency properties refer to the frequency
  content of noise in the Fourier (frequency)
  domain.
                                            7
     Noise Probability Density
         Functions (PDF)
Gaussian noise model
   The PDF of a Gaussian random variable, z, is
    defined by the following expression:
    where z represents intensity,           is the mean
    value of z, and is its standard deviation.
Rayleigh Noise Model
   The PDF of Rayleigh noise is given by
                                                      8
…cont’d
   The mean and variance of z when this random
    variable is characterized by a Rayleigh PDF
    are
    and
Erlang (Gamma) Noise Model
   The PDF of Erlang noise is
                                              9
…cont’d
     where the parameters are such that a > b , b is a
     positive integer, and “!” indicates factorial. The
     mean and variance of z are
     and
Exponential Noise Model
   The PDF of exponential noise is given by
     where a>0
                                                     10
…cont’d
   The mean and variance of z are
    and
   Note that this PDF is a special case of the
    Erlang PDF with b = 1.
Uniform Noise Model
   The PDF of uniform noise is
                                              11
…cont’d
   The mean and variance of z are
    and
Salt-and-Pepper Noise Model
   The PDF of salt-and-pepper noise is given by
    where V is any integer value in the range
                                                   12
    0<V<Vk−1.
…cont’d
  The mean of salt-and-pepper noise is given by
   and the variance by
                                               13
Some important PDF
                     14
…cont’d
      Test pattern used to illustrate the
      characteristics of the PDFs
                                            15
…cont’d
Images and histograms resulting from adding Gaussian, Rayleigh,
and Erlanga noise to the image                                    16
 5.5 Restoration in the Presence of
               Noise
 When an image is degraded only by additive
  noise
  and
 Spatial filtering is used to estimate f(x,y) [i.e.,
  de-noising image g(x,y)] in situations when
  only additive random noise is present.
                                                    19
                Mean Filters
Arithmetic Mean Filter
   The arithmetic mean filter is the simplest of the
    mean filters
   Let Sxy represent the set of coordinates in a
    rectangular subimage window (neighborhood)
    of size mxn, centered on point (x,y).The
    arithmetic mean filter computes the average
    value of the corrupted image, g(x,y), in the
    area defined by Sxy.
   The value of the restored image fˆ at point
    (x,y) is the arithmetic mean computed using
                                                   20
    the pixels in the region defined by S .
…cont’d
  In other words,
    where, r and c are the row and column
    coordinates of the pixels contained in the
    neighborhood Sxy .
  This operation can be implemented using a
   spatial kernel of size mxn in which all
   coefficients have value 1/mn. A mean filter
   smooths local variations in an image, and
   noise is reduced as a result of blurring.
                                             21
…cont’d
Geometric Mean Filter
   An image restored using a geometric mean
    filter is given by the expression
     where indicates multiplication.
   Here, each restored pixel is given by the
    product of all the pixels in the sub-image area,
    raised to the power 1/mn.
                                                   22
…cont’d
   A geometric mean filter achieves smoothing
    comparable to an arithmetic mean filter, but it
    tends to lose less image detail in the process.
Harmonic Mean Filter
   The harmonic mean filtering operation is given
    by the expression
   The harmonic mean filter works well for salt
    noise, but fails for pepper noise.
   It does well also with other types of noise like
    Gaussian noise.                                23
…cont’d
Contraharmonic Mean Filter
   The contraharmonic mean filter yields a
    restored image based on the expression
    where Q is called the order of the filter.
   This filter is well suited for reducing or
    eliminating the effects of salt-and-pepper
    noise.
                                             24
…cont’d
  For positive values of Q, the filter eliminates
   pepper noise.
  For negative values of Q, it eliminates salt
   noise.
  Note that the contraharmonic filter reduces to
   the arithmetic mean filter if Q = 0, and to the
   harmonic mean filter if Q = −1
                                                 25
Example …
(a) Original image
(b) Image corrupted
by additive
Gaussian noise.
(c) Result of
filtering with
an arithmetic
mean filter of size
3x3 .                 (a)   (b)
(d) Result
of filtering with a
geometric mean
filter of the same
size.
                      (c)   (d)
                                  26
          Order Statistic Filters
 Order-statistic filters are spatial filters whose
  response is based on ordering (ranking) the
  values of the pixels contained in the
  neighborhood encompassed by the filter.
 The ranking result determines the response
  of the filter.
Median Filter
    Median filter replaces the value of a pixel by
     the median of the intensity levels in a
     predefined neighborhood of that pixel:
                                                  27
…cont’d
     where, as before, Sxy       is a subimage
     (neighborhood) centered on point (x,y)
   Median filters provide excellent noise-
    reduction capabilities
Max and Min Filters
   Max filter is given by
                                             28
…cont’d
    This filter is useful for finding the brightest
     points in an image or for eroding dark regions
     adjacent to bright areas. It reduce pepper
     noise.
Min Filter
    The 0th percentile filter is the min filter:
    This filter is useful for finding the darkest
     points in an image or for eroding light regions
     adjacent to dark areas.
    It reduces salt noise.                         29
…cont’d
Midpoint Filter
    The midpoint filter computes the midpoint
     between the maximum and minimum values in
     the area encompassed by the filter:
    It works best for randomly distributed noise,
     like Gaussian or uniform noise
                                                 30
…cont’d
Alpha-Trimmed Mean Filter
   Suppose that we delete the d/2 lowest and the
    d/2 highest intensity values of g(r,c) in the
    neighborhood Sxy . Let gR (r,c) represent the
    remaining mn - d pixels in Sxy .
   A filter formed by averaging these remaining
    pixels is called an alpha-trimmed mean filter.
    The form of this filter is
    where value of d can range from 0 to mn − 1   31
…cont’d
  When d = 0 the alpha-trimmed filter reduces to
   the arithmetic mean filter discussed earlier.
  If we choose d = mn − 1, the filter becomes a
   median filter.
  For other values of d, the alpha-trimmed filter
   is useful in different types of noise, such as a
   combination of salt and-pepper and Gaussian
   noise.
                                                  32
             Adaptive Filters
 The filters discussed so far are applied to an
  image without regarding how image
  characteristics vary from one point to another.
 Adaptive filters are applied to an image by
  considering how image characteristics vary
  from one point to another.
 Adaptive filters are capable of performance
  superior to that of the filters discussed so far.
 There are two types of adaptive filters:
    Adaptive Local Noise Reduction Filter
    Adaptive median filter
                                                  33
 Adaptive, Local Noise Reduction
              Filter
 Adaptive filter bases on mean and variance
  because they are quantities closely related to
  the appearance of an image.
 The mean gives a measure of average
  intensity in the region over which the mean is
  computed, and the variance gives a measure
  of image contrast in that region.
 An adaptive expression for obtaining fˆ(x,y) is
  given by
                                                34
…cont’d
          , the variance of the noise
          , the local average intensity of the pixels in Sxy
         , the local variance of the intensities of pixels in
   Sxy
                                                           35
Adaptive Median Filter
 The adaptive median-filtering algorithm uses
  two processing levels, denoted level A and
  level B, at each point (x,y) :
                                             36
…cont’d
   where
           37
    Chapter Six
Image Compression
                    1
   6.1 Basic Definition of Image
           Compression
 Data compression refers to the process of
  reducing the amount of data required to
  represent a given quantity of information.
 Data are the means by which information is
  conveyed.
 Various amounts of data can be used to
  represent the same amount of information
 Representations that contain irrelevant or
  repeated information are said to contain
  redundant data.
                                           2
…cont’d
 Image compression, the art and science of
  reducing the amount of data required to
  represent an image
 Let b and b′ denote the number of bits in two
  representations of the same information, the
  relative data redundancy, R, of the
  representation with b bits is
                                              3
…cont’d
  where C, commonly called the compression
  ratio, is defined as
 For instance, if C = 10 (sometimes written
  10:1), the larger representation has 10 bits
  of data for every 1 bit of data in the smaller
  representation. The corresponding relative
  data     redundancy        of    the    larger
  representation is 0.9 (R = 0.9), indicating
  that 90% of its data is redundant.
                                               4
6.2 Data Redundancy
 Three forms of data redundancies exist in digital
  images
   Coding Redundancy
   Spatial and Temporal Redundancy
   Irrelevant Information.
                                                5
Coding Redundancy
  A code is a system of symbols (like, letters,
   numbers, bits) used to represent a body of
   information.
  Each piece of information is assigned a
   sequence of code symbols, called a code
   word.
  The number of symbols in each code word is
   its length.
  The 8-bit codes that are used to represent the
   intensities in most 2-D intensity arrays contain
   more bits than are needed to represent the
                                                  6
   intensities.
…cont’d
 Let rk in the interval [0,L – 1] is used to
  represent the intensities of an M*N image,
  and that each rk occurs with probability pr (rk).
   where L is the number of intensity values,
   and nk is the number of times that the kth
   intensity appears in the image.
 If the number of bits used to represent each
  value of rk is lr(k), then the average number of
  bits required to represent each pixel is
                                                  7
…cont’d
 The total number of bits required to represent
  an M*N image is M*N*Lavg.
 If the intensities are represented using a
  natural m-bit fixed-length code, then the total
  number of bits required to represent an M*N
  image is M*N*m                                .
                                                8
 …cont’d
 Example
 Lavg  for code 1 is 8 bits.
 The average length of encoded pixels for code 2
  Lavg = 0.25*2 + 0.47*1 + 0.25*3 + 0.03*3 = 1.81bits
  C = 256*256*8/256*256*1.81 = 4.42
  R = 1 – 1/C = 1-1/4.42 = 0.774  Thus, 77.4% of the
  data in the original 8-bit 2-D intensity array is
  redundant.                                     9
Spatial and Temporal Redundancy
 Because the pixels of most 2-D intensity
  arrays are correlated spatially (i.e., each pixel
  is similar to or dependent upon neighboring
  pixels),    information    is     unnecessarily
  replicated in the representations of the
  correlated pixels.
 In a video sequence, temporally correlated
  pixels (i.e., those similar to or dependent
  upon pixels in nearby frames) also duplicate
  information.
                                                  10
…cont’d
 To reduce the redundancy associated with
  spatially and temporally correlated pixels, a 2-
  D intensity array must be transformed into a
  more efficient representation.
 For example, run-lengths (128:1) or the
  differences between adjacent pixels can be
  used.
 In run-length representation, each run-length
  pair specifies the start of a new intensity and
  the number of consecutive pixels that have
  that intensity.                                11
Irrelevant Information
 Most 2-D intensity arrays contain information
  that is ignored by the human visual system
  and/or extraneous to the intended use of the
  image.
 It is redundant in the sense that it is not used.
                                                  12
…cont’d
(a) coding redundancy, (b) spatial redundancy,   (c) irrelevant information
                                                                        13
    6.3 Elements of Information
             Theory
 A key question in image compression is: “
  what is a minimum amount of data that is
  sufficient to describe an image without losing
  information?”
 How do we measure the information content
  of an image?
   Average information content of an image (the
    intensity source’s entropy) is given by:
                                  units/pixel
                                                14
Example
 It is not possible to code the intensity values
  of the imaginary source (and thus the sample
  image) with fewer than H̃ bits/pixel.
                                                15
Fidelity Criteria
 Since information may be lost during
  compression a means of quantifying the
  information loss is desirable.
 Two types of criteria:
    Objective fidelity criteria
    Subjective fidelity criteria
 Objective fidelity criteria: the information loss
  is expressed as a function of input image
  (original   image)       and     output    image
  (compressed and decompressed)
                                                  16
….cont’d
 The Root-mean-squared (rms) error between
  f(x,y) and fˆ(x,y) is
 The Means-Quared Signal-to-Noise ratio of
  the output image, denoted SNRms, can be
  defined as
                                          17
…cont’d
 Subjective fidelity criteria: measuring image
  quality by the subjective evaluation of a group
  of viewers and averaging their evaluations.
                                                18
  6.4 General Mechanism of Data
          Compression
 An image compression system is composed
  of two distinct functional components: an
  encoder and a decoder.
 The encoder performs compression, and the
  decoder    performs    the   complementary
  operation of decompression.
 A codec is a device or program that is
  capable of both encoding and decoding.
                                           19
…cont’d
Functional block diagram   of   a   general   image
compression system.
                                                 20
   The Encoding or Compression
             Process
 The encoder is designed to remove the data
  redundancies through a series of three
  independent operations.
 In the first stage of the encoding process, a
  mapper transforms f(x,y) into a format
  designed to reduce spatial and temporal
  redundancy. This operation generally is
  reversible, and may or may not directly
  reduce the amount of data required to
  represent the image.
 Example, Run-Length Coding                  21
…cont’d
 The quantizer reduces the accuracy of the
  mapper’s output in accordance with a pre-
  established fidelity criterion. The goal is to
  remove irrelevant information from the
  compressed representation. This operation is
  irreversible.
 In the third and final stage of the encoding
  process, the symbol coder generates a fixed-
  length or variable-length code to represent
  the quantizer output, and maps the output in
  accordance with the code.                    22
…cont’d
 The shortest code words are assigned to the
  most frequently occurring quantizer output
  values, thus minimizing coding redundancy.
  This operation is reversible.
                                            23
 The Decoding or Decompression
            Process
 The decoder contains only two components:
  a symbol decoder and an inverse mapper.
 They perform, in reverse order, the inverse
  operations of the encoder’s symbol encoder
  and mapper.
 Because quantization results in irreversible
  information loss, an inverse quantizer block is
  not included in the general decoder model.
                                                24
6.5 Types of Data Compression
                                25
Huffman Coding
 When coding the symbols of an information
  source individually, Huffman coding yields the
  smallest possible number of code symbols
  per source symbol.
 The first step in Huffman’s approach is to
  create a series of source reductions by
  ordering the probabilities of the symbols
  under consideration, then combining the
  lowest probability symbols into a single
  symbol that replaces them in the next source
  reduction.                                   26
…cont’d
 This process is then repeated until a reduced
  source with two symbols is reached.
          Huffman source reductions.
                                              27
…cont’d
 The second step in Huffman’s procedure is to
  code each reduced source, starting with the
  smallest source and working back to the
  original source. The minimal length binary
  code for a two-symbol source are the
  symbols 0 and 1
 This operation is then repeated for each
  reduced source until the original source is
  reached.
                                             28
…cont’d
         Huffman code assignment procedure.
 The average length of this code is
  and the entropy of the source 2.14 bits/symbol
                                              29
Arithmetic Coding
 In    arithmetic  coding,   a   one-to-one
  correspondence between source symbols
  and code words does not exist.
 Instead, an entire sequence of source
  symbols (or message) is assigned a single
  arithmetic code word.
 The code word itself defines an interval of
  real numbers between 0 and 1
                                            30
…cont’d
 As the number of symbols in the message
  increases, the interval used to represent it
  becomes smaller, and the number of
  information units (say, bits) required to
  represent the interval becomes larger.
 Each symbol of the message reduces the
  size of the interval in accordance with its
  probability of occurrence.
 The output of arithmetic coding is a stream of
  bits.
                                               31
…cont’d
 In order to explain the algorithm number will
  be shown as decimal, but obviously they are
  always binary.
                                                  32
Arithmetic coding example
 A five-symbol sequence or message,
  a1a2a3a3a4, from a four-symbol source is
  coded.
 At the start of the coding process, the
  message is assumed to occupy the entire
  half-open interval [0, 1).
 This interval is subdivided initially into four
  regions based on the probabilities of each
  source symbol.
                                                33
…cont’d
Symbol a1, for example, is associated with subinterval
[0, 0.2). Because it is the first symbol of the message
being coded, the message interval is initially narrowed
to [0, 0.2). Thus, [0, 0.2) is expanded to the full height of
the figure, and its end points labeled by the values of
the narrowed range. The narrowed range is then
subdivided in accordance with the original source
symbol probabilities, and the process continues until all
                                                            34
the symbols are coded.
Arithmetic coding procedure.
     [0.06752, 0.688)  0.068 (a1a2a3a3a4 )
                                          35
Bit Plane Coding
 Bit-plane coding, is based on the concept of
  decomposing a multilevel (monochrome or
  color) image into a series of binary images
  and compressing each binary image
 The intensities of an m-bit monochrome
  image can be represented in the form of the
  base-2 polynomial
                                             36
…cont’d
 Based on this property, a simple method of
  decomposing the image into a collection of
  binary images is to separate the m
  coefficients of the polynomial into m 1-bit bit
  planes.
 The lowest-order bit plane (the plane
  corresponding to the least significant bit) is
  generated by collecting the a0 bits of each
  pixel, while the highest-order bit plane
  contains the am-1 bits or coefficients.
                                                37
 …cont’d
 In general, each bit plane is constructed by setting its
  pixels equal to the values of the appropriate bits or
  polynomial coefficients from each pixel in the original
  image.
 Disadvantages of this approach is that small changes
  in intensity can have a significant impact on the
  complexity of the bit planes.
 E.g., because the most significant bits of the binary
  codes for 127(01111111) and 128(10000000) are
  different, the highest bit plane will contain a zero-
  valued pixel next to a pixel of value 1, creating a 0 to
  1 (or 1 to 0) transition at that point.            38
…
 An alternative decomposition approach
  (which reduces the effect of small intensity
  variations) is to first represent the image by
  an m-bit Gray code.
 The m-bit Gray code gm-1… g2 g1 g0 that
  corresponds to the base-2 polynomial can be
  computed from
                                               39
…cont’d
 This code has the unique property that
  successive code words differ in only one bit
  position.
 Thus, small changes in intensity are less
  likely to affect all m bit planes.
 For instance, when intensity levels 127 and
  128 are adjacent, only the highest-order bit
  plane will contain a 0 to 1 transition, because
  the Gray codes that correspond to 127 and
  128      are     01000000       and  11000000,
  respectively.                                 40
 …cont’d
The four most significant binary and Gray-coded bit planes of the image
                                                                    41
…cont’d
The four least significant binary and Gray-coded bit planes of the image
                                                                     42
    Chapter Seven
Color Image Processing
                         1
Color Fundamentals
 Color is the aspect of things that is caused by
  different qualities of light being reflected or
  emitted by them.
 The characteristics used to distinguish on
  color from another are:
   Hue – refers to primary colors - red, green and
    blue and secondary colors - magenta (red plus
    blue), cyan (green plus blue), and yellow (red
    plus green)
   Brightness – the amount of intensity
   Saturation – the degree of purity of hue      2
…cont’d
 Motivation to use color in image processing :
   Color is a powerful descriptor that simplifies
    object identification and extraction from a
    scene.
   Humans can perceive thousands of color
    shades as opposed to only about two dozen
    shades of gray.
 Color image processing is divided into two
  major areas:
   Full-color processing – image are acquired
    and processed in full color                   3
…cont’d
   Pseudo-color processing – images are by
    nature grayscale and are converted to color
    images for visualization purposes.
 In 1666, Isaac newton discovered that when
  a beam of sunlight passes through a glass
  prism, the emerging beam of light is split into
  a spectrum of colors ranging from violet at
  one end to red at the other.
                                                4
…cont’d
 Three basic quantities used to describe the
  quality of a chromatic light source are:
   Radiance - the total amount of energy that
    flows from the light source
   Luminance - a measure of the amount of
    energy that an observer perceives from a light
    source, and
   Brightness - a subjective descriptor that is
    practically unmeasurable.
                                                 5
…cont’d
 The human eye sees colors as variable
  combinations of primary colors: red (R),
  green (G), and blue (B).
 The primary colors can be added together to
  produce the secondary colors of light—
  magenta (red plus blue), cyan (green plus
  blue), and yellow (red plus green).
 Mixing the three primaries, or a secondary
  with its opposite primary color, in the right
  intensities produces white light.
                                              6
…cont’d
          7
…cont’d
 Hue and saturation taken together are called
  chromaticity
 A color may be characterized by its
  brightness and chromaticity
 The amounts of red, green, and blue needed
  to form any particular color are called the
  tristimulus values, and are denoted, X, Y, and
  Z, respectively.
 A color is then specified by its trichromatic
  coefficients, defined as
                                               8
…cont’d
          9
 7.2 Color Models (color space or
           color system)
 The color model aims to facilitate the
  specification of colors in some standard way.
 In digital image processing, commonly used
  color models are:
     RGB (Red, Green, Blue)
     CMY (Cyan, Magenta, Yellow)
     CMYK (Cyan, Magenta, Yellow, Black)
     HSI (Hue, Saturation, Intensity)
                                              10
The RGB Model
 Each color appears in its primary colors red,
  green and blue.
 This model is based on a Cartesian
  coordinate system.
 All color values R, G, and B are normalized in
  the range [o, 1]
 We can represent each of R, G, and B from 0
  to 255
 Each RGB color image consist of three
  component images, one for each primary
                                               11
  color.
…cont’d
 The number of bits used to represent each
  pixel in RGB space is called the pixel depth.
 24-bit image often referred as full-color image
                                                12
CMY Model
 This model is made up of secondary colors of
  light – Cyan, Magenta and Yellow
 Light reflected from a surface coated with
  pure cyan does not contain red
 Similarly, pure magenta does not reflect
  green, and pure yellow does not reflect blue.
 Therefore,
                                              13
CMYK Model
 CMYK color space is a variation on the CMY
  model.
 It adds black
 When equal components of cyan, magenta
  and yellow inks are mixed the result is usually
  a dark brown not black
 Adding black ink solve problem
                                                14
HSI Model
 When humans view a color object, we
  describe it by its hue, saturation, and
  brightness.
 Hue is a color attribute that describes a pure
  color (pure yellow, orange, or red), whereas
  saturation gives a measure of the degree to
  which a pure color is diluted by white light.
 Brightness is a subjective descriptor that is
  practically impossible to measure.
                                               15
…cont’d
 The HSI (hue, saturation, intensity) color
  model, decouples the intensity component
  from the color-carrying information (hue and
  saturation) in a color image.
 As a result, the HSI model is a useful tool for
  developing image processing algorithms
                                                16
  7.3 Basics of Full-Color Image
            Processing
 Full-color image processing approaches fall
  into two major categories:
   Processing each grayscale component image
    individually, then form a composite color
    image from the individually processed
    components.
   Processing color pixels directly.
 Full-color images have at least three
  components, and hence color pixels are
  vectors.
                                            17
…cont’d
 For example, in the RGB system, each color
  point can be interpreted as a vector extending
  from the origin to that point in the RGB
  coordinate system
 Let c represent an arbitrary vector in RGB
  color space:
 c are the RGB components of a color image
  at a point.
                                               18
…cont’d
 The colors of the pixels in an image are a
  function of spatial coordinates (x, y) by using
  the notation
 For an image of size MxN, there are MN such
  vectors,c(x, y), for x = 0, 1, 2 ,…, M – 1 and
  y = 0,1, 2 , …, N -1 .
                                                19
…cont’d
 The results of individual color component
  processing are not always equivalent to direct
  processing in color vector space.
 In this case we must use approaches for
  processing the elements of color points
  directly.
 We use the terms vectors, points, and voxels
  interchangeably when we are referring to
  images composed of more than one 2-D
  image.
                                               20
…cont’d
 In order for per-component-image and vector-
  based processing to be equivalent, two
  conditions have to be satisfied:
   first, the process has to be applicable to both
    vectors and scalars;
   second, the operation on each component of a
    vector (i.e., each voxel) must be independent
    of the other components.
                                                  21
…cont’d
 Spatial neighborhood processing of grayscale
  and full-color images
          (a)              (b)               22
…cont’d
 In (a), averaging would be done by summing
  the intensities of all the pixels in the 2-D
  neighborhood, then dividing the result by the
  total number of pixels in the neighborhood.
 In (b), averaging would be done by summing
  all the voxels in the 3-D neighborhood, then
  dividing the result by the total number of
  voxels in the neighborhood.
 Each of the three component of the average
  voxel is the sum of the pixels in the single
  image neighborhood centered on that
  location.                                   23
…cont’d
 But the same result would be obtained if the
  averaging were done on the pixels of each
  image, independently, and then the sum of
  the three values were added for each.
 Thus, spatial neighborhood averaging can be
  carried out on a per-component-image or
  directly on RGB image voxels.
                                             24
      7.4 Morphological image
            processing
 Mathematical morphology a tool used for
  extracting image components that are useful
  in the representation and description of
  region shape, such as boundaries, skeletons,
  and the convex hull.
 In image processing, we use morphology with
  two types of sets of pixels: objects and
  structuring elements (SE’s).
   Objects are defined as sets of foreground
    pixels.
                                             25
…cont’d
   Structuring elements can be specified in terms
    of both foreground and background pixels.
 Images are rectangular arrays, and sets in
  general are of arbitrary shape, applications of
  morphology in image processing require that
  sets be embedded in rectangular arrays.
 In forming such arrays, we assign a
  background value to all pixels that are not
  members of object sets.
                                                 26
…cont’d
Left: Objects represented as graphical sets.
Center: Objects embedded in a background to
form a graphical image. Right: Object and
background are digitized to form a digital image
                                               27
…cont’d
 Structuring elements are defined in the same
  manner
 Difference between the way we represent
  digital images and digital structuring
  elements:
   There is a border of background pixels
    surrounding the objects, while there is none in
    the Structuring element.
                                                  28
…cont’d
 The reflection of a set (structuring element)
  Bˆ about its origin, denoted by, is defined as
 If B is a set of points in 2-D, then Bˆ is the set
  of points in B whose (x, y) coordinates have
  been replaced by (-x, -y).
                                                   29
…cont’d
 Structuring elements and their reflections
  about the origin
                                           30
…cont’d
 The translation of a set B by point z = (z1, z2)
  is denoted (B)z , is defined as
 If B is a set of pixels in 2-D, then (B)z is the
  set of pixels in B whose (x, y)coordinates
  have been replaced by (x + z1 , y + z2 )
                                                 31
 For morphological image processing, we
  need a structuring element.
 It is similar to a mask used in spatial
  convolution.
 Morphological operations are defined for two
  images.
 The image being processed is the active
  image, and the second image is called
  (kernel) or (structuring element)
                                             32
…cont’d
 Each structuring element has a prespecified
  shape, which is applied as a filter on the
  active image.
 The active image can be modified by masking
  it with the structuring elements of different
  sizes and shapes.
 The basic operations in mathematical
  morphology are dilation and erosion. These
  two operations can be combined in sequence
  to develop other operations, such as opening
  and closing.                                33
…cont’d
 Dilation operation:
   Given a set A and the structuring element B,
    the dilation of A with B is defined as:
   Generally size of B or B^ is smaller than A. If
    B^ is placed at the boundary of A, then the
    size of A increases to include B^ points. So, all
    the points touching the boundary will be
    included because of the dilation.
                                                   34
…cont’d
  If there is a very small object, say (hole) inside
   the object A, then this unfilled hole inside the
   object is filled up.
  Small disconnected regions outside the
   boundary may be connected by dilation.
  Irregular boundary may also be smoothened
   out by dilation. Dilation is translation invariant.
                                                    35
…cont’d
Low-resolution text showing broken characters (b)
Structuring element. (c) Dilation of (a) by (b). Broken
segments were joined.                                   36
…cont’d
 Erosion operation:
   Erosion of A with B is given by:
   In this operation, the structuring element B
    should be completely inside the object A, and
    that is why the boundary pixels are not
    included.
   Two nearly connected regions will be
    separated by erosion operation.
                                                37
…cont’d
   Any hole inside the object will be increased
    and boundary of an object may be
    smoothened by the erosion operation.
 Dilation and erosion are dual operations in
  the sense that,
 Dilation expands the components of a set and
  erosion shrinks it.
                                               38
…cont’d
 Closing operation:
   The closing of set A by structuring element B,
    is defined as
   Closing tends to smooth sections of contours,
    it generally fuses narrow breaks and long thin
    gulfs, eliminates small holes, and fills gaps in
    the contour.
                                                   39
…cont’d
(a) Image I, composed of set (object) A, and
background. (b) Structuring element B. (c) Translations
of B such that B does not overlap any part of A. (A is
shown dark for clarity.) (d) Closing of A by B.
                                                     40
…cont’d
 Opening Operation
   The opening of set A by structuring element B,
    is defined as
   Opening generally smoothes the contour of an
    object, breaks narrow isthmuses, and
    eliminates thin protrusions.
                                                 41
…
Image I, composed of set (object) A and background.
(b) Structuring element, B. (c) Translations of B while
being contained in A. (A is shown dark for clarity.) (d)
Opening of A by B.                                         42