Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

‫بسم هللا الرحمن‬

‫الرحيم‬

Computer Vision By Dr Mohamed Berbar 1

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.

Computer Vision By Dr Mohamed Berbar 3

Classification of Image Transforms


• 2.1- Point transforms
– modify individual pixels
– modify pixels’ locations
• 2.2- Local transforms
– output derived from neighbourhood
• 2.3- Global transforms
– whole image contributes to each output value

Computer Vision By Dr Mohamed Berbar 4

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

Part 2.2: Modify pixels’ locations


LECTURE 2
Geometric Transformation
Part 2.3 : Local transforms
o Convolution
o Applications
» smoothing
» Sharpening
» edge detection, Low and High pass filters LECTURE 3
Part 2.4: Global transforms
Fourier, Hough, Principal Component, Wavelet LECTURE 4
Computer Vision By Dr Mohamed Berbar 5

Operatio Generic
n Characterization
Complexity/Pixel

- the output value at a specific coordinate is


Point
dependent only on the input value at that constant
same coordinate.

- the
output value at a specific coordinate is
Local dependent on the input values in the P2
neighborhood of that same coordinate.

- the output value at a specific coordinate is


Global
dependent on all the values in the input image.
N2

Table 2: Types of image operations. Image size = N x N;


neighborhood size = P x P. Note that the complexity is
specified in operations per pixel.
Computer Vision By Dr Mohamed Berbar 6

3
Unit 2
2.1- Point transforms
(A) Modify individual pixels
(B) Modify pixels’ locations

Computer Vision By Dr Mohamed Berbar 7

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

Computer Vision By Dr Mohamed Berbar 8

4
Brightness adjustment
Image Negation
IMAGE_GRAY(*,*) = abs(IMAGE_GRAY(*,*)-255)

Original image Full image negation

Computer Vision By Dr Mohamed Berbar 9

Brightness Adjustment

Add a constant to all values


g’ = g + k
(k = 50)

Computer Vision By Dr Mohamed Berbar 10

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).

Computer Vision By Dr Mohamed Berbar 11

11

Computer Vision By Dr Mohamed Berbar 12

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.

a)Original image unsigned byte;


b)Result of adding 80 to its pixels
a) b)
The problem with the above image is that the pixel
data type is unsigned byte. With this data type we
can only represent values from 0 to 255. Adding 80
to 255 gives (255+80) - 256 = 79 (wraparound),
which is a dark pixel value.
Computer Vision By Dr Mohamed Berbar 13

13

To solve this wraparound effect, we can convert the pixel data type to
unsigned short (16 bits) and then perform the addition.

Result with data type short

Computer Vision By Dr Mohamed Berbar 14

14

7
Contrast Adjustment

Scale all values by a constant


g’ = g*k
(k = 1.5)

Computer Vision By Dr Mohamed Berbar 15

15

Histogram Manipulation

• Modify distribution of grey values to


achieve some effect

Computer Vision By Dr Mohamed Berbar 16

16

8
Equalisation/Adaptive
Equalisation
• Specifically to make histogram
uniform

Grey Value Histogram

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

Computer Vision By Dr Mohamed Berbar 17

17

• Image pre-processing is the term for operations on the images at


the lowest level of abstraction. These operations do not increase
image information content, but they decrease it if entropy is an
information measure. The aim of pre-processing is an improvement
of the image data that suppresses undesired distortions or enhances
some image features relevant for further processing and analysis
tasks.
• There are four different types of Image Pre-Processing techniques,
and they are listed below.
1. Pixel brightness transformations/ Brightness corrections
2. Geometric Transformations
3. Image Filtering and Segmentation
4. Fourier transform and Image restoration
• Histogram equalization is one of the Pixel brightness
transformations techniques. It is a well-known contrast
enhancement technique due to its performance on almost all types
ofDr image.
Mohamed Berbar 18

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

• Contrast is defined as the difference in intensity between two objects


in an image. If the contrast is too low, it is impossible to distinguish
between two objects, and they are seen as a single object.
• Global histogram equalization (GHE)
• GHE is very simple and fast, but its contrast enhancement power is
low. Here the histogram of the whole input image is used to compute
the histogram transformation function. As a result, the dynamic range
of the image histogram is flattened and stretched. The overall contrast
is improved.
• Local histogram equalization (LHE)
• LHE can enhance the overall contrast more effectively.
• One of the drawbacks of histogram equalization is that it can change
the mean brightness of an image significantly as a consequence of
histogram flattening and sometimes this is not a desirable property
when preserving the original mean brightness of a given image is
necessary. Bi-Histogram Equalization was proposed to overcome this
problem.
Computer Vision By Dr Mohamed Berbar 20


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

• Compute the histogram of pixel values


of the input image. The histogram
Algorithm places the value of each pixel 𝑓[𝑥,𝑦]
into one of L uniformly-spaced
buckets ℎ[𝑖]

Where 𝐿=2^3= number of grey


levels
and the image dimension is 𝑀×𝑁
Dr Mohamed Berbar 22

22

11
•Calculate the cumulative distribution function (cumulative frequency
distribution)

Scale the input image using the cumulative distribution function to


