Professional Documents
Culture Documents
LECTURE 2 Image Transforms No Ink
LECTURE 2 Image Transforms No Ink
الرحيم
Unit 2
Image Transforms
Transforming images to images
Lecture 2
1
Types of operations
• The types of operations that can be applied
to digital images to transform an input
image a[m,n] into an output image b[m,n]
(or another representation) can be
classified into three categories as shown in
Table 2.
2
You Should Know…
Part 2.1: Point transforms
Modify individual pixels
2.1.1 Brightness adjustment
2.1.2 Contrast adjustment
2.1.3 Histogram equalisation
Operatio Generic
n Characterization
Complexity/Pixel
- the
output value at a specific coordinate is
Local dependent on the input values in the P2
neighborhood of that same coordinate.
3
Unit 2
2.1- Point transforms
(A) Modify individual pixels
(B) Modify pixels’ locations
Unit 2 Part 1
Point transforms
2.1.A Modify individual pixels
Manipulating individual pixel values
2.1.A1 Brightness adjustment
2.1.A2 Contrast adjustment
2.1.A3 Histogram equalisation
4
Brightness adjustment
Image Negation
IMAGE_GRAY(*,*) = abs(IMAGE_GRAY(*,*)-255)
Brightness Adjustment
10
5
Brightening the image could be done by adding
(or subtracting) a constant value to (or from)
intensity values of pixels in an image, expressed
algebraically, a pixel with intensity value Z is trans-
formed as follow
Z= Z +
where is the brightness constant, which can be
positive or negative. In some image processing textbooks
defining adjusting image brightness as histogram sliding (Low
1991).
11
12
6
Pixel Overflow
• When performing pixel arithmetic, the result of the
operation may not fit within the pixel data type. This
experiment illustrates this problem by adding a
constant to all image pixels.
13
To solve this wraparound effect, we can convert the pixel data type to
unsigned short (16 bits) and then perform the addition.
14
7
Contrast Adjustment
15
Histogram Manipulation
16
8
Equalisation/Adaptive
Equalisation
• Specifically to make histogram
uniform
12000
10000
8000
Frequency
6000
4000
2000
1
16
31
46
61
76
91
106
121
136
151
166
181
196
211
226
241
256
Grey Value
17
18
9
Equalisation Transform
•is a specific case of the more general
contrast adjustment operations.
•A simple example of contrast adjustment
involves scaling the pixels in the range
[a, b] to fill the range [Z1, Zk].
Z k − Z1
Z = '
( Z − a ) + Z1
b−a
Computer Vision By Dr Mohamed Berbar 19
19
•
20
10
Equalisation Transform
Algorithm
• Steps Involved
1. Get the input image
2. Generate the histogram for the image
3. Find the local minima of the image
4. Divide the histogram based on the local minima
5. Have the specific gray levels for each partition of the
histogram
6. Apply the histogram equalization on each partition
https://www.mygreatlearning.com/blog/histogram-
equalization-explained/#Algorithm
Dr Mohamed Berbar 21
21
22
11
•Calculate the cumulative distribution function (cumulative frequency
distribution)
23
Dr Mohamed Berbar 24
24
12
Unit 2
2.1.B Modify pixels’ locations
Geometric Transformation
• 2.1.B1 Translation
• 2.1.B2 Scalling
• 2.1.B3 Rotation
• 2.1.B4 Skewing
25
Transformations
26
13
Transforming Points
• A transformation simply takes a point and
maps it to another location. A
transformation alters each point P in space
into a new point Q by means of a specific
formula or algorithm.
27
Translation
-Scaling
-Rotation
-Reflection
Skewing (Shear )
28
14
Computer Vision By Dr Mohamed Berbar 29
29
30
15
Unit 2 Part 3
2.3 Local Transforms
• 2.3.1 Convolution
• 2.3.2 Applications
– smoothing
– sharpening
– matching
31
2.3.1 Convolution
Place template on image
Multiply overlapping
values in image and
template
Sum products and
normalise
(Templates usually small)
32
16
Convolution
Bit of theory! Convolution of two functions f(x) and g(x)
+
h( x ) = f ( x ) g ( x ) =
−
f (r ) g ( x − r )dr
height width
H ( x, y ) = I (i, j )M ( x − i, y − j )
j =1 i =1 Compute the convolution where
there are valid indices in the
kernel
Image Processing using Matlab Sumitha Balasuriya 33
33
34
17
Example
Image Template Result
… . . . . . ... … . . . . . ...
…3 5 7 4 4… … . . . . . ...
…4 5 8 5 4… 1 1 1 … . 6 6 6 .…
…4 6 9 6 4… 1 2 1 … . 6 7 6 .…
…4 6 9 5 3… 1 1 1 … . 6 7 6 .…
…4 5 8 5 4… … . . . . . ...
… . . . . . ... … . . . . . ...
Divide by template sum
35
Convolution example
Image (I)
0 0 0 0 0 0 0 0 0 0
197 199 195 194 189 190 132 90 112 101 Filter (M) 0 196 196 194 192 170 137 105 97 0
194 194 198 201 189 196 150 85 87 97
0 195 196 194 192 167 133 98 92 0
194 194 198 195 186 191 109 90 90 124
0 194 194 193 189 158 124 92 90 0
197 187 195 198 185 186 115 78 81 96 1/9 1/9 1/9 0 193 193 191 186 154 122 92 89 0
194 190 198 193 187 177 88 86 94 69
194 194 190 190 179 177 93 99 95 100 j 1/9 1/9 1/9 = 0
0
194
194
192
192
189
188
184
182
149
146
121
122
91
93
90
95
0
0
201 194 191 186 186 181 74 110 82 76
196 194 195 191 183 164 77 119 84 88 1/9 1/9 1/9 0 195 193 190 183 147 128 100 106 0
0 194 192 189 181 146 125 100 105 0
192 194 199 192 191 174 89 164 103 129
0 0 0 0 0 0 0 0 0 0
201 190 187 189 178 168 90 82 88 84
i
height width
H ( x, y ) = I (i, j )M ( x − i, y − j )
j =1 i =1
36
36
18
Common convolution kernels
0.11 0.11 0.11 -0.17 -0.67 -0.17 -0.17 -0.67 -0.17 0.01 0.08 0.01
0.11 0.11 0.11 -0.67 3.33 -0.67 -0.67 4.33 -0.67 0.08 0.62 0.08
0.11 0.11 0.11 -0.17 -0.67 -0.17 -0.17 -0.67 -0.17 0.01 0.08 0.01
Arithmetic mean Laplacian (enhance edges) Sharpening filter Gaussian filter
filter (smoothing) >>fspecial('laplacian') >>fspecial('unsharp') (smoothing)
>>fspecial('average') >>fspecial('gaussian')
37
Applications
38
19
Smoothing
39
Noise Definition
• Noise is deviation of a value from its
expected value
– Random changes
•x→x+n
– Salt and pepper
• x → {max, min}
Noise Filtering in Digital Image Processing
Noise filtering is another type of image enhancement operation.
• By smoothing
S(x + n) = S(x) + S(n) = S(x)
– Since noise is random and zero mean
Computer Vision By Dr Mohamed Berbar 40
40
20
Adaptive Smoothing
41
42
21
Sharpening
• What is it?
– Enhancing discontinuities
– Edge detection
• Why do it?
– Perceptually important
– Computationally important
– Suppress low frequency components
43
0 -1 0
-1 4 -1
0 -1 0
High-pass filter mask
Sum of all point is Zero
44
22
High-Pass Spatial Filters
High-pass filters attenuating the low -
frequency details of an image while
leaving the low-frequency content intact.
45
46
23
Mean Filter
9
Noise filtered value = Z i / 9
i =1
47
W1 W2 W3
W4 W5 W6
W7 W8 W9
48
24
W1 W2 W3
W4 W5 W6
W7 W8 W9
• If W1 = W2 = W3 = W7 = W8 = W9 = 0 and
W4,W5, W6 > 0
Then the operator blurs along rows of images;
horizontal features such as edges are not
affected
• If W1 = W4 = W7 = W3 = W6 = W9 = 0 and
W2,W5, W8 > 0
Then the operator blurs along columns
of images; vertical features such as edges are not
affected.
49
W1 W2 W3
W4 W5 W6
W7 W8 W9
• If W2 = W3 = W4 = W6 = W7 = W8 =
0 and W1,W5, W9 > 0
Then the operator blurs along diagonal
of images ( top left to bottom-right).
50
25
Median Smoothing
Median filtering is an area process that does not fall under the
category of convolution
Non-linear filters such as median filters In this case, the gray-level
of each pixel is replaced by the median (middle) of the
brightness values of pixels in the surrounding region.
Median is one value in an ordered set:
n +1
n odd
2
n n +1
average , n even
2 2
1 2 3 4 5 6 7 → median = 4
2 3 4 5 6 7 → median = 4.5
Computer Vision By Dr Mohamed Berbar 51
51
Original Smoothed
Median Smoothing
Computer Vision By Dr Mohamed Berbar 52
52
26
Noisy LP
filter
Image
HP Median
filter
filter
53
27