0% found this document useful (0 votes)
4 views118 pages

DIP-Week 1 Introduction and Image Fundamentals

DIP BASICS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views118 pages

DIP-Week 1 Introduction and Image Fundamentals

DIP BASICS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 118

SS050383: Digital Image Processing

Spring 2025

Dr. Odai Al Soad (拉和)

School of Measurement and Control Technology


and Communication Engineering
Harbin University of Science and Technology

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 1


Contact Information

Instructor: Dr. Odai Al Soad (拉和)


Email: [email protected]
Office: Main Building E0726 (West Campus)

Office Hours: By appointment

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 2


Now, tell me about yourself!

• Name
• Major
• Research interest
• Why do you take this course

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 3


This Course

This course
• It will involve a fair amount of math
– calculus, linear algebra, geometry
– probability
– analog/digital signal processing
– graph theory etc.
– Programming skills with matlab, Python, or C++

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 4


Textbook

Required:
Digital Image Processing, Rafael C.
Gonzalez and Richard E. Woods, 4th
Edition, Global Edition

We will cover many topics in this text


book

We will also include special topics on


recent progresses on image
processing

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 5


Final Course Exam

Final grade will be as:-

Attendance 10%+Seminar 10%+Final Exam 80%

Final Exam will be held on :- 2025-07-07 Monday

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 6


Major Topics Covered in Class

Image acquisition and digital image representation


Image enhancement
Image restoration
Color image processing
Image compression
Image segmentation

Morphological image processing


Special topics on recent progresses on digital image
processing

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 7


Introduction
to DIP

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 8


EM spectrum

• Limited vs entire EM spectrum


Energy of one photon (electron volts)
10-1 10-2 10-3 10-4 10-5 10-6 10-7 10-8 10-9 Wavelength
106 105 104 103 102 101 1 Band Name Characteristics
(Mm)
No. and Uses
Frequency (Hz)
1021 1020 1019 1018 1017 1016 1015 1014 1013 1012 1011 1010 109 108 107 106 105 1 Visible blue 0.45– 0.52 Maximum water
penetration
Wavelength (meters) 2 Visible 0.53– 0.61 Measures plant
10-12 10-11 10-10 10-9 10-8 10-7 10-6 10-5 10-4 10-3 10-2 10 -1 1 101
102
103 green vigor
3 Visible red 0.63– 0.69 Vegetation
discrimination
4 Near 0.78– 0.90 Biomass and
Gamma rays X-rays Ultraviolet Infrared Microwaves Radio waves infrared shoreline mapping
5 Middle 1.55–1.75 Moisture content:
Visible spectrum
infrared soil/vegetation
6 Thermal 10.4–12.5 Soil moisture;
infrared thermal mapping
7 Short-wave 2.09–2.35 Mineral mapping
infrared

0.4 X 10-6 0.5 X 10-6 0.6 X 10-6 0.7 X 10-6


Ultraviolet Violet Blue Green Yellow Orange Red Infrared TABLE 1.1
Thematic bands of NASA’s LANDSAT satellite.

FIGURE 2.10 The electromagnetic spectrum. The visible spectrum is shown zoomed to facilitate explanations,
but note that it encompasses a very narrow range of the total EM spectrum.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 9


Image Processing  Image Analysis

Image acquisition

Low level Image enhancement


Image compression Image processing
Image segmentation
Mid level
Object recognition
Image analysis
Scene understanding
(Computer vision,
High level
Semantics Pattern recognition, etc.)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 10


Image Processing System

Network

Image displays Computer Mass storage

Specialized
Hardcopy image processing Image processing
hardware software

FIGURE 1.24
Components of a general-
purpose image processing
system. Image sensors

Problem
domain

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 11


Image Representation

0 Black / White along axis 1

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 12


Image Enhancement

Image enhancement: This involves improving the visual quality of an


image, such as increasing contrast, reducing noise, and removing
artifacts.

Histogram
equalization

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 13


Image Restoration

Image restoration: This involves removing degradation from an image,


such as blurring, noise, and distortion.

Original image Blurred Restored by Wiener


filter

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 14


Image Compression

Image compression: This involves generating new images or


compressing existing images to reduce storage and transmission
requirements.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 15


Image Segmentation

Image segmentation: This involves dividing an image into regions or


segments, each of which corresponds to a specific object or feature in
the image.

“Rice” image Edges detected using Canny


filter
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 16
Image Completion

Interactively select objects. Remove them and automatically


