Digital Image Processing
ITU 08207 & CSU 08202
Lecture Outline
q   Sampling & Quantization Process
     ○   Sampling
     ○   Quantization
     ○   Representing Digital Image
     ○   Spatial & Intensity Resolution
     ○   Image Interpolation
q   Pixel Relationship
     ○   4-Neighbour pixels
     ○   Diagonal neighbor Pixels
     ○   8-Neighbour pixels
q   Adjacency
                                                                                  2
                             Department of Computing & Communication Technology
Sampling and Quantization
Basic Concepts in Sampling & Quantization
 Sampling and quantization are crucial steps in image processing, where they
 play a significant role in digitizing and representing visual information
Sampling
q   Sampling refers to the process of converting a continuous 2D image
    into a discrete representation by selection of its pixel values at specific
    locations
q   Each sample represents the intensity or color value of the image at a
    particular point
q   In digital imaging, an image is composed of a grid of pixels, where each
    pixel represents a tiny element of the image
                                                                                  3
                             Department of Computing & Communication Technology
Sampling and Quantization
Sampling
 q   The sampling process involves selecting a set of discrete pixel locations
     within the continuous image space and assigning intensity or color
     values to those pixels based on the original image
Quantization
 q   Quantization is a process of transforming a real-valued sampled image
     to one taking only a finite number of distinct values
 q   Under the quantization process, the amplitude values of the image are
     digitized (In simple words, when you are quantizing an image, you are
     dividing a signal into quanta(partitions))
                                                                                 4
                            Department of Computing & Communication Technology
Sampling and Quantization
 q   An image 𝑓 may be continuous with respect to the 𝑥 − and 𝑦 −
     coordinates, and also in amplitude
 q   To convert the continuous image to digital form, the image function 𝑓
     has to be sampled in both coordinates in amplitude
                Digitizing the coordinate values is called sampling
               and Digitizing the amplitude(intensity or brightness
                    or grey level) values is called quantization
                                                                                 5
                            Department of Computing & Communication Technology
Sampling and Quantization
                                                 A plot of amplitude [intensity
   Continuous Image that                        level] values of the continuous
    needs to be Digitized                      image along the line segment AB
                            The random variations are due to image noise
                                                                                  6
                       Department of Computing & Communication Technology
Sampling and Quantization
q   To sample the image function, we
    take equally spaced samples along
    line AB
q   The spatial location of each sample
    is indicated by a vertical tick mark in
    the bottom part of the figure
q   The samples are shown as small
    white squares superimposed on the
    function
q   The set of these discrete locations
    gives the sampled function
                                            § The right side of the Figure shows the
q   To form a digital function, the
                                              intensity scale divided into eight
    intensity values also must be             discrete intervals, ranging from black to
    converted (quantized) into discrete       white
    quantities                              § The vertical tick marks indicate the
                                                       specific value assigned to each of the
                                                       eight intensity intervals
                                                                                                7
                               Department of Computing & Communication Technology
