0% found this document useful (0 votes)
436 views50 pages

Dip R20 Unit-5 Notes

This document discusses morphological image processing and image segmentation. It defines morphological operations like dilation and erosion which can expand or shrink objects in an image. Dilation expands objects while erosion shrinks them. Opening involves erosion followed by dilation and is used to smooth contours and break thin connections. Closing is dilation followed by erosion and fuses breaks and fills holes. The hit-or-miss transform detects shapes in images. Basic algorithms like boundary extraction, region filling, and connected component extraction are also covered.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
436 views50 pages

Dip R20 Unit-5 Notes

This document discusses morphological image processing and image segmentation. It defines morphological operations like dilation and erosion which can expand or shrink objects in an image. Dilation expands objects while erosion shrinks them. Opening involves erosion followed by dilation and is used to smooth contours and break thin connections. Closing is dilation followed by erosion and fuses breaks and fills holes. The hit-or-miss transform detects shapes in images. Basic algorithms like boundary extraction, region filling, and connected component extraction are also covered.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

CHAPTER-6 Morphological Image Processing & Image Segmentation

UNIT-6
Morphological Image Processing
Introduction
The word morphology commonly denotes a branch of biology that deals with the form
and structure of animals and plants. Morphology in image processing is a tool for extracting
image components that are useful in the representation and description of region shape, such
as boundaries and skeletons. Furthermore, the morphological operations can be used for
filtering, thinning and pruning. The language of the Morphology comes from the set theory,
where image objects can be represented by sets.
Some Basic Concepts form Set Theory :
 If every element of a set A is also an element of another set B, then A is said to be a
subset of B, denoted as A ⊆ B
 The union of two sets A and B, denoted by C = A∪B
 The intersection of two sets A and B, denote by D = A∩B

 Disjoint or mutually exclusive A∩B =ø

 The complement of a set A is the set of elements not contained in

 The difference of two sets A and B, denoted A - B, is defined as

Digital Image Processing by P Sudheer Chakravarthi 1


CHAPTER-6 Morphological Image Processing & Image Segmentation

Reflection and Translation by examples:


• Need for a reference point.
• Reflection of B: = {x|x=-b, for b∈B}
• Translation of A by x=(x1,x2), denoted by (A)x is defined as:
(A)x = {c| c=a+x, for a∈A}

Dilation
Dilation is used for expanding an element A by using structuring element B. Dilation
of A by B and is defined by the following equation:

This equation is based on obtaining the reflection of B about its origin and shifting
this reflection by z. The dilation of A by B is the set of all displacements z, such that and A
overlap by at least one element. Based On this interpretation the equation of (9.2-1) can be
rewritten as:

Digital Image Processing by P Sudheer Chakravarthi 2


CHAPTER-6 Morphological Image Processing & Image Segmentation

Dilation is typically applied to binary image, but there are versions that work on gray
scale image. The basic effect of the operator on a binary image is to gradually enlarge the
boundaries of regions of foreground pixels (i.e. white pixels, typically). Thus areas of
foreground pixels grow in size while holes within those regions become smaller.
Any pixel in the output image touched by the dot in the structuring element is set to
ON when any point of the structuring element touches a ON pixel in the original image. This
tends to close up holes in an image by expanding the ON regions. It also makes objects
larger. Note that the result depends upon both the shape of the structuring element and the
location of its origin.
Summary effects of dilation:
 Expand/enlarge objects in the image
 Fill gaps or bays of insufficient width
 Fill small holes of sufficiently small size
 Connects objects separated by a distance less than the size of the window
Erosion
Erosion is used for shrinking of element A by using element B. Erosion for Sets A
and B in Z2, is defined by the following equation:

This equation indicates that the erosion of A by B is the set of all points z such that B,
translated by z, is combined in A.

Digital Image Processing by P Sudheer Chakravarthi 3


CHAPTER-6 Morphological Image Processing & Image Segmentation

Any pixel in the output image touched by the · in the structuring element is set to ON
when every point of the structuring element touches a ON pixel in the original image. This
tends to makes objects smaller by removing pixels.
Duality between dilation and erosion:
Dilation and erosion are duals of each other with respect to set
complementation and reflection. That is,

Opening:
An erosion followed by a dilation using the same structuring element for both
operations.

 Smooth contour
 Break narrow isthmuses
 Remove thin protrusion

Digital Image Processing by P Sudheer Chakravarthi 4


CHAPTER-6 Morphological Image Processing & Image Segmentation

Closing:
A Dilation followed by a erosion using the same structuring element for both
operations.

 Smooth contour
 Fuse narrow breaks, and long thin gulfs.
 Remove small holes, and fill gaps.

Digital Image Processing by P Sudheer Chakravarthi 5


CHAPTER-6 Morphological Image Processing & Image Segmentation

Hit-or-Miss Transform:
The hit-and-miss transform is a basic tool for shape detection. The hit-or-miss
transform is a general binary morphological operation that can be used to look for particular
patterns of foreground and background pixels in an image.
Concept: To detect a shape:
 Hit object
 Miss background
Let the origin of each shape be located at its center of gravity.
 If we want to find the location of a shape– X , at (larger) image, A
 Let X be enclosed by a small window, say – W.
 The local background of X with respect to W is defined as the set difference (W -
X).
 Apply erosion operator of A by X, will get us the set of locations of the origin of X,
such that X is completely contained in A.
 It may be also view geometrically as the set of all locations of the origin of X at
which X found a match (hit) in A.
 Apply erosion operator on the complement of A by the local background set (W – X).
 Notice, that the set of locations for which X exactly fits inside A is the intersection of
these two last operators above.
 If B denotes the set composed of X and it’s background B = (B1,B2) ; B1 = X ,
B2 = (W-X).
 The match (or set of matches) of B in A, denoted as