fill with similar background (from the same image)

I. Drori, D. Cohen-Or, H. Yeshurun, SIGGRPAH’03

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 17


More Examples

Watermarking

Original image Watermarked


image

Generate
watermark

Hidden message

Secret key

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 18


Morphological Image Processing

MORPHOLOGICAL PROCESSING: It deals with tools for extracting


image components that are useful in the representation & description
of shape.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 19


Object Detection / Recognition

OBJECT DETECTION AND RECOGNITION-It is a process that


assigns a label to an object based on its descriptor.

Biometrics

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 20


Applications of Digital Image Processing

Digital camera
Photoshop
Human computer interaction
Medical imaging for diagnosis and treatment
Surveillance

Automatic driving

Fast-growing market!

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 21


Examples

1. Brain MRI 2. Cardiac CT 3. Fetus Ultrasound

5. IR image
1 and 3. http://en.wikipedia.org
2. http://radiology.rsna.org
4. http://emap-int.com
5. http://www.imaging1.com

4. Satellite image
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 22
Image Pipeline

Camera + Scanner  Digital Camera: Get images into computer

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 23


Digital Image Fundamentals

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 24


Elements of Human Visual Perception

Human visual perception plays a


key role in selecting a technique
Lens and Cornea: focusing on the
objects
Visual axis

Two receptors in the retina:


• Cones and rods
• Cones located in fovea and are
highly sensitive to color
• Rods give a general overall
picture of view, are insensitive http://www.mydr.com.au/eye-health/eye-anatomy

to color and are sensitive to low


level of illumination

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 25


Distribution of Rods and Cones in the Retina

180,000
Blind spot
Cones
Rods
No. of rods or cones per mm2

135,000
FIGURE 2.2
Distribution of rods and
cones in the retina. 90,000

45,000

80° 60° 40° 20° 0° 20° 40° 60° 80°


Degrees from visual axis (center of fovea)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 26


Image Formation in the Eye

Image is upside down in the retina/imaging plane!

Adjust focus length


• Camera
• Human eye

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 27


Brightness Adaptation: Subjective Brightness

Scotopic:
• Vision under low illumination
• rod cells are dominant

Photopic:
• Vision under good illumination

• cone cells are dominant

The total range of distinct


intensity levels the eye can
discriminate simultaneously
is rather small
Brightness adaptation level
Lambert

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 28


Brightness Discrimination

Weber Ratio/Fraction
Additional
∆I c light source

I
I + ∆ Short-duration flash
Small ratio: good brightness
discrimination
FIGURE 2.5
An opaque glass
Large ratio: poor brightness Basic experimental
discrimination setup used to
characterize
brightness
discrimination.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 29


Brightness Discrimination at Different
Intensity Levels

rod

cone
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 30
Intensity

 Perceived Intensity is Not a


Simple Function of the Actual
Intensity

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 31


Simultaneous Contrast

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 32


Optical Illusions: Complexity of Human Vision

a b
c d
FIGURE 2.9 Some well-known
optical illusions.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 33


More Optical Illusions

http://www.123opticalillusions.com/ http://brainden.com/optical-illusions.htm

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 34


Relation Among Wavelength, Frequency and
Energy

wavelength ( λ ), frequency (v), and energy (E)


c
λ = , c = 2.998×108 m/s is the speed of light
v
E = hv, h is the Planck's constant, 6.626068×10 -34 m 2 kg / s

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 35


Lens Parameters
Image plane

f
P
d F
FOV
O

p
S1 S2

Thin lens theory: • Increasing the distance from the object to the lens
will reduce the size of image
•Large focus length will give a small FOV
FOV • d is the dimensions of the Lens
• f is the focal length
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 36
Airy disk

What size of the object you can “see”? Diffraction-limit.

Airy disk: the size is proportional to


wavelength and f-number (focal length/lens
dimension)
𝒇𝒇
~𝝀𝝀
𝒅𝒅
http://en.wikipedia.org/wiki/Airy_disc

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 37


Depth of Field & Out of Focus

• Depth of Field (DOF) is inversely


proportional to the focus length
• DOF is proportional to S1

http://www.azuswebworks.com/photography/dof.html
Image plane
P1 P P2
F
O p1
p
p2
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 38
What Do We Do With All Of This Visual
Information??

“Bottom up processing”
Scenes
• Data-driven
Top-down
• Sensation reaches brain,
and then brain makes
sense of it Objects

“Top down processing”