Sampling and Quantization
 q   The continuous intensity levels are
     quantized by assigning one of the
     eight values to each sample
 q   The assignment is made depending
     on the vertical proximity of a sample
     to a vertical tick mark
 q   The digital samples resulting from
     both sampling and quantization are
     shown in the figure
 q   Starting at the top of the image and
     carrying out this procedure line by
     line produces a two-dimensional
                                                                 Digital samples from the
     digital image                                              Sampling and Quantization
                                                                          process
                                                                                            8
                            Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
 q   Let         represent a continuous image function of two continuous
     variables, s and t
 q   Converting this continuous function into a digital image, the process of
     sampling and quantization is applied
 q   Suppose that we sample the continuous image into a 2-D array,
     containing M-rows and N-columns, where            are discrete
     coordinates
 q   For notational clarity and convenience, integer values are used for
     these discrete coordinates:
                                                                                 9
                            Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
 q   Thus, for example, the value of the digital image at the origin is      ,
     and the next coordinate value along the first row is
 q   Here, the notation (0, 1) is used to signify the second sample along the
     first row
 q   In general, the value of the image at any coordinates (x, y) is denoted
     as        , where x and y are integers
 q   The section of the real plane covered by the coordinates of an image is
     called the spatial domain, with x and y being referred to as spatial
     variables or spatial coordinates
 q   There are three basic ways to represent
                                                                                  10
                             Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
                             § The first representation is a plot of the function, with
                               two axes determining the spatial location and the third
                               axis being the values of “f” (intensities) as a function of
                               the two spatial variables x and y
                             § This representation is useful when working with gray-
                               scale sets whose elements are expressed as triplets of
                               the form           where x and y are spatial coordinates
                               and “z” is the value of “f” at coordinates (x, y)
                      § The second representation is much more common
                      § It shows f(x, y) as it would appear on a monitor or
                        photograph. Here, the intensity of each point is proportional
                        to the value of “f” at that point
                      § In the second figure, there are only three equally spaced
                        intensity values
                      § If the intensity is normalized to the interval [0, 1], then each
                        point in the image has the value 0, 0.5, or 1
                                                                                             11
                          Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
                     From the second representation, a monitor or printer
                     simply converts these three values to black, gray, or white,
                     respectively
                                             § The third representation is simply to
                                               display the numerical values of f(x, y) as an
                                               array (matrix)
                                             § This is the representation used for
                                               computer processing
                                             § When developing algorithms, this
                                               representation is more useful
                                             § The second & third representation are
                                               most useful compared to the first one
                                                                                               12
                          Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
    Numerical arrays are used for processing and algorithm development, In
    equation form, the numerical values are represented by M x N numerical
    array as
    Both sides of the above equation are equivalent ways of expressing a
    digital image quantitatively. The right side is a matrix of real numbers.
    Each element of this matrix is called an image element, picture element,
    or pixel
                                                                                13
                           Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
    Sometimes a more traditional matrix notation is used to represent a digital
    image and its elements
                                                                                  14
                             Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
 q   Note that the origin of a digital image is at the top left, with the positive
     x-axis extending downward and the positive y-axis extending to the
     right
 q   This is a conventional representation based on the fact that many
     image displays (e.g., TV monitors) sweep an image starting at the top
     left and moving to the right one row at a time
 q   More important is the fact that the first element of a matrix is by
     convention at the top left of the array, so choosing the origin of f(x, y)
     at that point makes sense mathematically
 q   This representation is the standard right-handed Cartesian coordinate
     system
 q   The axes are simply shown pointing downward and to the right, instead
     of to the right and up
                                                                                     15
                              Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
§ Expressing sampling and quantization in more formal mathematical terms can
  be useful
§ Let Z and R denote the set of integers and the set of real numbers,
  respectively