B1: Object related, B2: Background related


 The reason for using these kind of structuring element B = (B1,B2) is based on
definition two or more objects are distinct only if they are disjoint (disconnected)
sets.
 In some applications, we may interested in detecting certain patterns (combinations)
of 1’s and 0’s, not for detecting individual objects.
 In this case a background is not required and the hit-or-miss transform reduces to
simple erosion.
 This simplified pattern detection scheme is used in some of the algorithms for –
identifying characters within a text.

Digital Image Processing by P Sudheer Chakravarthi 6


CHAPTER-6 Morphological Image Processing & Image Segmentation

The structural elements used for Hit-or-miss transforms are an extension to the ones
used with dilation, erosion etc. The structural elements can contain both foreground and
background pixels, rather than just foreground pixels, i.e. both ones and zeros. The
structuring element is superimposed over each pixel in the input image, and if an exact match
is found between the foreground and background pixels in the structuring element and the
image, the input pixel lying below the origin of the structuring element is set to the
foreground pixel value. If it does not match, the input pixel is replaced by the boundary pixel
value.
Basic Morphological Algorithms

Boundary Extraction:
The boundary of a set A is obtained by first eroding A by structuring element B and
then taking the set difference of A and it’s erosion. The resultant image after subtracting the
eroded image from the original image has the boundary of the objects extracted. The
thickness of the boundary depends on the size of the structuring element. The boundary of a
set A is obtained by first eroding A by structuring element B and then taking the set
difference of A and it’s erosion. The resultant image after subtracting the eroded image from

Digital Image Processing by P Sudheer Chakravarthi 7


CHAPTER-6 Morphological Image Processing & Image Segmentation

the original image has the boundary of the objects extracted. The thickness of the boundary
depends on the size of the structuring element. The boundary β (A) of a set A is

Region Filling or Hole Filling:


A Hole may be defined as a background region surrounded by connected
border of foreground pixels. This algorithm is based on a set of dilations,
complementation and intersections. Let P is the point inside the boundary, and
that is filled with the value of 1.

 The process stops when Xk = Xk-1


Digital Image Processing by P Sudheer Chakravarthi 8
CHAPTER-6 Morphological Image Processing & Image Segmentation

 The set Xk contains all the filled holes


 The result that given by union of A and Xk , is a set contains the filled set
and the boundary.

Extraction of Connected Components:


Extraction of connected components from a binary image is central to many
automated image analysis applications.
 Let A be a set containing one or more connected components and form an array X0
whose elements are 0s except at each location known to correspond to a point in each
connected component A which is set to 1.
 The objective is to start with X0 and find all the connected components.

Digital Image Processing by P Sudheer Chakravarthi 9


CHAPTER-6 Morphological Image Processing & Image Segmentation

Convex Hull:
A is said to be convex if a straight line segment joining any two points in A lies
entirely within A.
 The convex hull H of set S is the smallest convex set containing S
 The set difference H-S is called the convex deficiency of S
The convex hull and convex deficiency useful for object description. This algorithm
iteratively applying the hit-or-miss transforms to A with the first of B element, unions it with
A, and repeated with second element of B.
Let Bi , i=1,2,3,4 represents the four structuring elements. Then we need to
implement the

Let us consider

and the procedure terminates when

Digital Image Processing by P Sudheer Chakravarthi 10


CHAPTER-6 Morphological Image Processing & Image Segmentation

If

then the convex hull of A is defined as

Thinning:
The thinning of a set A by a structuring element B, can be defined by terms of the hit-
and-miss transform:

A more useful expression for thinning A symmetrically is based on a sequence of


structuring elements:
{B}={B1, B2, B3, …, Bn}

Digital Image Processing by P Sudheer Chakravarthi 11


CHAPTER-6 Morphological Image Processing & Image Segmentation

Where Bi is a rotated version of Bi-1. Using this concept we define thinning by a


sequence of structuring elements:

The process is to thin by one pass with B1, then thin the result with one pass with B2,
and so on until A is thinned with one pass with Bn. The entire process is repeated until no
further changes occur. Each pass is preformed using the equation:

Thickening:
Thickening is a morphological dual of thinning and is defined as

Digital Image Processing by P Sudheer Chakravarthi 12


CHAPTER-6 Morphological Image Processing & Image Segmentation

As in thinning, thickening can be defined as a sequential operation:

the structuring elements used for thickening have the same form as in thinning, but with all
1’s and 0’s interchanged.

Skeletons:
The skeleton of A is defined by terms of erosions and openings:

with

Where B is the structuring element and indicates k successive


erosions of A:

k times, and K is the last iterative step before A erodes to an empty set in other words:

The S(A) can be obtained as the union of skeleton subsets Sk(A). A can be also
reconstructed from subsets Sk(A) by using the equation

Digital Image Processing by P Sudheer Chakravarthi 13


CHAPTER-6 Morphological Image Processing & Image Segmentation

Where denotes k successive dilations of Sk(A) .that is:

Digital Image Processing by P Sudheer Chakravarthi 14


CHAPTER-6 Morphological Image Processing & Image Segmentation

GRAY SCALE MORPHOLOGY


Gray Scale Images:
In gray scale images on the contrary to binary images we deal with digital image
functions of the form f(x,y) as an input image and b(x,y) as a structuring element. (x,y) are
integers from Z*Z that represent a coordinates in the image. f(x,y) and b(x,y) are functions
that assign gray level value to each distinct pair of coordinates. For example the domain of
gray values can be 0-255, whereas 0 – is black, 255- is white.

Dilation:
Equation for gray-scale dilation is

Df and Db are domains of f and b. The condition that (s-x),(t-y) need to be in the
domain of f and x,y in the domain of b, is analogous to the condition in the binary definition
of dilation, where the two sets need to overlap by at least one element.

