2.A - Some Basic Relationships Between Pixels Draft
2.A - Some Basic Relationships Between Pixels Draft
COMPUTER GRAPHICS
2
Some Basic Relationships Between
Pixels
A. Neighbors of a Pixel
● A pixel p at coordinates (x, y) has four
horizontal and vertical neighbors whose
coordinates are given by
(x + 1, y), (x - 1, y), (x, y + 1), (x, y – 1)
This set of pixels, called the 4-neighbors of p, is
denoted by N4(p).
Each pixel is a unit distance from (x, y), and some
of the neighbors of p lie outside the digital image if
(x, y) is on the border of the image.
3
Some Basic Relationships Between
Pixels
8-neighbors of p - N8(p) 4
Some Basic Relationships Between
Pixels
8-neighbors of p : N8(p) 5
Some Basic Relationships Between
Pixels
● The four diagonal neighbors of p have
coordinates
(x + 1, y + 1), (x + 1, y - 1), (x - 1, y + 1), (x - 1, y – 1)
and are denoted by ND(p). These points, together
with the 4-neighbors, are called the 8-neighbors of
p, denoted by N8(p).
As before, some of the points in ND(p) and N8(p) fall
outside the image if (x, y) is on the border of the
image.
N8(p) = N4(p) U ND(p)
6
Some Basic Relationships Between
Pixels
B. Adjacency, Connectivity, Regions, and
Boundaries
Connectivity between pixels is a fundamental concept
that simplifies the definition of numerous digital image
concepts, such as regions and boundaries.
To establish if two pixels are connected, it must be
determined if they are neighbors and if their gray
levels satisfy a specified criterion of similarity (say, if
their gray levels are equal).
For instance, in a binary image with values 0 and 1,
two pixels may be 4-neighbors, but they are said to
be connected only if they have the same value. 7
Some Basic Relationships Between
Pixels
● Let V be the set of intensity (gray-level)
values used to define adjacency.
In a binary image, V = {1} if we are referring to
adjacency of pixels with value 1.
In a gray-scale image, the idea is the same, but
set V typically contains more elements. For
example, in the adjacency of pixels with a range
of possible intensity (gray-level) values 0 to
255, set V could be any subset of these 256
values.
8
Some Basic Relationships Between
Pixels
We consider three types of adjacency:
(a) 4-adjacency: Two pixels p and q with values
from V are 4-adjacent if q is in the set N4(P).
(b) 8-adjacency: Two pixels p and q with values
from V are 8-adjacent if q is in the set N8(p).
(c) m-adjacency (mixed adjacency): Two pixels p
and q with values from V are m-adjacent if
➢ (1) q is in N4(p) or
➢ (2) q is in ND(p) and the set N4(p) ∩ N4(q) has no
pixels whose values are from V.
9
Some Basic Relationships Between
Pixels
10
Some Basic Relationships Between
Pixels
● Mixed adjacency is a modification of 8-
adjacency. It is introduced to eliminate the
ambiguities that often arise when 8-adjacency
is used.
For example, consider the pixel arrangement
shown in Fig. 2.26(a) for V = {1}. The three pixels
at the top of Fig. 2.26(b) show multiple
(ambiguous) 8-adjacency, as indicated by the
dashed lines.
This ambiguity is removed by using m-adjacency,
as shown in Fig. 2.26(c).
11
Some Basic Relationships Between
Pixels
● Two image subsets S1 and S2 are adjacent if
some pixel in S1 is adjacent to some pixel in S2.
It is understood here and in the following
definitions that adjacent means 4-, 8-, or m-
adjacent.
12
Some Basic Relationships Between
Pixels
A (digital) path (or curve) from pixel p with
coordinates (x, y) to pixel q with coordinates (s, t)
is a sequence of distinct pixels with coordinates
(x0, y0), (x1, y1), . . . , (xn, yn)
where (x0, y0) = (x, y), (xn, yn) = (s, t), and pixels
(xi, yi) and (xi-1, yi-1) are adjacent for 1 ≤ i ≤ n. In
this case, n is the length of the path.
If (x0, y0) = (xn, yn), the path is a closed path.
13
Some Basic Relationships Between
Pixels
We can define 4-, 8-, or m-paths depending on
the type of adjacency specified.
For example, the paths shown in Fig. 2.26(b)
between the northeast and southeast points are
8-paths, and the path in Fig. 2.26(c) is an m-path.
Note the absence of ambiguity in the m-path.
14
Some Basic Relationships Between
Pixels
● Let S represent a subset of pixels in an image.
Two pixels p and q are said to be connected
in S if there exists a path between them
consisting entirely of pixels in S.
➔ For any pixel p in S, the set of pixels that are
connected to it in S is called a connected
component of S. If it only has one connected
component, then set S is called a connected
set.
15
(d) (e) (f)
boundary: a pixels in the region that have one or more pixels that are not in the region
16
Some Basic Relationships Between
Pixels
Let R be a subset of pixels in an image. We call R a
region of the image if R is a connected set. Two regions
Ri and Rj are said to be adjacent if their union forms a
connected set. Regions that are not adjacent are said to
be disjoint.
We consider 4- and 8-adjacency when referring to
regions. For our definition to make sense, the type of
adjacency used must be specified.
For example, the two regions (of 1s) in Fig. 2.25(d) are
adjacent only if 8-adjacency is used (according to the
definition in the previous paragraph, a 4-path between
the two regions does not exist, so their union is not a
connected set).
17
Some Basic Relationships Between
Pixels
Suppose that an image contains K disjoint
regions, Rk, k = 1, 2, . . , K, none of which touches
the image border. Let Ru denote the union of all
the K regions, and let (Ru)c denote its complement
(recall that the complement of a set S is the set of
points that are not in S).
We call all the points in Ru the foreground, and
all the points in (Ru)c the background of the
image.
18
Some Basic Relationships Between
Pixels
The boundary (also called border or contour) of a region R is
the set of pixels in the region that have one or more neighbors
that are not in R.
The boundary (also called the border or contour) of a region
R is the set of points that are adjacent to points in the
complement of R. Said another way, the border of a region is
the set of pixels in the region that have at least one
background neighbor. Here again, we must specify the
connectivity being used to define adjacency.
For example, the point circled in Fig. 2.25(e) is not a member
of the border of the 1-valued region if 4-connectivity is used
between the region and its background. As a rule, adjacency
between points in a region and its background is defined in
terms of 8-connectivity to handle situations like this.
19
Some Basic Relationships Between
Pixels
The preceding definition sometimes is referred to as
the inner border of the region to distinguish it from
its outer border, which is the corresponding border
in the background. This distinction is important in the
development of border-following algorithms. Such
algorithms usually are formulated to follow the outer
boundary in order to guarantee that the result will
form a closed path.
For instance, the inner border of the 1-valued region
in Fig. 2.25(f) is the region itself. This border does
not satisfy the definition of a closed path given
earlier. On the other hand, the outer border of the
region does form a closed path around the region. 20
Some Basic Relationships Between
Pixels
If R happens to be an entire image (which we
recall is a rectangular set of pixels), then its
boundary is defined as the set of pixels in the first
and last rows and columns of the image.This
extra definition is required because an image has
no neighbors beyond its border.
Normally, when we refer to a region, we are
referring to a subset of an image, and any pixels
in the boundary of the region that happen to
coincide with the border of the image are included
implicitly as part of the region boundary.
21
Some Basic Relationships Between
Pixels
The concept of an edge is found frequently in
discussions dealing with regions and boundaries.
There is a key difference between these
concepts, however. 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 threshold. Thus, the
idea of an edge is a "local" concept that is based
on a measure of intensity-level (gray-level)
discontinuity at a point.
22
Some Basic Relationships Between
Pixels
It is possible to link edge points into edge segments,
and sometimes these segments are linked in such a
way that correspond to boundaries, but this is not
always the case.
The one exception in which edges and boundaries
correspond is in binary images. Depending on the
type of connectivity and edge operators used, the
edge extracted from a binary region will be the same
as the region boundary. This is intuitive.
Conceptually, until we arrive at Chapter 10, it is
helpful to think of edges as intensity discontinuities
and boundaries as closed paths.
23
Some Basic Relationships Between
Pixels
C. Distance Measures
For pixels p, q, and z with coordinates (x, y), (s, t),
and (v, w), respectively, D is a distance function
or metric if
a. D(p, q) ≥ 0 (D(p, q) = 0 iff p = q),
b. D(p, q) = D(q, p), and
c. D(p, z) ≤ D(p, q) + D(q, z).
24
Some Basic Relationships Between
Pixels
● The Euclidean distance between p and q is
defined as
De(p, q) = [(x-s)2 + (y-t)2]1/2 (2.5-1)
For this distance measure, the pixels having a
distance less than or equal to some value r
from (x, y) are the points contained in a disk of
radius r centered at (x, y).
25
Some Basic Relationships Between
Pixels
● The D4 distance (also called city-block
distance) between p and q is defined as
D4(p, q) = |x-s| + |y-t| (2.5-2)
➔ The pixels with D4 = 1 are the 4-neighbours of
(x,y).
26
Some Basic Relationships Between
Pixels
➔ In this case, the pixels having a D4 distance
from (x, y) less than or equal to some value r
form a diamond centered at (x, y). For example,
the pixels with D4 distance ≤ 2 from (x, y) (the
center point) form the following contours of
constant distance:
27
Some Basic Relationships Between
Pixels
● The D8 distance (also called chessboard
distance) between p and q is defined as
D8(p, q) = max(|x-s|, |y-t|) (2.5-3)
● The pixels with D8 = 1 are the 8-neighbors of
(x,y).
28
Some Basic Relationships Between
Pixels
● In this case, the pixels with D8 distance from (x,
y) less than or equal to some value r form a
square centered at (x,y). For example, the
pixels with D8 distance ≤ 2 from (x, y) (the
center point) form the following contours of
constant distance:
29
Some Basic Relationships Between
Pixels
● Note that the D4 and D8 distances between p
and q are independent of any paths that might
exist between the points because these
distances involve only the coordinates of the
points.
● If we elect to consider m-adjacency, however,
the Dm distance between two points is defined
as the shortest m-path between the points. In
this case, the distance between two pixels will
depend on the values of the pixels along the
path, as well as the values of their neighbors. 30
Some Basic Relationships Between
Pixels
● For instance, consider the following arrangement of pixels
and assume that p, p2, and p4 have value 1 and that p1 and
p3 can have a value of 0 or 1:
32