§ The sampling process is viewed as partitioning the                into a grid, with
  the coordinates of the center of each cell in the grid being a pair of elements
  from the Cartesian product 𝑍 ! , which is the set of all ordered pairs of elements
  (𝑍" , 𝑍# ), with 𝑍" and 𝑍# being integers from 𝑍
§ 𝑓(𝑥, 𝑦) is a digital image if (𝑥, 𝑦) are integers from 𝑍 ! and 𝑓 is a function that
  assigns an intensity value (that is, a real number from the set of real numbers,
  𝑅) to each distinct pair of coordinates (𝑥, 𝑦)
§ This functional assignment is the quantization process. If the intensity levels are
  integers, then Z replaces R, and a digital image then becomes a 2-D function
  whose coordinates and amplitude values are integers                                   16
                               Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
§ The digitization process requires that decisions be made regarding the values
  for M, N, and for the number, L, of discrete intensity levels
§ There are no restrictions placed on M and N, other than they have to be
  positive integers
§ Due to storage and quantizing hardware considerations, the number of
  intensity levels is an integer power of 2
§ The assumption is made that the discrete levels are equally spaced and that
  they are integers in the interval [0, L - 1]
§ The number, b, of bits required to store a digitized image, is
§ When M = N, this equation becomes
                                                                                  17
                             Department of Computing & Communication Technology
Sampling and Quantization
Representing Digital Image
When an image can have 2$ intensity levels, it is common practice to refer to
the image as a “k-bit image.” For example, an image with 256 possible
discrete intensity values is called an 8-bit image
          The number of bits required to store square images with
                        various values of N and k
                                                                                  18
                             Department of Computing & Communication Technology
Sampling and Quantization
Spatial and Intensity Resolution
  Spatial resolution and intensity resolution are two concepts that
  characterize the quality and detail of an image. A balance between these
  two factors needs to be considered based on the specific requirements of
  the image-processing task
Spatial Resolution
 Ø Spatial resolution refers to the level of detail or the ability to distinguish
   features in an image
 Ø It relates to the number of pixels used to represent the image and the physical
   size of each pixel
 Ø A higher spatial resolution means more pixels are used, resulting in finer
   details and a clearer representation of the image
                                                                                     19
                               Department of Computing & Communication Technology
Sampling and Quantization
Spatial Resolution
 Ø Spatial resolution is expressed in terms of the number of dots (pixels) per unit
   length, such as dots (pixels) per inch (PPI) or pixels per centimeter (PPCM)
 Ø Higher spatial resolution is desirable in applications where fine details need to
   be preserved, such as medical imaging, satellite imagery, or digital microscopy
                                                                                       20
                              Department of Computing & Communication Technology
Sampling and Quantization
Intensity Resolution
 Ø Intensity resolution (gray level resolution or bit depth) is the number of distinct
   intensity levels that can be assigned to each pixel in an image
 Ø It represents the ability to characterize variations in brightness or color in an
   image
 Ø Intensity resolution is determined by the number of bits used to represent each
   pixel's intensity value
 Ø For grayscale images, the intensity resolution determines the number of shades
   of gray that can be distinguished, For example, an 8-bit image has 256 distinct
   intensity levels (𝐿 = 2$ = 2% ), allowing for fine shifts between black and white
 Ø The most common number is 8 bits, with 16 bits being used in some applications
   in which enhancement of specific intensity ranges is necessary
                                                                                         21
                                Department of Computing & Communication Technology
Sampling and Quantization
Intensity Resolution
 Ø Higher intensity resolution enables the representation of smoother transitions
   and more refined variations in intensity
 Ø In color images, intensity resolution is applied to each color channel (e.g., red,
   green, and blue), and the overall color resolution is influenced by the intensity
   resolutions of those channels
 Ø Increasing the intensity resolution can enhance the visual quality of an image,
   especially in applications that require accurate representation of color or shading,
   such as digital photography or professional graphics
 Ø However, it's important to note that the available intensity resolution is limited by
   the capabilities of the image sensor or the color space being used
                                                                                           22
                                Department of Computing & Communication Technology
Sampling and Quantization
Illustration of effect of Reducing Spatial Resolution
The figures show the effects of reducing spatial resolution in an image. The images in
Figs (a) through (d) are shown in 1250, 300, 150, and 72 dpi, respectively. The lower -
resolution images are smaller than the original. For example, the original image is of
size 3692 * 2812 pixels, but the 72 dpi image is an array of size 213 * 162. To facilitate
comparisons, all the smaller images were zoomed back to the original size.
                                                               (a)                   (b)
 There are some small visual differences
 between Figs (a) and (b), the most notable
 being a slight distortion in the large black
 needle. For the most part, however, Fig (b) is
 acceptable, Figure (c) begins to show visible                 (c)                   (d)
 degradation (see, for example, the small
 needle pointing to 60 on the right side).
 Figure (d) shows degradation that is visible in
 most features of the image.
                                                                                           23
                                Department of Computing & Communication Technology
Sampling and Quantization
Image Interpolation
 Ø Image interpolation is a technique used to estimate the values of pixels in
   a digital image at locations where they are not explicitly defined
   (interpolation is the process of using known data to estimate values at
   unknown locations)
 Ø Interpolation is commonly used when resizing or resampling images, as
   well as in various image-processing tasks (zooming, shrinking, rotating,
   and geometric corrections)
 Ø When an image is scaled up (enlarged) or scaled down (reduced) in size,
   the number of pixels changes, resulting in a change in the image's spatial
   resolution
 Ø Interpolation helps to estimate the intensity or color values of the new
   pixels that are introduced during the resizing process
                                                                                  24
                             Department of Computing & Communication Technology
Sampling and Quantization
Image Interpolation
 When performing image interpolation, the goal is to create a smoother or
 higher-resolution version of the original image by estimating the values of
 the missing pixels
 The interpolation algorithm analyzes the neighboring pixels and uses
 mathematical techniques to determine the most plausible values for the
 new pixels
 Three most common Interpolation Method
Nearest Neighbour Interpolation
 This method assigns the value of the nearest pixel to the new pixel. It is
 the simplest form of interpolation and provides a fast computation
                                                                                 25
                            Department of Computing & Communication Technology
Sampling and Quantization
Image Interpolation
Nearest Neighbour Interpolation
q If an image of size 500 x 500 pixels has to be enlarged 1.5 times to 750 x
  750 pixels. A simple way to visualize zooming is to create an imaginary 750
  x 750 grid with the same pixel spacing as the original, and then shrink it so
  that it fits exactly over the original image
q To perform an intensity-level assignment for any point in the overlay, we
  look for its closest pixel in the original image and assign the intensity of that
  pixel to the new pixel in the 750 x 750 grid. When finished assigning
  intensities to all the points in the overlay grid, the image is expanded to the
  original specified size to obtain the zoomed image.
q This approach is simple but, it produces undesirable artifacts, such as
  severe distortion of straight edges, so it is not much used in practice
                                                                                      26
                             Department of Computing & Communication Technology
Sampling and Quantization
Bilinear Interpolation
Ø Bilinear interpolation considers the values of the four nearest pixels (forming
  a square) surrounding the new pixel
Ø It calculates a weighted average of these pixels based on their distances
  from the new pixel
Ø Bilinear interpolation produces smoother results compared to nearest-
  neighbor interpolation and is widely used in image rescaling
     Let (x, y) denote the coordinates of the location to which we want
     to assign an intensity value (a point of the grid), and let v(x, y)
     denote that intensity value. For bilinear interpolation, the
     assigned value is obtained using the equation
                                                                                 27
                            Department of Computing & Communication Technology
Sampling and Quantization
Bilinear Interpolation
 Ø From the equation above, the four coefficients (a, b, c, and d) are
   determined from the four equations in four unknowns that can be written
   using the four nearest neighbors of point (x, y)
 Ø bilinear interpolation gives much better results than nearest neighbor
   interpolation, with a modest increase in computational burden
Bicubic Interpolation
 Bicubic interpolation is a more sophisticated method that takes into account
 the values and positions of 16 neighboring pixels (forming a 4x4 square)
 around the new pixel
                                                                                  28
                             Department of Computing & Communication Technology
Sampling and Quantization
Bicubic Interpolation
It uses a weighted average based on the distances to these pixels, resulting
in smoother and more detailed output
Bicubic interpolation is commonly used for high-quality image resizing and is
the default interpolation method in image editing software such as Adobe
Photoshop and Corel Photopaint since it preserves fine image details
compared to bilinear interpolation
   The intensity value assigned to point (x, y) is obtained using the equation
     Where the sixteen coefficients are determined from the sixteen
     equations in sixteen unknowns that can be written using the sixteen
     nearest neighbors of point (x, y)
                                                                                  29
                             Department of Computing & Communication Technology
Pixel Relationship
Neighbours of a Pixel
 A pixel p at coordinates (x, y) has four horizontal and vertical neighbors
 whose coordinates are given by
                                                                                  30
                             Department of Computing & Communication Technology
Pixel Relationship
Neighbours of a Pixel
The four diagonal neighbors of p have coordinates
                                 § The diagonal neighbors are denoted by 𝑁! (𝑝)
                                 § These points, together with the 4-neighbors, are
                                   called the 8-neighbors of p, denoted by 𝑁" (𝑝)
                                                                                      31
                           Department of Computing & Communication Technology
Pixel Relationship
Adjacents, Connectivity, Regions, and Boundaries
Adjacency
 Ø Adjacency refers to the relationship between pixels or image
   elements that are spatially connected or neighboring each other
 Ø Adjacency is a fundamental concept used in various image
   processing operations, such as image segmentation, edge
   detection, and morphological operations
                                                                              32
                         Department of Computing & Communication Technology
Pixel Relationship
Adjacents, Connectivity, Regions, and Boundaries
Adjacency
v Let V be the set of intensity values used to define adjacency
v In a binary image, V = {1} if we are referring to the adjacency
  of pixels with a value of 1
v In a gray-scale image, the set V contains more elements
v For example, in the adjacency of pixels with a range of
  possible intensity values 0 to 255, set V could be any subset
  of these 256 values
Three Types of Adjacency
                                                                             33
                        Department of Computing & Communication Technology
Pixel Relationship
Adjacents, Connectivity, Regions, and Boundaries
Three Types of Adjacency
2:
                                                                           34
                      Department of Computing & Communication Technology
Pixel Relationship
Adjacents, Connectivity, Regions, and Boundaries
Three Types of Adjacency
3:
     i)    q is in 𝑁#(𝑝), or
     ii)   q is in 𝑁! (𝑝) and the set 𝑁# 𝑝 ∩ 𝑁#(𝑞)N4(p) has no pixels
            whose values are from V
                                                                                    35
                               Department of Computing & Communication Technology