Digital Image Processing by P Sudheer Chakravarthi 15


CHAPTER-6 Morphological Image Processing & Image Segmentation

We will illustrate the previous equation in terms of 1-D. and we will receive an
equation for 1 variable:

The requirements the (s-x) is in the domain of f and x is in the domain of b implies
that f and b overlap by at least one element. Unlike the binary case, f, rather than the
structuring element b is shifted. Conceptually f sliding by b is really not different than b
sliding by f. The general effect of performing dilation on a gray scale image is twofold:
If all the values of the structuring elements are positive than the output image tends to
be brighter than the input. Dark details either are reduced or eliminated, depending on how
their values and shape relate to the structuring element used for dilation
Erosion:
Gray-scale erosion is defined as:

The condition that (s+x),(t+y) have to be in the domain of f, and x,y have to be in the
domain of b, is completely analogous to the condition in the binary definition of erosion,
where the structuring element has to be completely combined by the set being eroded. The
same as in erosion we illustrate with 1-D function

Digital Image Processing by P Sudheer Chakravarthi 16


CHAPTER-6 Morphological Image Processing & Image Segmentation

• General effect of performing an erosion in grayscale images:


 If all elements of the structuring element are positive, the output image tends
to be darker than the input image.
 The effect of bright details in the input image that are smaller in area than the
structuring element is reduced, with the degree of reduction being determined
by the grayscale values surrounding by the bright detail and by shape and
amplitude values of the structuring element itself.
• Similar to binary image grayscale erosion and dilation are duals with respect to
function complementation and reflection.
Opening:
In the opening of a gray-scale image, we remove small light details, while relatively
undisturbed overall gray levels and larger bright features.

The structuring element is rolled underside the surface of f. All the peaks that are
narrow with respect to the diameter of the structuring element will be reduced in amplitude
and sharpness. The initial erosion removes the details, but it also darkens the image. The
subsequent dilation again increases the overall intensity of the image without reintroducing
the details totally removed by erosion.
Opening a G-S picture is describable as pushing object B under the scan-line graph,
while traversing the graph according the curvature of B

Digital Image Processing by P Sudheer Chakravarthi 17


CHAPTER-6 Morphological Image Processing & Image Segmentation

Closing:
In the closing of a gray-scale image, we remove small dark details, while relatively
undisturbed overall gray levels and larger dark features

The structuring element is rolled on top of the surface of f. Peaks essentially are left
in their original form (assume that their separation at the narrowest points exceeds the
diameter of the structuring element). The initial dilation removes the dark details and
brightens the image. The subsequent erosion darkens the image without reintroducing the
details totally removed by dilation
Closing a G-S picture is describable as pushing object B on top of the scan-line graph,
while traversing the graph according the curvature of B. The peaks are usually remains in
their original form.

Applications of Gray-Scale Morphology:

Morphological smoothing
 Perform opening followed by a closing
 The net result of these two operations is to remove or attenuate both bright and
dark artifacts and noise.

Digital Image Processing by P Sudheer Chakravarthi 18


CHAPTER-6 Morphological Image Processing & Image Segmentation

Morphological gradient
 Dilation and erosion are use to compute the morphological gradient of an image,
denoted g:

 It uses to highlights sharp gray-level transitions in the input image.


 Obtained using symmetrical structuring elements tend to depend less on edge
directionality.
Top-hat and Bottom-hat transformation:
 Combining image subtraction with opening and closing results are referred as top-hat
and bottom-hat transformations.
 The top-hat transformation of gray scale image f is defined as

 The bottom-hat transformation of gray scale image f is defined as

 The top-hat transform is used for light objects on a dark background and the bottom-
hat transform is used for the converse.
Textural segmentation:
 The objective is to find the boundary between different image regions based on
their textural content.
 Close the input image by using successively larger structuring elements.
 Then, single opening is preformed ,and finally a simple threshold that yields the
boundary between the textural regions.

Digital Image Processing by P Sudheer Chakravarthi 19


CHAPTER-6 Morphological Image Processing & Image Segmentation

Granulometry:
 Granulometry is a field that deals principally with Determining the size distribution
of particles in an image.
 Because the particles are lighter than the background, we can use a morphological
approach to determine size distribution. To construct at the end a histogram of it.
 Based on the idea that opening operations of particular size have the most effect on
regions of the input image that contain particles of similar size.
 This type of processing is useful for describing regions with a predominant
particle-like character.

Digital Image Processing by P Sudheer Chakravarthi 20


CHAPTER-6 Morphological Image Processing & Image Segmentation

Image Segmentation
Image segmentation divides an image into regions that are connected and have some
similarity within the region and some difference between adjacent regions. The goal is
usually to find individual objects in an image. For the most part there are fundamentally two
kinds of approaches to segmentation: discontinuity and similarity.

 Similarity may be due to pixel intensity, color or texture.


 Differences are sudden changes (discontinuities) in any of these, but especially
sudden changes in intensity along a boundary line, which is called an edge.

Detection of Discontinuities:

There are three kinds of discontinuities of intensity: points, lines and edges. The most
common way to look for discontinuities is to scan a small mask over the image. The mask
determines which kind of discontinuity to look for.

9
R  w1 z1  w2 z 2  ...  w9 z9  w z
i 1
i i

Point Detection: Whose gray value is significantly different from its background
R T
where T : a nonnegativ e threshold

Digital Image Processing by P Sudheer Chakravarthi 21


CHAPTER-6 Morphological Image Processing & Image Segmentation

Line Detection:

 Only slightly more common than point detection is to find a one pixel wide line in an
image.

 For digital images the only three point straight lines are only horizontal, vertical, or
diagonal (+ or –45).

