You are on page 1of 37

Basic relationship between pixels

BITS Pilani Instructor-In-Charge: Rajitha K


Hyderabad Campus
Basic Relationships Between Pixels

• Neighborhood
• Adjacency
• Connectivity
• Paths
• Regions and boundaries
Neighbors of a pixel

Any pixel p(x, y) has two vertical and two horizontal


neighbors, given by (x+1, y), (x-1, y), (x, y+1), (x, y-1)
Neighbors of a pixel
Neighbors of a Pixel

• Any pixel p(x, y) has two vertical and two


horizontal neighbors, given by
(x+1, y), (x-1, y), (x, y+1), (x, y-1)
• This set of pixels are called the 4-neighbors of
P, and is denoted by N4(P).
Each of them are at a unit distance from P.
Neighbors of a Pixel (Contd..)
• The four diagonal neighbors of p(x,y) are
given by, (x+1, y+1), (x+1, y-1), (x-1, y+1),
(x-1 ,y-1)
• This set is denoted by ND(P).
• Each of them are at Euclidean distance of
1.414 from P.
Neighbours of a pixel

=
Neighbors of a Pixel (Contd..)
• The points ND(P) and N4(P) are together
known as 8-neighbors of the point P, denoted
by N8(P).
• Some of the points in the N4, ND and N8 may
fall outside image when P lies on the border
of image.
Connectivity

• It is very useful for establishing object


boundaries
• Defining image components and
regions etc

Brightness values more than


200 is assigned as 1 and less
than 200 is assigned 0
Brightness values more
than 30 is assigned as 0
and less than 30 is
assigned 1
Connectivity

• Two pixels are connected if they are neighbors


N4(P), ND(P) or N8(P) and their gray levels are
similar
• For example, in a binary image two pixels
are connected if they are 4-neighbors and
have same value (0/1).
Connectivity(Conditions)
Q Q

P P P

They are neighbours(N4,ND or N8)

B(Q) B(Q)

B(P) B(P) B(P)

B(Q)

Their intensity values(Gray levels are same), B(P)=B(Q)


M-connectivity (mixed connectivity)

: Two pixels p and q with values from V are


m-connected
i) if, q is in N4(p) or
ii) q is in ND(p) and the set N4(p)∩ N4(q)
is empty (has no pixels whose values are
from V).
Connectivity (Contd.)

8-Connected
4-Connected

V=(1,2)

M-
Connected
M-connected examples
Set V = { 10, 20,30) Connection between P and Q
is
R 10 40 20 a) 4 connected
Q b) 8 connected
c) m-connected
40 10 40
P

20 40 40 Connection between P and R is


a) 4 connected
b) 8 connected
c) m-connected
Adjacency
Mainly there are three types of adjacency
Let V be set of gray levels values used to define
adjacency.
• 4-adjacency: Two pixels p and q with values from
V are 4- adjacent if q is in the set N4(P).
• 8-adjacency: Two pixels p and q with values from
V are 8-adjacent if q is in the set N8(P).
Adjacency (Contd.)
• m-adjacency: Two pixels p and q with values from V are m-
adjacent
i) if, q is in N4(p) or
ii) q is in ND(p) and the set N4(p)∩ N4(q) is empty (has no
pixels whose values are from V).
Connectivity/Adjacency
Connectivity/Adjacency
• Pixel p is adjacent to pixel q if they are connected.
• Two image subsets S1 and S2 are adjacent if some
pixels in S1 is adjacent to some pixels in S2
Paths & Path lengths
• A path 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) and
(xn,yn) = (s,t)
n is the length of the path
Connectivity between subsets of
images

S1 S2

0 0 0 0 0 1 1 0
1 0 0 1 0 1 0 1
1 0 0 1 1 1 0 1
0 0 1 1 0 0 0 0
0 0 1 1 0 0 1 1

4- connected , M –connected and 8-


connected
Connectivity between subsets of
images

S1 S2

0 0 0 0 0 1 1 0
1 0 0 0 0 1 0 1
1 0 0 0 1 1 0 1
0 0 1 1 0 0 0 0
0 0 1 1 0 0 1 1

M –connected & 8
connected
Connected Components
Image I

• Subset s

p
Connected Components
• If p and q are pixels of an image subset S then p is
connected to q in S if there is a path from p to q
consisting entirely of pixels in S.
• For every pixel p in S, the set of pixels in S that are
connected to p is called a connected component of S.
• Distinct connected components are disjoint
Connected component labeling
• Ability to assign different labels to various disjoint
components of an image.
• It facilitates automatic image analysis
• Shape matching
• Area calculation
Algorithm
• Scan the image from left to right
and top to bottom fashion
• Assume 4- connectivity
• ‘A’ be a pixel at any instant of
scanning process. ‘B’ and ‘C’ are
the pixels scanned before scanning
the pixel A.
Steps
Algorithm
l(a) => Pixel value at position A
L(a)=> Label Assigned to pixel location A
If l(a) = 0, move to next scanning position
If l(a)=1 and l(b) = l(c) = 0
then assign a new label to position A
If l(a) =1 and only one of the two neighbor is one
then assign its label to A
If l(a) =1 and both B and C are 1’s ,
then
if l(b) = l(c) than l(a) = l(b)
if l(b) ≠ l(c) then assign one of the labels to A and make a note that
the two labels are equivalent
CCL- Algorithm

C
B A
Connected components labeling
CCL- Algorithm Contd.

1
2 2
Connected components labeling

1
2 2 2

(1,2) are equivalent


Connected components labeling

1
2 2 2
Connected components labeling

1
2 2 2
2 2

(1,2) are equivalent


Connected components labeling

1
2 2 2
2 2 3
2 4 4
2 4
5 5 5 5

(1,2) are equivalent


Connected components labeling

2
2 2 2
2 2 3
2 4 4
2 4
5 5 5 5

(1,2) are equivalent


(3,4) are equivalent
(4,5) are equivalent
Regions and Boundaries
• A subset R of pixels in an image is called a
Region of the image if R is a connected set.
• The boundary of the region R is the set of
pixels in the region that have one or more
neighbors that are not in R.
Count the number of birds…………
can we do this using ccl…..

You might also like