Digital Image Processing - Lecture Notes
Digital Image Processing - Lecture Notes
Lectures by
[email protected]
Contents
1 Image Processing 1
2 Digital Images 3
2.1 Digital Representation . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Image Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.1 Pixel Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.2 Spatial Resolution . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.3 Grayscale Resolution . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3 Issues with Digitising an Image . . . . . . . . . . . . . . . . . . . . . . 5
2.4 Isopreference Curves . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 Histogram Processing 28
6.1 Histogram Equalization . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Lecture 1
Image Processing
In imaging science, image processing is any form of signal processing for which the input
is an image, such as a photograph or video frame; the output of image processing may
be either an image or a set of characteristics or parameters related to the image. Most
image-processing techniques involve treating the image as a two-dimensional signal
and applying standard signal-processing techniques to it. Image processing is referred
to processing of a 2D picture by a computer.Closely related to image processing are
computer graphics and computer vision. In computer graphics, images are manually
made from physical models of objects, environments, and lighting, instead of being
acquired (via imaging devices such as cameras) from natural scenes, as in most animated
movies. Computer vision, on the other hand, is often considered high-level image
processing out of which a machine/computer/software intends to decipher the physical
contents of an image or a sequence of images (e.g., videos or 3D full-body magnetic
resonance scans). Various image processing techniques include:
1
nature, in the sense that restoration techniques tend to be based on mathemat-
ical or probabilistic models of image degradation, we use several models
and finds out (hopefully!!) which model is best suited. For instance, ultrasound
images are usually corrupted by speckle noises, whereas CCD (Charge Couple
Devices) camera images are affected by salt & pepper noises (due to faulty CCD
elements).
2
Jerrin
c Thomas Panachakel
Lecture 2
Digital Images
3
2.1. DIGITAL REPRESENTATION
it). It is interesting to see the exact pixel values of this sampled image; this is shown
in Fig. 2.1. The values of the pixels need to be stored in the computers memory, this
means that in the end the data ultimately need to end up in a binary representation,
the spatial continuity of the image is approximated by the spacing of the samples in the
sample grid. The number of bits is called the BPP (Bits Per Pixel). For obtaining the
values shown in Fig. 2.1, 8 BPP sampling depth was used. We can make the following
observations,
Brighter the pixel, higher will be the pixel value and vice-versa.
Although for an 8BPP image, the values of pixels can range from o (darkest
pixel) to 255 (brightest pixel), here the range is from 8 to 250,the ratio of these
two numbers is called the dynamic range of the image. It is measured as a ratio,
or as a base-10 (decibel) or base-2 (doublings, bits or stops) logarithmic value.
The standard coordinate system for images is slightly confusing, atleast for be-
ginners, the first element is denoted as (0, 0) and the last as (10, 8), the first index
denotes the row and the second index denotes the column. This is a widely used
format but there are other formats too.
4
Jerrin
c Thomas Panachakel
2.2. IMAGE RESOLUTION
Jerrin
c Thomas Panachakel 5
2.3. ISSUES WITH DIGITISING AN IMAGE
cos(x) = [1.0000, 0.9950, 0.9801, 0.9553, 0.9211, 0.8776, 0.8253, 0.7648, 0.6967, 0.6216),
translating these values to the range [0, 255], cos0 (x) = [255.0000, 254.3605, 252.4485, ...
...249.2831, 244.8958, 239.3306, 232.6430, 224.8998, 216.1785, 206.5661], formula used,
cos0 (x) = ((cos(x)+1) 128) 1. Similarly, consider the signal z = cos(5x), and obtain
cos0 (5x) for same values of x. A plot of both was obtained using Matlab is shown in
Fig. 2.2. As it can be seen, the rate change of pixel intensities for cos0 (5x) is much
higher than that for cos0 (x). So, in images also, higher frequency mean more rapid rate
of change. And where do we have high frequencies in an image? In the fine details,
edges, where there are rapid changes in pixel values. So, if we pass an image through
a low pass filter, we will lose the high frequencies present, and the perceivable change
will be that the fine details will be lost, implies, the edges will be blurred. This is really
bad, but not in all cases. Let me explain that...
When do you say that you image is corrupted by noise? When some pixels have
values which are not matching with the surrounding pixel values. That is, we are
actually having high frequencies there! Thus an easy way to remove high frequencies is
by using low pass filter. This same approach is used in many applications, to remove
the noise from a noisy image, we pass the image through a low pass filter and hence we
can remove the nose at the expense of high frequency information present in the image.
And now the question is what the unit of this image frequency is? In image pro-
cessing, frequency has the units of cycles per millimetre.
Now we have frequency and sampling, but how are they related?
6
Jerrin
c Thomas Panachakel
2.3. ISSUES WITH DIGITISING AN IMAGE
Suppose we scan a 6in 4 in photo at 110 dpi, what will be resolution of the
image?
Resolution will be 660 440.
Jerrin
c Thomas Panachakel 7
2.4. ISOPREFERENCE CURVES
your operating system or viewer program is only showing a quarter or less of the
pixels will still look as sharp as anything else.
8
Jerrin
c Thomas Panachakel
Lecture 3
Interpolation can be used in STEP 2. Interpolation is the process of using known data
to estimate values at unknown location. There are several approaches for achieving
zooming using interpolation, they are listed below in the increasing order of complexity
3. Bicubic interpolation
4. Spline interpolation
5. Sinc Interpolation
9
3.1. ZOOMING AN IMAGE
2. Bilinear Interpolation: Since different sources dont agree on bilinear and bicubic
interpolation, only the basics are given here. In bilinear interpolation, the values
of four neighbouring pixels are used to decide the intensity value of the pixel at
the given location. If we need to find the value at location (x, y) given by v(x, y),
we use the following relation,
10
Jerrin
c Thomas Panachakel
3.2. NEIGHBOURS OF A PIXEL
The four coefficients are found out by solving four equations in four unknowns
that can be obtained by using the four nearest neighbours of (x, y).
Although bilinear interpolation is computationally more demanding than nearest
neighbour interpolation, it gives better results.
The sixteen coefficients are found out by solving sixteen equations in sixteen un-
knowns that can be obtained by using the sixteen nearest neighbours of (x, y).
It is interesting to note that Eq. 3.2 attains the form of Eq.3.2 when the limits
of both summations are changed from 0 to 3 to 0 to 1. Of all the techniques
discussed, bicubic interpolation gives the best results. Comparison of these tech-
niques is given in Fig. 3.2. Checkerboard effect is clearly visible in Fig. ??.Bicubic
interpolation gives slightly sharper results than the other two
If P is a border pixel, some neighbouring pixels of P will lie outside the image.
Jerrin
c Thomas Panachakel 11
3.3. A FEW TERMS...
12
Jerrin
c Thomas Panachakel
3.3. A FEW TERMS...
Let V = {1, 2}, and intensity matrix as be given in Fig. 3.6. If the pixel shown
in red is p, then all the pixels in blue can be q, i.e. they are 8- adjacent with p.
m- adjacency (mixed adjacency): Two pixels p and q are said to be m-
adjacent iff
q N4 (p). i.e. q is one of the 4 neighbours of p. OR
q is in ND (p) and the set ND (p) N4 (p) has no pixels whose values are from
V.
Let V = {1}, and intensity matrix as be given in Fig. 3.7.If the pixel shown in
red is p , then the pixel in black satisfies condition 1 for m-adjacency and the
pixel in blue satisfies condition 2.
Before going any further, why do we actually need these stuffs? Consider Fig. 3.4.
How many object are there? We can find out using what we discussed just now!
Other applications include but not limited to segregating the foreground image from
the background.
A (digital ) path (or curve from pixel p with coordinates (x, Y ) to pixel q with Figure 3.4
coordinates (s, t) is a sequence of distinct pixels with coordinates
Jerrin
c Thomas Panachakel 13
3.3. A FEW TERMS...
where (X0 , y0 ) = (x, y), (xn , yn ) = (s, t) and pixels (xi , yi ) and (xi1 , yi1 ) are
adjacent for 1 i n. Here, n is the length of the path. The path is said to
be a closed path if (x0 , y0 ) = (xn , yn ). We can define 4, 8 or m paths
depending on the type of adjacency specified.
Now lets see why we moved to m adjacency from 8 adjacency. Its because of the
ambiguity of the latter. That is, 8 adjacency sometimes gives us ambiguous or multiple
paths for the same pair of pixels as shown Fig. 3.8. Vrinda maam: IF the question
is to find the shortest path, find all possible paths and mention which one
is the shortest.
Problem 3.1
Find the shortest (a) 4- path, (b) 8- path and (c) m- path between the pixels
4 2 3 2
?
3 3 1 3
with the intensity value in boldface. . Given, V = {1, 2}.
2 3 2 2
2 1 2 3
(a): Referring to Fig. 3.9a, a 4- path doesnt exist between the given pair of
pixels.
(b): Referring to Fig. 3.9b, the length of the shortest 8- path is 4.
(c): Referring to Fig. 3.9c, the length of the shortest m- path is 5.
14
Jerrin
c Thomas Panachakel
3.3. A FEW TERMS...
For any pixel p in S, the set of pixels that are connected to it in S is called a
connected component.
Two regions R1 and R2 are said to be adjacent if their union forms a connected
set.
The boundary or border or contour of a region R is the set of points that are
adjacent to the points n the complement of R. i.e., the border of a region is the
set of pixels in that region that have at least one background neighbour.
The boundary of a finite region forms a closed path and is thus a global concept.
Edges are formed from pixels with derivative values that exceed a preset thresh-
old.
Jerrin
c Thomas Panachakel 15
3.3. A FEW TERMS...
PROBLEM
Problem 3.2
Consider the two image subsets, S1 and S2 , shown in the figure. For
V=1, determine whether these two subsets are
(a): 4- adjacent
(b): 8- adjacent
(c): m- adjacent
figure).
PROBLEM
?
(a): Not 4- adjacent. (b): Is 8- adjacent (ref. figure). (c): Is m- adjacent (ref.
Problem 3.3
Consider the two image subsets, S1 and S2 , shown in the figure. For
V=1, determine the number of pairs between S1 and S2 for each
(a): 4- adjacent
?
(b): 8- adjacent
(c): m- adjacent
16
Jerrin
c Thomas Panachakel
3.3. A FEW TERMS...
(a): No. of 4- adjacent pairs: 2 with coordinates [(2, 4), (2, 5)] and [(3, 4), (3, 5)].
(b): No. of 8- adjacent pairs: 6 with coordinates [(1, 4), (0, 5)], [(1, 4), (2, 5)], ...
...[(2, 4), (2, 5)], [(2, 4), (3, 5)], [(3, 4), (2, 6)], [(3, 5), (3, 6)]
(c): No. of m- adjacent pairs: 3 with coordinates [(2, 4), (2, 5)], ...
...[(3, 4), (3, 5)], [(1, 4), (0, 5)].
Jerrin
c Thomas Panachakel 17
Lecture 4
Different Metrics
1. Euclidean Distance:
The pixels having a distance of less than or equal to a value r from a pixel
location, say (x, y), are contained in a disk of radius r centered at (x, y) as
shown in Fig. 4.1.
D4 (p, q) = |x s| + |y t| (4.2)
The pixels having a distance of less than or equal to a value r from a pixel
location, say (x, y),form a diamond centered at (x, y) as shown in Fig. 4.2.
18
4.1. DISTANCE MEASURES
The pixels having a distance of less than or equal to a value r from a pixel
location, say (x, y),form a square centered at (x, y) as shown in Fig. 4.3.
The pixels with D8 = 1 are the 8-neighbours of (x, y).
4. Dm distance
Jerrin
c Thomas Panachakel 19
4.1. DISTANCE MEASURES
the neighbours.
Refer section 3.3 for Dm distance. Dm between P and P4 for several ar-
rangements of pixels are shown in Fig.4.4. Note that P and P2 are no longer
m-adjacent in Fig. 4.4b.
20
Jerrin
c Thomas Panachakel
4.2. MATHEMATICAL OPERATIONS ON PIXELS
a11 a12 b11 b12
and
a21 a22 b21 b22
a11 a12 b11 b12 a11 b11 a12 b12
=
a21 a22 b21 b22 a21 b21 a22 b2
X X X
[ai fi (x, y) + aj fj (x, y)] = ai fi (x, y) + aj fj (x, y) (4.5)
X X
= ai fi (x, y) + aj fj (x, y) (4.6)
= ai g( x, y) + aj gj (x, y) (4.7)
Thus,the sum operator satisfies Eq.4.4 and hence it is a linear operator. L is said to be
a non-linear operator iff
2 5 2 1
Let A = and B =
7 3 4 5
Jerrin
c Thomas Panachakel 21
4.2. MATHEMATICAL OPERATIONS ON PIXELS
Then,
Clearly,
L(A + B) 6= L(A) + L(B) (4.13)
and hence the operator is non-linear in nature.
Applications
Addition: Image enhancement. If pixel g(x, y) = f (x, y) + (x, y) where g(x, y) is ob-
tained when the pixel f (x, y) of the original noise-free image is corrupted
by zero mean noise. If the noise at every pixel coordinates (x, y) is uncor-
related, it can be easily shown than if K versions of g(x, y) is averaged, the
averaged version approaches the original noise-free image with very small
variance provided K is sufficiently large. This is called image averaging
or signal averaging.
Subtraction: For enhancing the difference between two images.
Multiplication/division: Shading correction. Let f (x, y) be the perfect image, which when multi-
plied by the shading function h(x, y) gives the image g(x, y). i.e. g(x, y) =
f (x, y) h(x, y). If the shading function h(x, y) is known or can be approx-
imated by imaging a constant intensity image, f (x, y) can be obtained from
g(x, y) by multiplying g(x, y) by the inverse of h(x, y), i.e., by dividing g by
h.
22
Jerrin
c Thomas Panachakel
Lecture 5
The elements of the set as far as DIP is concerned can be pixel coordinates
(ordered pair) or pixel intensities.
Disjoint sets: Two sets A and B are said to be disjoint or mutually exclusive if they ahve no
common elements, i.e. A B =
Difference: A B = {w|w A, w B} = A B c
Similar to union, complement etc, we have AND, OR, NOT etc here.
Used in morphology
23
5.3. GEOMETRIC SPATIAL TRANSFORMATION
Like to align two images taken at the same time but using different imaging
systems (like MRI and PET).
Or to align two images taken using the same imaging system but at different
times, like satellite images of a given location, several days, moths or years apart.
We have the input image and the reference image (image to which the input is
to be aligned). What we need to find the transformation that will perform this
alignment or registration.
For this, we use what is called tie points or control points which are corresponding
points whose location are known precisely in the input and the reference images.
24
Jerrin
c Thomas Panachakel
5.5. VECTOR AND MATRIX OPERATION
There are several methods for selecting the tie points, 1) interactively, 2) using
algorithms that attempt to detect the points automatically or 3)by embedding
artifacts (such as small metallic objects) in the imaging sensors which will produce
a set of known points or reseau marks directly on all images which can be used
as guided for establishing tie points.
A color image in the RGB space will have a red, a blue and a green component
per pixel.
Jerrin
c Thomas Panachakel 25
5.6. IMAGE TRANSFORMATION
Once pixels are represented using matrices and vectors, we can make use of tolls
of vector-matrix theory. For example, Euclidean Distance, D between a pixel
vector x and an arbitrary point a is defined by the vector product,
1
D(x,a) = [(x a)T (x a)] 2 (5.3)
1
2 2 2
= [(x1 a1 ) + (x2 a2 ) + ..... + (xn an ) ] 2 (5.4)
26
Jerrin
c Thomas Panachakel
5.7. PROBABILISTIC METHODS
Mean
L1
X
m = zk p(zk ) (5.7)
k=0
L1
Variance 2 = (zk m)2 p(zk )
P
k=0
Variance is the measure of spread of pixel intensity values about the mean and
hence is is a useful measure of image contrast.
Jerrin
c Thomas Panachakel 27
Lecture 6
Histogram Processing
Let T (r) be transformation on the pixel values r of the input image to give s, the pixel
values of the transformed image. i.e.,
s = T (r) (6.1)
where 0 r L 1 We assume the following,
1. T (r) is a monotonically increasing function in the interval 0 r L 1
and
2. 0 r L 1 for 0 r L 1.
It may be noted that we assume the transformation to be monotonically increas-
ing rather than to be strictly monotonically increasing. The difference is that a
function is said to be strictly monotonically increasing iff T (r2 ) > T (r1 )f orr2 > r1 and
monotonically increasing if T (r2 ) T (r1 )f orr2 > r1 . i.e., we allow the transformation
to map multiple values to map to the same element in case of a monotonically increasing
function whereas in a strictly monotonically increasing function, we allow only unique
mappings (one to one mapping), i.e., no two elements from the domain can have the
same element in the range.
One issue with simple monotonically increasing function is that inverse mapping
may not be possible since multiple elements are mapped to the same element in the
range. so, if we want the inverse transformation (r = T 1 (s)0 r L 1 to exist, we
change the assumption one to T (r) is a strictly monotonically increasing function
in the interval 0 r L 1.
28
6.1. HISTOGRAM EQUALIZATION
Jerrin
c Thomas Panachakel 29
References
1. http://en.wikipedia.org/wiki/Bilinear_interpolation
2. http://en.wikipedia.org/wiki/Nearest_neighbour_interpolation
3. http://site.iugaza.edu.ps/amaliha/files/2010/02/DIP_ch02.pdf
4. http://support.esri.com/es/knowledgebase/techarticles/detail/23127
5. http://www.cambridgeincolour.com/tutorials/image-interpolation
6. http://tech-algorithm.com/articles/nearest-neighbor-image-scaling
7. http://tech-algorithm.com/articles/nearest-neighbor-image-scaling
8. http://facweb.cs.depaul.edu/research/vc/VC_Workshop/presentations/pdf/
Jacob_tutorial1.pdf
9. http://bme.med.upatras.gr/improc/image_sampling
10. http://staff.najah.edu/sites/default/files/Chapter2_Digital_Image_Fundamentals.
pdf
11. http://www-cs.ccny.cuny.edu/~wolberg/pub/crc04.pdf
12. http://www.haberdar.org/Spatial-Frequency-of-an-Image-Tutorial
13. http://www.cs.cf.ac.uk/Dave/Multimedia/node223
14. http://www-cs.engr.ccny.cuny.edu/~wolberg/cs470/doc/CSc470.pdf
15. http://bme.med.upatras.gr/improc/image_sampling
16. http://users.wfu.edu/matthews/misc/DigPhotog/alias
17. Digital Image Processing, Gonzalez and Woods, Second Edition, Prentice-Hall,
2002
30