Preferred direction is weighted by with a larger coefficient


 The coefficients in each mask sum to zero response of constant gray level areas
 Compare values of individual masks (run all masks) or run only the mask of specified
direction

Edge Detection:

Edge is a set of connected pixels that lie on the boundary between two regions
• ’Local’ concept in contrast to ’more global’ boundary concept
• To be measured by grey-level transitions
• Ideal and blurred edges

Digital Image Processing by P Sudheer Chakravarthi 22


CHAPTER-6 Morphological Image Processing & Image Segmentation

 First derivative can be used to detect the presence of an edge (if a point is on a ramp).
 The sign of the second derivative can be used to determine whether an edge pixel lie
on the dark or light side of an edge
 Second derivative produces two value per edge
 Zero crossing near the edge midpoint
 Non-horizontal edges – define a profile perpendicular to the edge direction

Digital Image Processing by P Sudheer Chakravarthi 23


CHAPTER-6 Morphological Image Processing & Image Segmentation

Edges in the presense of noise


 Derivatives are sensitive to (even fairly little) noise
 Consider image smoothing prior to the use of derivatives
Edge definition again
 Edge point – whose first derivative is above a pre-specified threshold
 Edge – connected edge points
 Derivatives are computed through gradients (1st) and Laplacians (2nd)

Edge Detection Gradient Operators:

Gradient
– Vector pointing to the direction of maximum rate of change of f at coordinates (x,y)

Gx   fx 
f      f 
G y   y 

Digital Image Processing by P Sudheer Chakravarthi 24


CHAPTER-6 Morphological Image Processing & Image Segmentation

– Magnitude: gives the quantity of the increase (some times referred to as gradient too)


f  mag (f )  Gx2  Gy2 
1
2

– Direction: perpendicular to the direction of the edge at (x,y)


 Gx 
 ( x, y )  tan 1  

G
  y

Partial derivatives computed through 2x2 or 3x3 masks. Sobel operators introduce
some smoothing and give more importance to the center point

Digital Image Processing by P Sudheer Chakravarthi 25


CHAPTER-6 Morphological Image Processing & Image Segmentation

Laplacian
– Second-order derivative of a 2-D function

2 f 2 f
 f  2  2
2

x y
– Digital approximations by proper masks

 Complementary use for edge detection


 Cons: Laplacian is very sensible to noise; double edges
 Pros: Dark or light side of the edge; zero crossings are of better use
 Laplacian of Gaussian (LoG): preliminary smoothing to find edges through zero
crossings.
 Consider the function:

The Laplacian of h is

The Laplacian of a Gaussian sometimes is called the Mexican hat function. It also can
be computed by smoothing the image with the Gaussian smoothing mask, followed by
application of the Laplacian mask.

Digital Image Processing by P Sudheer Chakravarthi 26


CHAPTER-6 Morphological Image Processing & Image Segmentation

Edge Linking and Boundary Detection


Local Processing:
 Two properties of edge points are useful for edge linking:
o the strength (or magnitude) of the detected edge points
o their directions (determined from gradient directions)
 This is usually done in local neighborhoods.
 Adjacent edge points with similar magnitude and direction are linked.
For example, an edge pixel with coordinates (x0,y0) in a predefined neighborhood of (x,y)
is similar to the pixel at (x,y) if
Strength of the gradient vector response f ( x, y)  ( x0 , y0 )  E, E : a nonnegativ e threshold
Gradient vector direction  ( x, y)   ( x0 , y0 )  A, A : a nonegative angle threshold
Both magnitude and angle criteria should be satisfied

Global Processing via the Hough Transform:


Hough transform: a way of finding edge points in an image that lie along a straight line.
Example: xy-plane v.s. ab-plane (parameter space)
yi  axi  b

Digital Image Processing by P Sudheer Chakravarthi 27


CHAPTER-6 Morphological Image Processing & Image Segmentation

The Hough transform consists of finding all pairs of values of  and  which satisfy
the equations that pass through (x,y). These are accumulated in what is basically a
2-dimensional histogram. When plotted these pairs of  and  will look like a sine wave. The
process is repeated for all appropriate (x,y) locations.

Thresholding:

The range of intensity levels covered by objects of interest is different from the
background.
1 if f ( x, y )  T
g ( x, y )  
0 if f ( x, y )  T

Illumination:

Fig. a) Computer Generated Reflectance Function b) Histogram of Reflectance


Function c) Computer Generated Illumination Function d) Product of a and c e)
Histogram of Product Image.

Digital Image Processing by P Sudheer Chakravarthi 28


CHAPTER-6 Morphological Image Processing & Image Segmentation

 Image is a product of reflectance and illuminance


 Reflection nature of objects and backaground
 Poor (nonlinear) illumination could impede the segmentation
 The final histogram is a result of convolution of the histogram of the log reflectance
and log illuminance functions
 Normalization if the illuminance function is known

Basic Global Thresholding:

Threshold midway between maximum and minimum gray levels


– Appropriate for industrial inspection applications with controllable illumination
– Automatic algorithm
• Segment with initial T into regions G1 and G2
• Compute the average gray level m1 and m2
• Compute new T=0.5(m1+m2)
• Repeat until reach an acceptably small change of T in successive iterations

Region Based Segmentation:


Edges and thresholds sometimes do not give good results for segmentation. Region-
based segmentation is based on the connectivity of similar pixels in a region.

– Each region must be uniform.

– Connectivity of the pixels within the region is very important.

Digital Image Processing by P Sudheer Chakravarthi 29


CHAPTER-6 Morphological Image Processing & Image Segmentation

There are two main approaches to region-based segmentation: region growing and
region splitting.

Region Growing:

 Let R represent the entire image region.

 Segmentation is a process that partitions R into subregions, R1,R2,…,Rn, such that


n
(a)  Ri  R
i 1

