Kotebe University of
Education
Digital Image Processing
and CV
Mulugeta A.(PhD)
1
Chapter Two
Digital Image Fundamentals
2
Outline
Digital Image Processing Topics
Sampling and Quantization
Image Transforms
3
Sampling and Quantization
In order to become suitable for digital processing,
an image function f(x,y) must be digitized both
spatially and in amplitude.
Typically, a frame grabber or digitizer is used to
sample and quantize the analogue video signal.
Hence in order to create an image which is digital, we
need to covert continuous data into digital form.
There are two steps in which it is done:
Sampling
Quantization
4
Cont.
The sampling rate determines the spatial
resolution of the digitized image, while the
quantization level determines the number
of grey levels in the digitized image.
A magnitude of the sampled image is
expressed as a digital value in image
processing.
The transition between continuous values
of the image function and its digital
equivalent is called quantization.
5
Cont.
The number of quantization levels should be
high enough for human perception of fine
shading details in the image.
The occurrence of false contours is the main
problem in image which has been quantized
with insufficient brightness levels.
Note:
Sampling :- related to coordinates values
Quantization:- related to intensity values
6
2D Sampling: From analogue images to digital
images (pixels)
Sampling of an image is basically sampling of a
The continuous image coordinates (𝑥,𝑦) are
2D signal.
replaced with a set of discrete values.
That means we only observe the image signal at
certain locations.
In the example below two identical images are
sampled at different rates.
Obviously the higher the sampling rate the better
the quality of the image.
After a specific sampling rate the human eye is
not able to perceive an improved image.
7
Cont.
For the image below sampling which yields a
digital image of size 256×256 is efficient so
that the human eye perceives the image as an
analogue one with good quality.
8
Quantization: From continuous image signal to discrete
image signal
of the image signal 𝑓(𝑥,𝑦) (discretization of the
Quantization of an image is basically discretization
image amplitude).
coordinates (𝑥,𝑦) and image values 𝑓(𝑥,𝑦) are
After sampling and quantization both pixel
represented with binary numbers.
Below you see an image quantized in two levels
(binary).
where 𝑓(𝑥,𝑦) is a scalar and represents all shades
For images of the so called gray level type
of the gray color, ranging from the absolute black
256 gray levels for 𝑓(𝑥,𝑦).
(0) to the absolute white (255), we normally use
9
Cont.
The value of 𝑓(𝑥,𝑦) is called the intensity of the image.
Obviously the more
quantization levels we assign to
digital images the better their
quality.
When can we say that an image
is of good quality?
10
Steps to Convert Analog to Digital Media
Sampling: converts a continuous media
(analog signal) into a discrete set of values at
regular space intervals.
Given an analog media, sampling represents a
mapping of the image from a continuum of points
in space to a discrete set.
The samples are continuous and have infinite
number of possible values at every sampled points
(at regular space).
The issue here is deciding the Sampling Rate:
It is the number of samples to be taken from an
analog signal in a given space.
11
Cont.
Quantization
it converts a sampled signal into a signal that can
take only a limited number of values (or bit depth).
The digitization/quantization process approximates
the bit depth with a fixed number of values.
To represent N numbers, we need log2N bits.
• For example, an 8 bit quantization represents 28=256
possible values.
• What about a 16 bit quantization? It handles almost more
than 65, 000 possible values
Degree of Quantization:
What determines the number of bits we need to digitize an
image?
12
Cont.
Compression:
There are probably some further
compression process to reduce file size to
save space.
Compression is minimizing the size in bytes
of a media file without degrading the
quality of multimedia data.
Raw image takes about 6MBs 24KBs with jpeg
(without header information) 13
Examples
a b
c d
Generating a digital image.
(a) Continuous image. (b)
A scaling line from A to B
in the continuous image,
used to illustrate the
concepts of sampling and
quantization. (c) sampling
and quantization. (d)
Digital scan line.
14
Image Transform
Transform
IMAGE ANOTHER IMAGE
NxN NxN
Inverse Transform
Coefficient Matrix
15
Cont.
Image transform is representation of a 2D
signal(image signal holds 2D visual information)
The efficient representation of visual information
lies at the foundation of many image processing
tasks which include image filtering, image
compression and feature extraction.
Efficiency of representation: the ability of capture
significant information of an image in a small
description.
Efficient image transforms are extensively used
in image processing and image analysis
16
Cont.
Transform is basically a mathematical tool
which allow us to move from one domain to
another domain.
Generally time/spatial domain to frequency domain
The reason to migrate from one domain to
another domain is to perform the task at
hand in an easier manner.
The transform is reversible, i.e. we can
revert to the initial domain.
The transform doesn’t change the
information continent present in the signal
17
Cont.
Most of the image transforms like Fourier
transform, discrete cosine transform, wavelet
transform etc give information about the
frequency contents in an image.
Therefore, image transform is defined as
Operations to change the default representation
space of a digital image(spatial domain another
domain), so that all the information present in the
image is preserved in the transformed domain but
represent differently.
18
Need for image transform
Mathematical convenience
Every action in the time domain will have an impact
in the frequency domain
For more image extraction
Note:
Transform theory plays a fundamental role in image
processing, as working with the transform of an
image instead of the image itself may give us more
insight into the properties of the image.
Two-dimensional transforms are applied to image
enhancement, restoration, encoding and description.
19
Cont.
Image processing tasks are best performed in
a domain other than spatial domain.
Key Steps
1. Transform the image
2. Carry the tasks in the transformed domain
3. Apply inverse transform to return to spatial
domain.
20
Varies image transforms
2D Discrete Fourier Transform
Discrete Cosine Transform
Haar Transform
Walsh Transform
Hadamard Transform
Slant Transform
KL Transform
Radon Transform
21
Fourier Transform
An image is spatially varying function f(x,y).
For analyzing spatial variations, one way is to
decompose an image in to a set of orthogonal
functions(fourier functions).
22
THE TWO-DIMENSIONAL FOURIER
TRANSFORM
Why is Fourier Transform Useful
Easier to remove undesirable frequencies
Faster to perform certain operations in the
frequency domain than in the spatial
domain
The transform is independent of signals
23
Discrete Fourier Transform(DFT)
Where K=0,1,……..N-1
24
2D-Discreter Fourier Transform(2D-DFT)
M 1 N1
T (u , v) f ( x, y )e j 2 ( ux / M vy / N )
x 0 y 0
M 1 N1
1
f ( x, y )
MN
T (u, v)e
u 0 v 0
j 2 ( ux / M vy / N )
25
Implementation
We use the numpy.fft.fft2() and fftshift()
functions to transform an image to the
frequency domain.
import numpy as np
import cv2
import matplotlib.pyplot as plt
# Load a grayscale image
img = cv2.imread('image.jpg', cv2.IMREAD_GRAYSCALE)
dft = np.fft.fft2(img)
dft_shift = np.fft.fftshift(dft)
magnitude_spectrum = 20 * np.log(np.abs(dft_shift))
plt.imshow(magnitude_spectrum, cmap='gray')
plt.title("Magnitude Spectrum")
26
plt.show()
Discrete Cosine Transform (DCT)
Transforms an image into frequency components
using cosine waves.
Formula:
Applications: JPEG compression, video compression
(e.g., MPEG).
Implementation
We can use the cv2.dct() function in OpenCV for applying DCT
img = cv2.imread('image.jpg',
cv2.IMREAD_GRAYSCALE)
img_float = np.float32(img) / 255.0
dct = cv2.dct(img_float)
plt.imshow(dct, cmap='gray')
plt.title("DCT of Image")
plt.show()
28
Haar Transform
A simple, fast wavelet transform based on square-
shaped wavelets.
Applications: Progressive image transmission,
wavelet-based compression.
Implementation
This algorithm uses a simple wavelet transform from
the PYWT library
import pywt
img = cv2.imread('image.jpg',
cv2.IMREAD_GRAYSCALE)
coeffs = pywt.dwt2(img, 'haar')
cA, (cH, cV, cD) = coeffs
plt.imshow(cA, cmap='gray')
plt.title("Haar Transform -
Approximation")
30
plt.show()
Walsh Transform
Decomposes signals into square wave functions
(binary-valued).
Applications: Signal processing, error correction,
feature extraction.
Hadamard Transform
Decomposes an image using orthogonal Hadamard
basis functions.
Formula:
Applications: Data compression, error detection.
Slant Transform
Captures directional features, like lines and edges.
Applications: Image compression, edge detection.
Karhunen-Loève Transform (KL Transform or
PCA)
Projects data into a basis maximizing variance (dimensionality
reduction).
Applications: Feature extraction, image compression, noise
reduction.
Radon Transform
Transforms an image into projections; used in
medical imaging.
Formula:
Applications: CT and MRI scans, image reconstruction.
Thank you !!!!
36