• Cognitive functions informs Groups of
our sensation Features
• E.g., walking to refrigerator
in middle of night
Bottom-up Features

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 39


Image Acquisition and Representation
 When photons strike, electron-
hole pairs are generated on
sensor sites.
 Electrons generated are
collected over a certain period
of time.
 The number of electrons are
converted to pixel values.
(Pixel is short for picture
element.)

Image acquisition: This involves capturing an image


using a digital camera or scanner, or importing an
existing image into a computer

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 40


Image Acquisition and Representation

Two types of sampling and quantization:


1. There are finite number of pixels. (Spatial resolution)
2. The amplitude of pixel is represented by a finite number of bits. (Gray-scale
resolution)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 41


Image Sampling and Quantization

Sampling: Digitalizing the coordinate values (usually determined by


sensors)
Quantization: Digitalizing the amplitude values

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 42


Image Representation

Discrete representation of images


• we’ll carve up image into a rectangular grid of pixels P[x,y]
• each pixel p will store an intensity value in [0 - 1]
• 0  black; 1  white; in-between  gray
• Image size MxN (M,N) pixels

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 43


Matrix Image Representation

A digital image can be written as a matrix


 f (0, 0) f (0,1)  f (0, N − 1)   x[0, 0] x[0,1]  x[0, N − 1] 
 f (1, 0) f (1, N − 1)   x[1, 0]
f (1,1)  x[1,1]  x[1, N − 1] 
f ( x, y ) =  x[n1 , n2 ] = 
           
   
 f ( M − 1, 0)   f ( M − 1, N − 1)  MxN  x[ M − 1, 0]   x[ M − 1, N − 1] MxN

35 45 20 
 43 64 52 
 
10 29 39 

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 44


Color Image

Red Green Blue


(1,0,0) (0,1,0) (0,0,1)
0.6
0.0
+
0.8

0 Colors along Red axis 1


xR [n1 , n2 ]
xG [n1 , n2 ]
xB [n1 , n2 ]
RGB
channels

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 45


Video: Frame by Frame

30 frames/second

x[n1 , n2 , n3 ]
n1 = vertical position
n2 = horizontal position
n3 = frame number
Representing Digital Images
a f(x, y)
b c
FIGURE 2.18
(a) Image plotted
as a surface.
(b) Image displayed
as a visual intensity
array. (c) Image
shown as a 2-D nu-
merical array. (The
numbers 0, .5, and
1 represent black, y
gray, and white, x
respectively.)

Origin
y 0 0 0 0 0 0 0
0 0 0 0 0 0
0 0
0 0 .5 .5 .5
0 0 .5 .5
0 .5 1 1 1
1
1 .5

Dr. Odai Al Soad x DIP-Lect1-Intro & Imag. Fundamentals 47


Representing Digital Images

An digital image = a 2D function f(x,y) where


• x and y are spatial coordinates
• f(x,y) is the intensity or gray level
• x, y, and f(x,y) are all finite

• For example x ∈{1,2,, M }


, y ∈{1,2, ….,N }
f (x, y) ∈{0,1,2,,255}

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 48


Store an Image

 Number of intensity levels L = 2ᵏ ,where k is an integral No.


 Number of bits storing the image k=8
100
90 7

b = M ×N ×k 80 6

* 106 )
70
5
60