(b) Ri is a connected region, i  1,2,..., n


(c) Ri  R j   for all i and j, i  j

(d) P( Ri )  TRUE for i  1,2,..., n

(e) P( Ri  R j )  FALSE for any adjacent regions Ri and R j


where P(Rk): a logical predicate defined over the points in set Rk

For example: P(Rk)=TRUE if all pixels in Rk have the same gray level.

Digital Image Processing by P Sudheer Chakravarthi 30


CHAPTER-6 Morphological Image Processing & Image Segmentation

Region Splitting:

 First there is a large region (possible the entire image).


 Then a predicate (measurement) is used to determine if the region is uniform.
 If not, then the method requires that the region be split into two regions.
 Then each of these two regions is independently tested by the predicate
(measurement).
 This procedure continues until all resulting regions are uniform.
 The main problem with region splitting is determining where to split a region.
 One method to divide a region is to use a quadtree structure.
 Quadtree: a tree in which nodes have exactly four descendants.

Digital Image Processing by P Sudheer Chakravarthi 31


CHAPTER-6 Morphological Image Processing & Image Segmentation

Segmentation by Morphological Watersheds:


 The concept of watersheds is based on visualizing an image in three dimensions: two
spatial coordinates versus gray levels.
 In such a topographic interpretation, we consider three types of points:
(a) Points belonging to a regional minimum
(b) Points at which a drop of water would fall with certainty to a single minimum
(c) Points at which water would be equally likely to fall to more than one such
minimum.
 The principal objective of segmentation algorithms based on these concepts is to find
the watershed lines.

Digital Image Processing by P Sudheer Chakravarthi 32


CHAPTER-6 Morphological Image Processing & Image Segmentation

PREVIOUS QUESTIONS
1. With necessary figures, explain the opening and closing operations.
2. Explain the following morphological algorithms i) Boundary extraction ii) Hole
filling.
3. Explain the following morphological algorithms i) Thinning ii) Thickening
4. What is Hit-or-Miss transformation? Explain.
5. Discuss about Grey-scale morphology.
6. Write a short notes on Geometric Transformation
7. Explain about edge detection using gradient operator.
8. What is meant by edge linking? Explain edge linking using local processing
9. Explain edge linking using Hough transform.
10. Describe Watershed segmentation Algorithm
11. Discuss about region based segmentation.
12. Explain the concept of Thresholding in image segmentation and discuss its
merits and limitations.

Digital Image Processing by P Sudheer Chakravarthi 33


CHAPTER-4 Color Image Processing

UNIT-4
Color Image Processing
Introduction
The use of color in image processing is motivated by two principal factors. They are
Color is a powerful descriptor that often simplifies object identification and extraction from a
scene. Humans can discern thousands of color shades and intensities, compared to about only
two dozen shades of gray. Color in image processing is divided into two major areas,
Full-color processing: Images acquired with a full-color sensor, such as color TV camera or
Color scanner.
Pseudo-color processing: Assigning a color to a particular monochrome intensity or range of
Intensities.

4.1. Color Fundamentals


Color of an object is determined by the nature of the light reflected from it. In 1666,
Sir Isaac Newton discovered that when a beam of sunlight passes through a glass prism, the
emerging beam of light is not white but consists instead of a continuous spectrum of colors
ranging from violet at one end to red at the other. As the following Fig. shows that the color
spectrum may be divided into six broad regions: violet, blue, green, yellow, orange, and red.

Fig. Color spectrum seen by passing white light through a prism

Fig. Wavelengths comprising the visible range of the electromagnetic spectrum


Digital Image Processing by P Sudheer Chakravarthi 1
CHAPTER-4 Color Image Processing

Visible light is composed of a relatively narrow band of frequencies in the


electromagnetic spectrum. A body that reflects light that is balanced in all visible
wavelengths appears white to the observer. However, a body that favors reflectance in a
limited range of the visible spectrum exhibits some shades of color. For example, green
objects reflect light with wavelengths primarily in the 500 to 570 nm range while absorbing
most of the energy at other wavelengths. Characterization of light is central to the science of
color. If the light is achromatic (void of color), its only attribute is its intensity, or amount.
Achromatic light is what viewers see on a black and white television set.
Chromatic light spans the electromagnetic spectrum approximately from 400 to
700nm. Three basic quantities are used to describe the quality of a chromatic light source:
radiance, luminance, and brightness.
Radiance: Radiance is the total amount of energy that flows from the light source, and it is
usually measured in watts (W).
Luminance: Luminance, measured in lumens (lm), gives a measure of the amount of energy
an observer perceives from a light source.
Brightness: Brightness is a subjective descriptor that is practically impossible to measure.

Fig. Absorption of light by the red, green and blue cones in the human eye as a function
of wavelength

Cones are the sensors in the eye responsible for color vision. Detailed experimental
evidence has established that the 6 to 7 million cones in the human eye can be divided into
three principal sensing categories, corresponding roughly to red, green, and blue.

Digital Image Processing by P Sudheer Chakravarthi 2


CHAPTER-4 Color Image Processing

Approximately 65% of all cones are sensitive to red light, 33% are sensitive to green
light, and only about 2% are sensitive to blue (but the blue cones are the most sensitive). The
above figure shows average experimental curves detailing the absorption of light by the red,
green, and blue cones in the eye. Due to these absorption characteristics of the human eye,
colors are seen as variable combinations of the so- called primary colors red (R), green (G),
and blue (B).
The primary colors can be added to produce the secondary colors of light --magenta
(red plus blue), cyan (green plus blue), and yellow (red plus green). Mixing the three
primaries or a secondary with its opposite primary color, in the right intensities produces
white light.

Fig. Primary and Secondary Colors of light and pigments