produce the output image.

Where CDFmin is the smallest non-zero value of the cumulative


distribution function
Where 𝐿=2^8 and the image
dimension is 𝑀×𝑁
Dr Mohamed Berbar 23

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

Computer Vision By Dr Mohamed Berbar 25

25

Transformations

• A Transformation consists of:


•a Rotation
•a Scaling and
•a Translation
•a Skewing (Shearing)

Computer Vision By Dr Mohamed Berbar 26

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.

Computer Vision By Dr Mohamed Berbar 27

27

Translation

-Scaling

-Rotation

-Reflection

Skewing (Shear )

Computer Vision By Dr Mohamed Berbar 28

28

14
Computer Vision By Dr Mohamed Berbar 29

29

Computer Vision By Dr Mohamed Berbar 30

30

15
Unit 2 Part 3
2.3 Local Transforms

• 2.3.1 Convolution
• 2.3.2 Applications
– smoothing
– sharpening
– matching

Computer Vision By Dr Mohamed Berbar 31

31

2.3.1 Convolution
Place template on image
Multiply overlapping
values in image and
template
Sum products and
normalise
(Templates usually small)

Computer Vision By Dr Mohamed Berbar 32

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

Image convolution Filter Support region


Output
operator (mask/kernel) of filter where
filtered
g(x-r) is
image
nonzero
Discrete image processing 2D form

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

For the 8 pixels, Z1…Z8, surrounding the pixel being


processed, define a 3x3 neighbourhood centred on this
pixel, Z9, the noise filtered value can be calculated using

Computer Vision By Dr Mohamed Berbar 34

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

Computer Vision By Dr Mohamed Berbar 35

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

Write your own convolution function


myconv.m to perform a convolution.
It should accept two parameters – the
input matrix (image) and convolution
http://www.s2.chalmers.se/undergraduate/courses0203/ess060/PDFdocuments/ForScreen/Notes/Convolution.pdf
kernel, and output the filtered matrix.

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')

Investigate the listed kernels in Matlab by


1 0 -1 1 2 1 performing convolutions on the Mandrill and
2 0 -2 0 0 0 Lena images. Study the effects of different
kernel sizes (3x3, 9x9, 25x25) on the output.
1 0 -1 -1 -2 -1
Sobel operators (edge
The median filter is used for noise reduction. It works by
detection in x and y replacing a pixel value with the median of its neighbourhood
directions) pixel values (vs the mean filter which uses the mean of the
neighbourhood pixel values). Apply Matlab’s median filter
>>fspecial('sobel') function medfilt2 on the Mandrill and Lena images. Remember to
>>fspecial('sobel')’
use different filter sizes (3x3, 9x9, 16x16).

Image Processing using Matlab Sumitha Balasuriya 37

37

Applications

• Usefulness of convolution is the


effects generated by changing
templates
– Smoothing
• Noise reduction
– Sharpening
• Edge enhancement
– Template matching
• A later lecture

Computer Vision By Dr Mohamed Berbar 38

38

19
Smoothing

• Aim is to reduce noise


• What is “noise”?
• How is it reduced

Computer Vision By Dr Mohamed Berbar 39

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

• Compute smoothed value, s


• if |s – x| > T then
Output = s
x otherwise

Computer Vision By Dr Mohamed Berbar 41

41

High-Pass Spatial Filters

Suppress Low frequency components

Computer Vision By Dr Mohamed Berbar 42

42

21
Sharpening
• What is it?
– Enhancing discontinuities
– Edge detection
• Why do it?
– Perceptually important
– Computationally important
– Suppress low frequency components

Computer Vision By Dr Mohamed Berbar 43

43

0 -1 0
-1 4 -1
0 -1 0
High-pass filter mask
Sum of all point is Zero

After applying High-pass


filter mask and then add
constant 85 to adjust the
brightness.
Computer Vision By Dr Mohamed Berbar 44

44

22
High-Pass Spatial Filters
High-pass filters attenuating the low -
frequency details of an image while
leaving the low-frequency content intact.

Effects: Edge enhancement of an


image

Computer Vision By Dr Mohamed Berbar 45

45

Low-Pass Spatial Filters

Low-Pass Spatial Filters


Low-pass spatial filters leave the low-frequency content of
an image intact while attenuating the high-frequency
content.

Effects: Reducing the visual noise contained in an image.


Remove the high-frequency content of an image.

Computer Vision By Dr Mohamed Berbar 46

46

23
Mean Filter

9
Noise filtered value =  Z i / 9
i =1

Computer Vision By Dr Mohamed Berbar 47

47

W1 W2 W3
W4 W5 W6
W7 W8 W9

• If all weights are either +ve or +ve and


zeros, the operator will blur the image.
• Blur the image is referred to as Low-
Pass filter
• Subtracting a blurred image from the
original results in a highlighting of
those pixels where the intensity is
changing rapidly and is termed High-
Pass filter
Computer Vision By Dr Mohamed Berbar 48

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.

Computer Vision By Dr Mohamed Berbar 49

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).

Computer Vision By Dr Mohamed Berbar 50

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

Computer Vision By Dr Mohamed Berbar 53

53

27

You might also like