8
b
Megabytes (
4
50
When M = N, this equation becomes 40 3
30 2
20
→ b = N² k 10
1

0
0 1 2 3 4 5 6 7 8 9 10 * 103
FIGURE 2.21 N
Number of megabytes required to store images
for various values of N and k.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 49


Store an Image

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 50


LINEAR VS. COORDINATE INDEXING

• The coordinate indices for a given linear index value α are given by

x = α mod M , and y = (α-x) / M


Recall that α mod M means “the remainder of the division of α by M.”
(0, 1) α = M
(0, 0) α = 0 (0, 2) α = 2M FIGURE 2.22
y
Illustration of column scanning for
generating linear indices. Shown are
several 2-D coordinates (in
parentheses) and their corresponding
linear indices.

Image
Image f(x, y)
(M - 1, 0) α = M - 1 (M - 1, N - 1) α = MN - 1
(M - 1, 1) α = 2M - 1
Dr. Odai Al Soad x DIP-Lect1-Intro & Imag. Fundamentals 51
Spatial Resolution

Spatial resolution: smallest discernible details


• No. of line pairs per unit distance
• No. of dots (pixels) per unit distance

Large image size itself does not mean high


spatial resolution!
Scene/object size in the image

1280*960

http://www.shimanodealer.com/fishing_reports.htm
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 52
Intensity Resolution

256 128 64 32

16 8 4 2
• Smallest discernible change in intensity levels
• Using the number of levels of intensities
• False contouring (banding) when k is small - undersampling
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 53
Isopreference Curves

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 54


Image Resampling & Interpolation

Need to resample the image when


• Rescaling
• Geometrical transformation
• The output image coordinates
are not discrete
Interpolation methods:
• Nearest neighbor
• Fast and simple
• Loss of sharpness
• Artifacts (checkerboard)
• Bilinear
• Bicubic
• Images are sharpest
• Fine details are preserved
• Slow

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 55


Image Interpolation – Nearest Neighbor

http://www.brockmann-consult.de/beam/doc/help/general/ResamplingMethods.html

Assign each pixel in the output image with the nearest neighbor in the input image.
(It assigns to each new location the intensity of its nearest neighbor in the original
Image)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 56


Image Interpolation – Bilinear

Bilinear Interpolation
v(x, y) = ax + by + cxy + d

Bicubic Interpolation

 In which we use the four nearest neighbors to estimate the intensity at a


given location.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 57


Adjacency

Adjacency is the relationship between two pixels p and q


V is a set of intensity values used to define adjacency

• Binary image: V={1} or V={0}


• Gray level image:
Intensity
constraints
Three types of adjacency:
4-adjacency 8-adjacency m-adjacency

p X

and
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 58
Neighborhood Operations

Neighbors of a pixel
(x-1,y) (x-1,y-1) (x-1,y+1)

(x,y-1) (x,y) (x,y+1) (x,y)

(x+1,y) (x-1,y+1) (x+1,y+1)

(x-1,y-1) (x-1,y) (x-1,y+1)

(x,y-1) (x,y) (x,y+1)

(x-1,y+1) (x+1,y) (x+1,y+1)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 59


Connectivity

• Path from p to q: a sequence of distinct and adjacent pixels with


coordinates

Starting point p ending point q


adjacent

• Closed path: if the starting point is the same as the ending point
• p and q are connected: if there is a path from p to q in S
• Connected component: all the pixels in S connected to p
• Connected set: S has only one connected component
Are they connected sets? q

4-adjacency: No 8-adjacency: Yes m-adjacency: Yes


Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 60
Regions

• R is a region if R is a connected set


• Ri and Rj are adjacent if is a connected set

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 61


Boundaries

• Inner boundary (boundary) -- the set of pixels each of which


has at least one background neighbor
• Outer boundary – the boundary pixels in the background

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 62


Distance Measures

For pixels p, q, and z, with coordinates (x,y), (u,v) and (w,z),


D is a distance function or metric if
(a) D(p,q) ≥ 0 (D(p,q) = 0 if p = q) ,
(b) D(p,q) = D(q, p), and
(c) D(p, s) ≤ D(p, q) + D(q, s).

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 63


Distance Measures

Euclidean distance

De ( p, q) = (x − u)2 + ( y − v)2

City-block (D4) distance D4 (p,q) = 1 are


the 4-neighbors
of the pixel at (x,
D4 ( p, q) =| x − u | + | y − v | y).

D8= 1 are the


Chessboard (D8) distance (Chebyshev distance) 8-neighbors
of the pixel at
D8 ( p, q) = max(| x − u |,| y − v |) (x, y).

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 64


Distance: Example

D4 distance p
M

6
D8 distance

q
Euclidean distance
𝟏𝟏 + 𝟓𝟓𝟐𝟐

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 65


Mathematic Tools

Array/Matrix operations
Linear/nonlinear operations
Linearity:
Arithmetic Operations – single pixel operations
• Image averaging, image subtraction, image multiplication
Set and logic operations
Spatial operations
• Single pixel operations and neighborhood operations
Image transformation
Probabilistic methods

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 66


Mathematic Tools

Array versus Matrix operations


Array Multiplications
𝒂𝒂𝟏𝟏𝟏𝟏 𝒂𝒂𝟏𝟏𝟐𝟐 ∙ 𝒃𝒃𝟏𝟏𝟏𝟏 𝒃𝒃𝟏𝟏𝟐𝟐
=
𝒂𝒂𝟏𝟏𝟏𝟏𝒃𝒃𝟏𝟏𝟏𝟏 𝒂𝒂𝟏𝟏𝟐𝟐𝒃𝒃𝟏𝟏𝟐𝟐
𝒂𝒂𝟐𝟐𝟏𝟏 𝒂𝒂𝟐𝟐𝟐𝟐 𝒃𝒃𝟐𝟐𝟏𝟏 𝒃𝒃𝟐𝟐𝟐𝟐 𝒂𝒂𝟐𝟐𝟏𝟏𝒃𝒃𝟐𝟐𝟏𝟏 𝒂𝒂𝟐𝟐𝟐𝟐𝒃𝒃𝟐𝟐𝟐𝟐
Matrix Multiplications

𝒂𝒂𝟏𝟏𝟏𝟏 𝒂𝒂𝟏𝟏𝟐𝟐 𝒃𝒃𝟏𝟏𝟏𝟏 𝒃𝒃𝟏𝟏𝟐𝟐 𝒂𝒂𝟏𝟏𝟏𝟏𝒃𝒃𝟏𝟏𝟏𝟏 + 𝒂𝒂𝟏𝟏𝟐𝟐𝒃𝒃𝟐𝟐𝟏𝟏 𝒂𝒂𝟏𝟏𝟏𝟏𝒃𝒃𝟏𝟏𝟐𝟐 + 𝒂𝒂𝟏𝟏𝟐𝟐𝒃𝒃𝟐𝟐𝟐𝟐


𝒂𝒂𝟐𝟐𝟏𝟏 𝒂𝒂𝟐𝟐𝟐𝟐 × 𝒃𝒃𝟐𝟐𝟏𝟏 𝒃𝒃𝟐𝟐𝟐𝟐
=
𝒂𝒂𝟐𝟐𝟏𝟏𝒃𝒃𝟏𝟏𝟏𝟏 + 𝒂𝒂𝟐𝟐𝟐𝟐𝒃𝒃𝟐𝟐𝟏𝟏 𝒂𝒂𝟐𝟐𝟏𝟏𝒃𝒃𝟏𝟏𝟐𝟐 + 𝒂𝒂𝟐𝟐𝟐𝟐𝒃𝒃𝟐𝟐𝟐𝟐

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 67


Set and Logical Operations

(Ω)
= A∩Bꟲ

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 68


Set Operations Based on Coordinates

A region in an image is represented by a set of coordinates within the region


set universe complement disjoint or mutually The union of two sets

The difference of two sets complement The difference of two sets


Set Operations Based on Coordinates

A region in an image is represented by a set of coordinates within the region


Set Operations Based on Coordinates
Set Operations Based on Intensities

Complement – negative image


𝑨𝑨𝒄𝒄 = 𝒙𝒙, 𝒚𝒚, 𝑲𝑲 − 𝒛𝒛 𝒙𝒙, 𝒚𝒚, 𝒛𝒛 ∈ 𝑨𝑨
Thresholding
𝑨𝑨 ∪ 𝑩𝑩 = 𝒙𝒙, 𝒚𝒚, max 𝒛𝒛𝒂𝒂, 𝒛𝒛𝒃𝒃 𝒙𝒙, 𝒚𝒚, 𝒛𝒛𝒂𝒂 ∈ 𝑨𝑨, 𝒙𝒙, 𝒚𝒚, 𝒛𝒛𝒃𝒃 ∈ 𝑩𝑩
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 72
a b a ANDb a OR b NOT(a)
0 0 0 0 1
0 1 0 1 1
Logical Operations 1 0 0 1 0
1 1 1 1 0

Foreground/background
• Binary image: 0/1
• Fuzzy set: [0,1]

Logic operations will be used


a lot in morphological image
processing
Image Averaging – Noise Reduction

Assumption: the noise is uncorrelated in image and has zero mean


Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 74
Arithmetic Operations

The images used in averaging & subtraction must be


registered!

Output images should be normalized to the range of [0,255]

fm = f − min( f )
fs = K[ fm / max( fm )]

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 75


Spatial Operations

Perform directly on the pixels of the given image


• Intensity transformation – change the intensity
• Single pixel operations s=T(z)
• Neighborhood operations
• Geometric spatial transformations – change the
coordinates

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 76


Single pixel operations

• Determined by
• Transformation function T
• Input intensity value
• Not depend on other pixels and position
IN BETWEEN THE THE INTENSITY LEVEL

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 77


Neighborhood Operations

Image smoothing
g( x, y) =
1
∑ f (r, c)
mn ( r,c )∈Sxy

where r and c are the row


and column coordinates of
the pixels whose
coordinates are in the set Sxy

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 78


Geometric Transformations

affine transformations eq.:-

This transformation can scale,


rotate, translate, or sheer an
image, depending on the values
MOVING SOME PART OF THE PICTURE

chosen for the elements of


matrix A

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 79


Image Registration

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 80


Image Registration

Coordinates in the moving image 𝒗𝒗, 𝒘𝒘


Coordinates in the template image 𝒙𝒙, 𝒚𝒚
x = c1v + c2w + c3vw+ c4
y = c5v + c6w + c7vw+ c8

• Known: coordinates of the points 𝒙𝒙, 𝒚𝒚 and 𝒗𝒗, 𝒘𝒘


• Unknown: 𝒄𝒄𝟏𝟏 to 𝒄𝒄𝟖𝟖

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 81


Image Registration

Compensate the geometric


change in:
• view angle
• distance
• orientation
• sensor resolution
• object motion
Four major steps:
• Feature detection
• Feature matching
• Transformation model
• Resampling

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 82


Vector and Matrix Operations

FIGURE 2.43
Forming a vector
from
corresponding
pixel values in
three RGB
z1
component z = z2
images. z3 Component image 3 (Blue)
Component image 2 (Green)

Component image 1 (Red)

The Euclidean distance, D(z, a), between points (vectors) z and a in


n-dimensional space is defined as:

D(z,a) = z − a = (z − a )2 + (z − a )2 +... + (z − a )2
1 1 2 2 n n

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 83


Image Transformation

Forward transformation kernel

u = 0,1,..., M − 1
Inverse transformation kernel
v = 0,1,..., N − 1
x = 0,1,..., M − 1
y = 0,1,..., N − 1

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 84


Image Transformation

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 85


Review: Linear Systems

We define a system as a unit that converts an input function


into an output function.

Independent System operator


variable

86
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals
Linear Systems

 the convolution integral. It states that the response of a


linear, fixed-parameter system is completely characterized by
the convolution of the input with the system impulse
response.
δ(a) δ(x-a)
a
x

Convolution of two functions In the 1D discrete case


∞ ∞
( x)* h( x)
f= ∫ f (α )h( x − α )dα f [n]* h[n]
= ∑
m = −∞
f [m]h[n − m]
−∞

87
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals
Linear Systems

 In the 2D discrete case

∞ ∞
f [n=
1 , n2 ]**h[ n1 , n2 ] ∑ ∑
m1 = −∞ m2 = −∞
f [m1 , m2 ]h[n1 − m1 , n2 − m2 ]

h[n1 , n2 ] is a linear filter.

88
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals
Convolution Example

h
1 -1 -1
f
1 2 -1
2 2 2 3
1 1 1
2 1 3 3
Rotate
2 2 1 2
1 1 1 1 3 2 2
-1 2 1
-1 -1 1
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 89


Convolution Example 1 1 1 2 2 2 3

Step 1 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2
1 1 1
-1 2
4 2 2 3 5
-1 2
-2 1 3 3
2 2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 90


Convolution Example 1 1 1 2 2 2 3

Step 2 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2
1 1 1
2
-2 2
4 2 3 5 4
2
-2 1
-1 3 3
2 2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 91


Convolution Example 1 1 1 2 2 2 3

Step 3 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2
1 1 1
2 2
-2 2
4 3 5 4 4
2 1
-1 3
-3 3
2 2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 92


Convolution Example 1 1 1 2 2 2 3

Step 4 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2
1 1 1
2 2 2
-2 3
6 1 5 4 4 -2
2 1 3
-3 3
-3 1
2 2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 93


Convolution Example 1 1 1 2 2 2 3

Step 5 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2

1 2 2 2 3 5 4 4 -2
-1 4
2 1 3 3 9
-1 -2
2 2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 94


Convolution Example 1 1 1 2 2 2 3

Step 6 -1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
h
1 3 2 2

2 2 2 3 5 4 4 -2
-2
2 2
1 3 3 9 6
2
-2 2
-2 1 2
1 3 2 2
f f*h
From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 95


Convolution Example

and so on…

From C. Rasmussen, U. of Delaware

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 96


Example

1 1 1
1
* 9
1 1 1 
 =
1 1 1

97
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals
Example

1 1 1

*
1 −8 1
 
1 1 1
=

98
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals
Review Image Analysis

2D Discrete Fourier Transform

 2D Fourier Transform
∞ ∞
F (u , v) = ∑∑
m = −∞ n = −∞
f [m, n]e − j 2π (um + vn )

 2D Discrete Fourier Transform (DFT)


 k l 
1 M −1 N −1 − j 2π  m + n 
F [k , l ] = ∑ ∑
MN =m 0=n 0
f [m, n]e  M N 

2D DFT is a sampled version of 2D FT.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 99


2D Discrete Fourier Transform

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 100


2D Discrete Fourier Transform

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 101


2D Discrete Fourier Transform

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 102


2D Discrete Fourier Transform

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 103


Discrete Cosine Transform

 1D Discrete Cosine Transform (DCT)


N −1
 (2n + 1)kπ 
F [k ] = ∑ f [n]α (k ) cos  
n =0  2 N 
 1
 for k = 0
 N
where
= k 0,1,..., N − 1 and α (k ) = 
 =2
 N for k 1, 2,..., N − 1

Inverse DCT
N −1
 (2n + 1)kπ 
f [n] = ∑ F [k ]α (k ) cos  
k =0  2N 

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 104


Discrete Cosine Transform

 2D Discrete Cosine Transform (DCT)


M −1 N −1
 (2m + 1)kπ   (2n + 1)lπ 
F [k .l ] = ∑ ∑ f [m, n]α (k )α (l ) cos   cos  
m 0=
= n 0  2M   2N 
 1
 for k = 0
 N
where
= k , l 0,1,..., N − 1 and α (k ) = 
 =2
 N for k 1, 2,..., N − 1

Inverse DCT
M −1 N −1
 (2m + 1)kπ   (2n + 1)lπ 
f [m, n] = ∑ ∑ F [k , l ]α (k )α (l ) cos   cos  
=k 0=l 0  2M   2N 

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 105


Discrete Cosine Transform

 The basis functions of DCT are real. (DFT has complex


basis functions.)
 DCT has very good energy compaction properties.
 DCT can be expressed in terms of DFT, therefore, Fast
Fourier Transform implementation can be used.
 In the case of block-based image compression, (e.g.,
JPEG), DCT produces less artifacts along the boundaries
than DFT does.

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 106


DCT and DFT
 N-point DCT of x[n] can be obtained from 2N-point
DFT of symmetrically extended x[n].
Symmetric extension:  x[n] for n 0,1,..., N − 1
=
x[n] = 
 x[2 N − n − 1] for=n N , N + 1,..., 2 N − 1
2 N −1  k 
− j 2π  n
DFT of x[ n] : X F [k ] = ∑ x[n]e
n =0
 2N 

 (2n + 1)kπ 
N −1
DCT of x[ n] : X C [k ] = α (k )∑ x[n]cos  
n =0  2 N 

πk
α (k ) −j
X C [k ] = e 2N
X F [k ]
2

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 107


Discrete Cosine Transform

 Matrix Representation of DCT


N −1
 (2n + 1)kπ 
F [k ] = ∑ f [n]α (k ) cos  
n =0  2N 

  (2*0 + 1)0π   (2*1 + 1)0π   (2*( N − 1) + 1)0π  


 α (0) cos   α (0) cos    α (0) cos   
 2N   2N   2N 
 F [0]     f [0] 
    (2*0 + 1)1π 
α (1) cos 
 (2*1 + 1)1π 
α (1) cos 
 (2*( N − 1) + 1)1π 
α (1) cos 
 
 F [1]   f [1]

=  2N

  2N

  2N

 
     
        
 F [ N − 1]    f [ N − 1]
α ( N − 1) cos  (2*0 + 1)( N − 1)π  α ( N − 1) cos  (2*1 + 1)( N − 1)π   α ( N − 1) cos  (2*( N − 1) + 1)( N − 1)π 
      
 2N   2N   2N 
F f
D
F = Df

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 108


Discrete Cosine Transform

 Matrix Representation of Inverse DCT


N −1
 (2n + 1)kπ 
f [n] = ∑ F [k ]α (k ) cos  
k =0  2 N 

  (2*0 + 1)0π   (2*0 + 1)1π   (2*0 + 1)( N − 1)π  


 α (0) cos  2N
 α (1) cos 
2N
  α ( N − 1) cos 
2N
 
     
 f [0]     F [0] 
   α (0) cos  (2*1 + 1)0π   (2*1 + 1)1π 
α (1) cos 
 (2*1 + 1)( N − 1)π 
α ( N − 1) cos 
 
 f [1]   F [1]

= 
 2N

  2N

  2N

 
     
        
 f [ N − 1]    F [ N − 1]
α (0) cos  (2* ( N − 1) + 1)0π  α (1) cos  (2*( N − 1) + 1)1π   α ( N − 1) cos  (2*( N − 1) + 1)( N − 1)π 
      
 2N   2N   2N 
f F

D−1
f = D−1F

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 109


Discrete Cosine Transform

 Inverse DCT matrix is equal to the transpose of DCT


matrix!
D−1 = DT

DD
=T
D=
T
D I

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 110


Discrete Cosine Transform

 For two-dimensional signals:


Β = DΑDT

     T 
=
 Β   D  A  D 
     

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 111


Try In MATLAB

DCF & DFT

a = imread(‘cameraman.tif’);
DCTa = dct2(a);
DFTa = fft2(a); DFTa = fftshift(DFTa);

figure; imshow(log(abs(DCTa)),[ ]);


figure; imshow(log(abs(DFTa)),[ ]);

DCT DFT
figure; plot(abs(DCTa(1,:)));
figure; plot(abs(DFTa(128,:)));

% Also use mesh plots

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 112


Try In MATLAB

DCT
f=[1 2 3];
Df1 = dct(f)

D=dctmtx(3);
Df2=D*f;
f2=D’*f;

g=[1 2 3; 4 5 6; 7 8 9];
Dg1=dct2(g);
Dg2=D*g*D’;

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 113


Try In MATLAB

Review your matrix-vector knowledge


f = [1 2; 3 4]
g = [1; 1]
g = [1 1]
g’
z = f * g’
n=0:10
plot(sin(n));
plot(n,sin(n)); title(‘Sinusoid’); xlabel(‘n’); ylabel(‘Sin(n)’);
n=0:0.1:10
plot(n,sin(n));
grid;
figure; subplot(2,1,1); plot(n,sin(n)); subplot(2,1,2); plot(n,cos(n));

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 114


Try In MATLAB

Some more built-ins

a = zeros(3,2)
b = ones(2,4)
c = rand(3,3) %Uniform distribution
help rand
help randn %Normal distribution
d1 = inv(c)
d2 = inv(rand(3,3))
d3 = d1+d2
d4 = d1-d2
d5 = d1*d2
d6 = d1.*d3
e = d6(:)

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 115


Try In MATLAB

Image processing in Matlab

x=imread(‘cameraman.tif’);  x[0, 0] x[0,1]  x[0, N − 1] 


figure;  x[1, 0] x[1,1]  x[1, N − 1] 
x[n1 , n2 ] = 
imshow(x);      
 
[h,w]=size(x);  x[ M − 1, 0]   x[ M − 1, N − 1] MxN
y=x(0:h/2,0:w/2);
imwrite(y,‘cameraman.tif’’);

Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 116


Try In MATLAB

Image Resize & compare


Compare with myresize1.m  Compare with myresize3.m
function [y]=myresize1(x)
% This function down samples an image by two function [y]=myresize3(x)
[h,w]=size(x); % This function downsamples an image by two
for i=1:h/2, y = x(1:2:end,1:2:end);
for j=1:w/2,
y(i,j) = x(2*i,2*j);  We can add inputs/outputs
end function [y,height,width]=myresize4(x,factor)
end
% Inputs:
% x is the input image
Compare with myresize2.m % factor is the downsampling factor
function [y]=myresize2(x) % Outputs:
% This function down samples an image by two % y is the output image
[h,w]=size(x); % height and width are the size of the output
for i=0:h/2-1, image
for j=0:w/2-1,
y = x(1:factor:end,1:factor:end);
y(i+1,j+1) = x(2*i+1,2*j+1);
end [height,width] = size(y);
end
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals 117
Try In MATLAB

Convolution Integral
f=imread(‘saturn.tif’);
figure; imshow(f);
[height,width]=size(f);
f2=f(1:height/2,1:width/2);
figure; imshow(f2);
[height2,width2=size(f2);
f3=double(f2)+30*rand(height2,width2);
figure;imshow(uint8(f3));
h=[1 1 1 1; 1 1 1 1; 1 1 1 1; 1 1 1 1]/16;
g=conv2(f3,h);
figure;imshow(uint8(g));

118
Dr. Odai Al Soad DIP-Lect1-Intro & Imag. Fundamentals

You might also like