The characteristics generally used to distinguish one color from another are
brightness, hue, and saturation. Brightness embodies the chromatic notion of intensity. Hue is
an attribute associated with the dominant wavelength in a mixture of light waves. Hue
represents dominant color as perceived by an observer. Saturation refers to the relative purity
or the amount of white light mixed with a hue. The pure spectrum colors are fully saturated.
Colors such as pink (red and white) and lavender (violet and white) are less saturated, with
the degree of saturation being inversely proportional to the amount of white light-added. Hue
and saturation taken together are called chromaticity, and. therefore, a color may be
characterized by its brightness and chromaticity. The amounts of red, green and blue needed
to form any particular color are called the tristimulus values and are denoted by red (X),
green (Y) and blue (Z) needed to form a particular color. A color can be specified by its
trichromatic coefficients and defined as

Digital Image Processing by P Sudheer Chakravarthi 3


CHAPTER-4 Color Image Processing

4.2. Color Models


The purpose of a color model (also called color space or color system) is to facilitate
the specification of colors in some standard, generally accepted way. In essence, a color
model is a specification of a coordinate system and a subspace within that system where each
color is represented by a single point.
Most color models used are oriented either toward hardware or toward applications
where color manipulation is goal. The most commonly used hardware-oriented models are
RGB (Red, Green, Blue) for color monitors and video cameras, CMY (Cyan, Magenta,
Yellow) and CMYK (CMY + Black) for color printing and HSI (Hue, Saturation, Intensity)
which corresponds closely with the way humans describe and interpret color.

4.2.1. The RGB Color Model:


In the RGB model, each color appears in its primary spectral components of red,
green, and blue. This model is based on a Cartesian coordinate system. The color subspace of
interest is the cube shown in the following figure. In which RGB values are at three corners;
cyan, magenta, and yellow are at three other corners; black is at the origin; and white is at the
corner farthest from the origin. In this model, the gray scale (points of equal RGB values)
extends from black to white along the line joining these two points. The different colors in
this model arc points on or inside the cube, and are defined by vectors extending from the
origin. For convenience, the assumption is that all color values have been normalized so that
the cube shown in the figure is the unit cube. That is, all values of R, G. and B are assumed
to be in the range [0, 1].

Digital Image Processing by P Sudheer Chakravarthi 4


CHAPTER-4 Color Image Processing

Fig. Schematic of the RGB color cube

Images represented in the RGB color model consist of three component images, one
for each primary color. When fed into an RGB monitor, these three images combine on the
phosphor screen to produce a composite color image.

Fig. Generating the RGB image of the cross Sectional color plane

The number of bits used to represent each pixel in RGB space is called the pixel
depth. Consider an RGB image in which each of the red, green, and blue images is an 8-bit
image. Under these conditions each RGB color pixel [that is, a triplet of values (R, G, B)] is
said to have a depth of 24 bits C image planes times the number of bits per plane). The term
full-color image is used often to denote a 24-bit RGB color image. The total number of
colors in a 24-bit RGB image is (28)3 = 16,777,216.

Digital Image Processing by P Sudheer Chakravarthi 5


CHAPTER-4 Color Image Processing

4.2.2. The CMY and CMYK Color models


Cyan, magenta, and yellow are the secondary colors of light or, alternatively, the
primary colors of pigments. For example, when a surface coated with cyan pigment is
illuminated with white light, no red light is reflected from the surface. That is, cyan subtracts
red light from reflected white light, which itself is composed of equal amounts of red, green,
and blue light. Most devices that deposit colored pigments on paper, such as color printers
and copiers, require CMY data input or perform an RGB to CMY conversion internally. This
conversion is performed using

Where, again, the assumption is that all color values have been normalized to the
range [0, 1]. The above equation demonstrates that light reflected from a surface coated with
pure cyan does not contain red (that is, C = 1 — R in the equation). Similarly, pure magenta
does not reflect green, and pure yellow does not reflect blue. So, the RGB values can be
obtained easily from a set of CMY values by subtracting the individual CMY values from 1.
Equal amounts of the pigment primaries, cyan, magenta, and yellow should produce black. In
practice, combining these colors for printing produces a muddy-looking black. So, in order to
produce true black, a fourth color, black is added, giving rise to the CMYK color model.

4.2.3. HSI color model


When humans view a color object, we describe it by its hue, saturation, and
brightness. Hue is a color attribute that describes a pure color (pure yellow, orange, or red),
whereas saturation gives a measure of the degree to which a pure color is diluted by white
light. Brightness is a subjective descriptor that is practically impossible to measure. It
embodies the achromatic notion of intensity and is one of the key factors in describing color
sensation.
Intensity (gray level) is a most useful descriptor of monochromatic images. This
quantity definitely is measurable and easily interpretable. The HSI (hue, saturation, intensity)
color model, decouples the intensity component from the color-carrying information (hue and
Saturation) in a color image. As a result, the HSI model is an ideal tool for developing image
processing algorithms based on color descriptions that are natural and intuitive to humans.

Digital Image Processing by P Sudheer Chakravarthi 6


CHAPTER-4 Color Image Processing

In the following figure the primary colors are separated by 120° and the secondary
colors are 60° from the primaries, which means that the angle between secondaries is also
120°.

Fig. The relation between RGB and HSI color model

The hue of the point is determined by an angle from some reference point. Usually
(but not always) an angle of 0° from the red axis designates 0 hue, and the hue increases
counter clockwise from there. The saturation (distance from the vertical axis) is the length of
the vector from the origin to the point. The origin is defined by the intersection of the color
plane with the vertical intensity axis. The important components of the HSI color space are
the vertical intensity axis, the length of the vector to a color point, and the angle this vector
makes with the red axis.

Fig. Hue and saturation in the HSI color model

Digital Image Processing by P Sudheer Chakravarthi 7


CHAPTER-4 Color Image Processing

