Sunteți pe pagina 1din 4

i

An Introduction to Digital Image


Processing with Matlab
Notes for SCM2511 Image
Processing 1
Alasdair McAndrew
School of Computer Science and Mathematics
Victoria University of Technologyii CONTENTS
Contents
1 Introduction 1
1.1 Images and pictures . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 1
1.2 What is image processing? . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 1
1.3 Images and digital images . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 4
1.4 Some applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 6
1.5 Aspects of image processing . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 7
1.6 An image processing task . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 7
1.7 Types of digital images . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 8
1.8 Image File Sizes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 11
1.9 Image Acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 12
1.10 Image perception . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 12
2 Basic use of Matlab 15
2.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 15
2.2 Basic use of Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 16
2.3 Variables and the workspace . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 17
2.4 Dealing with matrices . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 19
2.5 Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . 28
2.6 Help in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 30
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 32
3 Images and Matlab 33
3.1 Greyscale images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 33
3.2 RGB Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 35
3.3 Indexed colour images . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 35
3.4 Data types and conversions . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 38
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 39
4 Image Display 41
4.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 41
4.2 The imshow function . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . 41
4.3 Bit planes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 44
4.4 Spatial Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 45
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 47
5 Point Processing 51
5.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 51
5.2 Arithmetic operations . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 52CONTENTS iii
5.3 Histograms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 56
5.4 Thresholding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 67
5.5 Applications of thresholding . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 70
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 71
6 Spatial Filtering 75
6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 75
6.2 Notation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 79
6.3 Filtering in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 80
6.4 Frequencies; low and high pass lters . . . . . . . . . . . . . . . . . . . .
. . . . . 84
6.5 Gaussian lters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 87
6.6 Non-linear lters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 89
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 91
7 Noise 95
7.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 95
7.2 Types of noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 95
7.3 Cleaning salt and pepper noise . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 98
7.4 Cleaning Gaussian noise . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 102
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 106
8 Edges 111
8.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 111
8.2 Dierences and edges . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 111
8.3 Second dierences . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 118
8.4 Edge enhancement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 122
8.5 Final Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 128
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 128
9 The Fourier Transform 131

9.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 131
9.2 The one-dimensional discrete Fourier transform . . . . . . . . . . . . . . .
. . . . 131
9.3 Properties of the one-dimensional DFT . . . . . . . . . . . . . . . . . . .
. . . . . 135
9.4 The two-dimensional DFT . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 137
9.5 Fourier transforms in Matlab . . . . . . . . . . . . . . . . . . . . . . . .
. . . . 142
9.6 Fourier transforms of images . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 144
9.7 Filtering in the frequency domain . . . . . . . . . . . . . . . . . . . . .
. . . . . . 148
9.8 Removal of periodic noise . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 159
9.9 Inverse ltering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 161
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 167
10 The Hough and Distance Transforms 169
10.1 The Hough transform . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 169
10.2 Implementing the Hough transform in Matlab . . . . . . . . . . . . . . . .
. . . 174
10.3 The distance transform . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 180
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 191
11 Morphology 195iv CONTENTS
11.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . 195
11.2 Basic ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . 195
11.3 Dilation and erosion . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 196
11.4 Opening and closing . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 203
11.5 The hit-or-miss transform . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 211
11.6 Some morphological algorithms . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 213
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 220
12 Colour processing 223
12.1 What is colour? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 223
12.2 Colour models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 227
12.3 Colour images in Matlab . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . 234
12.4 Pseudocolouring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 236
12.5 Processing of colour images . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . 239
Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 245
13 Image coding and compression 247
13.1 Lossless compression . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . 247

Exercises . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
. . . . . . . . . 252
Bibliography 255
Index 257Chapter 1
Introduction
1.1 Images and pictures
As we mentioned in the preface, human beings are predominantly visual creatures:
we rely heavily
on our vision to make sense of the world around us. We not only look at things t
o identify and
classify them, but we can scan for dierences, and obtain an overall rough feeling f
or a scene with
a quick glance.
Humans have evolved very precise visual skills: we can identify a face in an ins
tant; we can
dierentiate colours; we can process a large amount of visual information very qui
ckly.
However, the world is in constant motion: stare at something for long enough and
it will change
in some way. Even a large solid structure, like a building or a mountain, will c
hange its appearance
depending on the time of day (day or night); amount of sunlight (clear or cloudy
), or various shadows
falling upon it.
We are concerned with single images: snapshots, if you like, of a visual scene.
Although image
processing can deal with changing scenes, we shall not discuss it in any detail
in this text.
For our purposes, an image is a single picture which represents something. It ma
y be a picture
of a person, of people or animals, or of an outdoor scene, or a microphotograph
of an electronic
component, or the result of medical imaging. Even if the picture is not immediat
ely recognizable,
it will not be just a random blur.
1.2 What is image processing?
Image processing involves changing the nature of an image in order to either
1. improve its pictorial information for human interpretation,
2. render it more suitable for autonomous machine perception.
We shall be concerned with digital image processing, which involves using a comp
uter to change the
nature of a digital image (see below). It is necessary to realize that these two
aspects represent two
separate but equally important aspects of image processing. A procedure which sa
tises condition
(1)a procedure which makes an image look bettermay be the very worst procedure for s
atisfying condition (2). Humans like their images to be sharp, clear and detailed; m
achines prefer their
images to be simple and uncluttered.
Examples of (1) may include:
12 CHAPTER 1. INTRODUCTION

S-ar putea să vă placă și