4.2.4. Conversion from RGB color model to HSI color model


Given an image in RGB color format, the H component of each RGB pixel is
obtained using the equation,

It is assumed that the RGB values have been normalized to the range [0, 1] and that
angle θ is measured with respect to the red axis of the HST space. The SI values are in [0,1]
and the H value can be divided by 360o to be in the same range.
4.2.5. Conversion from HSI color model to RGB color model
Given values of HSI in the interval [0,1 ], one can find the corresponding RGB values
in the same range. The applicable equations depend on the values of H. There are three
sectors of interest, corresponding to the 120° intervals in the separation of primaries.
RG sector (0o ≤ H <120°):
When H is in this sector, the RGB components are given by the equations

GB sector (120o ≤ H < 240o):


If the given value of H is in this sector, first subtract 120° from it.
H = H - 1200

Digital Image Processing by P Sudheer Chakravarthi 8


CHAPTER-4 Color Image Processing

Then the RGB components are

BR sector (240o ≤ H ≤ 360o):


If H is in this range, subtract 240o from it
H = H - 2400
Then the RGB components are

4.3. Pseudo color image processing


Pseudo color (also called false color) image processing consists of assigning colors to
gray values based on a specified criterion. The term pseudo or false color is used to
differentiate the process of assigning colors to monochrome images from the processes
associated with true color images. The process of gray level to color transformations is
known as pseudo color image processing. The two techniques used for pseudo color image
processing are,
 Intensity Slicing

 Gray Level to Color Transformation

4.3.1. Intensity Slicing:


The technique of intensity (sometimes called density) slicing and color coding is one
of the simplest examples of pseudo color image processing. If an image is interpreted as a 3-
D function (intensity versus spatial coordinates), the method can be viewed as one of placing
planes parallel to the coordinate plane of the image; each plane then "slices" the function in
the area of intersection. The following figure shows an example of using a plane at f(x, y) = li
to slice the image function into two levels.

Digital Image Processing by P Sudheer Chakravarthi 9


CHAPTER-4 Color Image Processing

Fig. Geometric interpretation of the intensity slicing technique


If a different color is assigned to each side of the plane shown in the above figure any
pixel whose gray level is above the plane will be coded with one color and any pixel below
the plane will be coded with the other. Levels that lie on the plane itself may be arbitrarily
assigned one of the two colors. The result is a two-color image whose relative appearance can
be controlled by moving the slicing plane up and down the gray-level axis.
In general, the technique may be summarized as follows. Let [0, L - 1 ] represent the
gray scale, level lo represent black [f(x, y) = 0], and level lL - 1 represent white
[f(x, y) = L - 1 ]. Suppose that P planes perpendicular to the intensity axis are defined at
levels l1, l2,….,lp.. Then, assuming that 0 < P < L – 1, the P planes partition the gray scale into
P + 1 intervals, V1, V2,..., Vp + 1. Gray-level to color assignments are made according to the
relation
f(x, y) = ck if f(x, y) є Vk
Where ck is the color associated with the kth intensity interval Vk defined by the
partitioning planes at l = k - 1 and l = k. An alternative representation defines the same
mapping according to the mapping function shown in the following figure. Any input gray
level is assigned one of two colors, depending on whether it is above or below the value of li.
When more levels are used, the mapping function takes on a staircase form.

An alternative representation of the intensity-slicing technique

Digital Image Processing by P Sudheer Chakravarthi 10


CHAPTER-4 Color Image Processing

4.3.2. Gray Level to Color Transformation:


This approach is to perform three independent transformations on the gray level of
any input pixel. The three results are then fed separately into the red, green, and blue
channels of a color television monitor. This method produces a composite image whose color
content is modulated by the nature of the transformation functions. These are transformations
on the gray-level values of an image and are not functions of position. In intensity slicing,
piecewise linear functions of the gray levels are used to generate colors. On the other hand,
this method can be based on smooth, nonlinear functions, which, as might be expected, gives
the technique considerable flexibility. The output of each transformation is a composite
image.

Fig. Functional block diagram for pseudo color image processing

4.4. Full color image processing


Full-color image processing approaches fall into two major categories. In the first
category, each component image is processed individually and then forms a composite
processed color image from the individually processed components. In the second category,
one works with color pixels directly. Because full-color images have at least three
components, color pixels really are vectors. For example, in the RGB system, each color
point can be interpreted as a vector extending from the origin to that point in the RGB
coordinate system.
Let c represent an arbitrary vector in RGB color space:

Digital Image Processing by P Sudheer Chakravarthi 11


CHAPTER-4 Color Image Processing

It indicates that the components of c are simply the RGB components of a color
image at a point. If the color components are a function of coordinates (x, y) by using the
notation

For an image of size M × N, there are MN such vectors, c(x, y), for x = 0,1, 2,...,M- l;
y = 0,1,2,...,N- 1. In order for per-color-component and vector-based processing to be
equivalent, two conditions have to be satisfied: First, the process has to be applicable to both
vectors and scalars. Second, the operation on each component of a vector must be
independent of the other components.

Fig. Spatial masks for (a)gray-scale and (b) RGB color images.

The above figure shows neighborhood spatial processing of gray-scale and full-color
images. Suppose that the process is neighborhood averaging. In Fig. (a), averaging would be
accomplished by summing the gray levels of all the pixels in the neighborhood and dividing
by the total number of pixels in the neighborhood. In Fig. (b), averaging would be done by
summing all the vectors in the neighborhood and dividing each component by the total
number of vectors in the neighborhood. But each component of the average vector is the sum
of the pixels in the image corresponding to that component, which is the same as the result
that would be obtained if the averaging were done on a per-color-component basis and then
the vector was formed.

Digital Image Processing by P Sudheer Chakravarthi 12


CHAPTER-4 Color Image Processing

4.5. Color Transformations


Color transformations deal with processing the components of a color image within
the context of a single color model, without converting components to different color space.

4.5.1. Formulation
We can model color transformations using the expression
g(x, y) = T[f(x, y)]
Where f(x, y) is color input image, g(x, y) is the transformed color output image and
T is the operator over a spatial neighborhood of (x, y). Each f(x, y) component is a triplet in
the chosen color space. For a given transformation the cost of converting from one color
space to another is also a factor to implement it. Hence, we wish to modifying intensity of an
image in different color spaces, using the transform
g(x, y) = k f(x, y)
When only data at one pixel is used in the transformation, we can express the transformation
as:
si = Ti( r1, r2,……,rn) i= 1, 2, …, n
Where ri = color component of f(x, y)
si = color component of g(x, y)

In RGB color space,

In HSI color space,

In CMY color space,

Digital Image Processing by P Sudheer Chakravarthi 13


CHAPTER-4 Color Image Processing

4.5.2. Color Complements


Color complement replaces each color with its opposite color in the color circle of the
Hue component. This operation is analogous to image negative in a gray scale image. Color
complements are used to enhance the details in dark regions of a color image.

Fig. Complements on the Circle


4.5.3. Color Slicing
Color slicing is the process of highlighting a specific range of colors in an image is
useful for separating object from their surroundings. It is more complex than gray-level
slicing, due to multiple dimensions for each pixel. This can be done by selecting the region
that needs to be high spotted in a cube of width ’w’. The outside region must be mapped with
a neutral color. Then the transformation is given by

4.5.4. Tone and Color Corrections


Effectiveness of these transformations judged ultimately in print. But developed,
refined and evaluated on monitors. Need to maintain a high degree of color consistency
between monitors used and eventual output devices. Device-independent color model,
relating the color gamut’s of the monitors and output devices. The success of this approach is
a function of the quality of the color profiles used to map each device to the model and the

Digital Image Processing by P Sudheer Chakravarthi 14


CHAPTER-4 Color Image Processing

model itself. The model of choice for many color management system (CMS) is the CIE
L*a*b model.

Like the HIS system, the L*a*b system is an excellent decoupler of intensity
(represented by lightness L*) and color (represent by a* for red minus green and b* for green
minus blue). The tonal range of an image, also called its key type, refer to its general
distribution of color intensities. Most of the information in high-key images are located
predominantly at low intensities; middle-key images lie in between.
4.5.5. Histogram Processing
Histogram processing transformations can be applied to color images in an automated
way. As might be expected, it is generally unwise to histogram equalize the component of a
color image independently. This results in erroneous color. A more logical approach is to
spread the color intensities uniformly, leaving the colors themselves (e.g., hues) unchanged.
The HSI color space is ideally suited to this type of approach.

Fig. Histogram Equalization in the HSI Color Space

Digital Image Processing by P Sudheer Chakravarthi 15


CHAPTER-4 Color Image Processing

4.6. Color segmentation process


Segmentation is a process that partitions an image into regions and partitioning an image into
regions based on color is known as color segmentation.
Segmentation in HSI Color Space:
If anybody wants to segment an image based on color, and in addition, to carry out
the process on individual planes. It is natural to think first of the HSI space because color is
conveniently represented in the hue image. Typically, saturation is used as a masking image
in order to isolate further regions of interest in the hue image. The intensity image is used
less frequently for segmentation of color images because it carries no color information.
Segmentation in RGB Vector Space:
Although, working in HSI space is more intuitive, segmentation is one area in which
better results generally are obtained by using RGB color vectors. The approach is
straightforward. Suppose that the objective is to segment objects of a specified color range in
an RGB image. Given a set of sample color point’s representative of the colors of interest, we
obtain an estimate of the "average" color that we wish to segment. Let this average color be
denoted by the RGB vector a. The objective of segmentation is to classify each RGB pixel in
a given image as having a color in the specified range or not. In order to perform this
comparison, it is necessary to have a measure of similarity. One of the simplest measures is
the Euclidean distance. Let z denote an arbitrary point in RGB space. z is similar to a if the
distance between them is less than a specified threshold, Do. The Euclidean distance between
z and a is given by

Where the subscripts R, G, and B, denote the RGB components of vectors a and z.
The locus of points such that D(z, a) ≤ Do is a solid sphere of radius Do. Points contained
within or on the surface of the sphere satisfy the specified color criterion; points outside the
sphere do not. Coding these two sets of points in the image with, say, black and white,
produces a binary segmented image.

Digital Image Processing by P Sudheer Chakravarthi 16


CHAPTER-4 Color Image Processing

A useful generalization of previous equation is a distance measure of the form


D (z, a) = [(z-a) T C-1 (z-a)] 1/2
Where C is the covariance matrix1 of the samples representative of the color to be
segmented and the above equation represents an ellipse with color points such that D(z, a ) ≤
Do.

PREVIOUS QUESTIONS
1. Explain about RGB, CMY and CMYK color models?
2. What is Pseudocolor image processing? Explain.
3. Explain about color image smoothing and sharpening.
4. Explain about histogram processing of color images.
5. Explain the procedure of converting colors from RGB to HSI and HSI to RGB.
6. Discuss about noise in color images.
7. Explain about HSI colour model.
8. Consider the following RGB triplets. Convert each triplet to CMY and YIQ
i) (1 1 0) ii) (1 1 1) iii). ( 1 0 1 )
9. Explain in detail about how the color models are converted to each other.
10. Discuss about color quantization and explain about its various types.
11. What are color complements? How they are useful in image processing.
12. What is meant by Luminance, brightness, Radiance & trichromatic Coefficients.

Digital Image Processing by P Sudheer Chakravarthi 17

You might also like