week 5 - alexandru ioan cuza universityancai/dip/curs/dip w5 2020.pdf · 2020. 11. 2. · week 5....

104
Digital Image Processing Week 5

Upload: others

Post on 23-Aug-2021

5 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 5

Page 2: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The Hit-or-Miss Transformation

The morphological hit-or-miss transformation is a basic tool for shape detection.

Consider the set A from Figure 9.12 consisting of three shapes (subsets) denoted

C, D, and E. The objective is to locate one of the shapes, say, D.

Let the origin of each shape be located at its center of gravity. Let D be enclosed

by a small window, W. The local background of D with respect to W is defined

as the set difference (W-D) (Figure 9.12(b)). Figure 9.12(c) shows the

complement of A. Fig. 9.12(d) shows the erosion of A by D. Figure 9.12(e)

shows the erosion of the complement of A by the local background set (W-D).

From Figures 9.12(d) and (e) we can see that the set of location for which D

exactly fits inside A is the intersection of the erosion of A by D and the erosion

of Ac by (W-D) as shown in Figure 9.12(f).

Page 3: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

If B denotes the set composed of D and its background, the match (or the set of

matches) of B in A, denoted A B is:

( ) ( )c

A B A D A W D

Page 4: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 5: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

We can generalize the notation by letting B = (B1, B2), where B1 is the set

formed from elements of B associated with an object and B2 is the set of

elements of B associated with the corresponding background (B1=D, B2=W-D)

in the preceding example).

1 2( )

cA B A B A B

The set A B contains all the (origin) points at which, simultaneously, B1 found

a match (“hit”) in A and B2 found a match in Ac. Taking into account the

definition and properties of erosion we can rewrite the above relation as:

1 2( ) ( )A B A B A B

The above three equations for A B are referred as the morphological hit-or-

miss transform.

Page 6: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Some Basic Morphological Algorithms

When dealing with binary images, one of the principal applications of

morphology is in extracting image components that are useful in the

representation and the description of shape. We consider morphological

algorithms for extracting boundaries, connected components, the convex hull,

and the skeleton of a region.

The images are shown graphically with 1s shaded and 0s in white.

Boundary Extraction

The boundary of a set A, denoted β(A), can be obtained by first eroding A by B

and then performing the set difference between A and its erosion.

( )A A A B

where B is a suitable structuring element.

Page 7: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 8: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 9: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Filling Holes

A hole may be defined as a background region surrounded by a connected

border of foreground pixels. We present an algorithm based on set dilation,

complementation, and intersection for filling holes in an image.

Let A denote a set whose elements are 8-connected boundaries, each boundary

enclosing a background region (i.e. a hole). Given a point in each hole, the

objective is to fill all the holes with 1s.

We form an array, X0, of 0s (the same size as the array containing A), except at

the location in X0 corresponding to the given point in each hole, which is set to

1. The following procedure fills all the holes with 1s:

1, 1,2,3, ...

c

k kX X B A k

Page 10: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

where B is the symmetric structuring element in Figure 9.15(c). The algorithm

terminates at iteration step k if Xk=Xk-1. The set Xk then contains all the filled

holes. The set union of Xk and A contains all the filled holes and their

boundaries.

Page 11: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 12: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Extraction of Connected Components

Extraction of connected components from binary images is important in many

automated image analysis applications.

Let A be a set containing one or more connected components. Form an array

X0 (of the same size as the array containing A) whose elements are 0s

(background values), except at each location known to correspond to a point in

each connected component in A, which we set to 1 (foreground value). The

objective is to start with X0 and find all the connected components.

The procedure that accomplishes this task is the following:

1( ) , 1,2,3, ...

k kX X B A k

where B is a suitable structuring element. The procedure terminates when Xk =

Xk-1, with Xk containing all connected components of the input image.

Page 13: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 14: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 15: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Figure 9.18(a) shows an X-ray image of a chicken breast that contains bone

fragment. It is of considerable interest to be able to detect such objects in

processed food befor packing and/or shiping. In this case, the density of the

bones is such that their normal intensity values are different from the

background. This makes extraction of the bones from the background a simple

matter by using a single threshold. The result is the binary image in Figure

9.18(b). We can erode the thresholded image so that only objects of

„significant” size remain. In this example, we define as significant any object

that remains after erosion with a 5×5 structuring elemnt of 1s. The result of

erosion is shown in Figure 9.18(c). The next step is to analyse the objects that

remain. We identify these objects by extracting the connected components in the

image. There are a total of 15 connected components, with four of them being of

Page 16: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

dominant size. This is enough to determine that significant undesirable objects

are containd in the original image.

Thinning, thickening

( ) ( )cA B A A B A A B - thinning

1 2{ , , , }nB B B B

Bi is the rotated version of Bi-1

1 2{ } ( (( ) ) )i nA B A B B B

Thickening

( )A B A A B

1 2{ } ( (( ) ) )i nA B A B B B

Page 17: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 18: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 19: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 20: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 21: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Image Processing Color Image Processing

Color Image Processing

Color is very important characteristic of an image that in most cases

simplifies object identification and extraction form a scene. Human eye can

discern thousands of color shades and intensities and only two dozen shades of

gray.

Color image processing is divided in 2 major areas: full-color (images acquired

with a full-color sensor) and pseudo-color (gray images for which color is

assigned) processing.

The colors that humans can perceive in an object are determinde by the nature

of the light reflected from the object.Visible light is composed of a relatively

narrow band of frequencies in the electromagnetic spectrum (390nm to750nm).

Page 22: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

A body that reflects light that is balanced in all visible wavelengths appears

white to the observer. A body that favors reflectance in a limited range of the

visible spectrum exhibits some shades of color.

For example, blue objects reflect light with wavelengths from 450 to 475 nm,

while absorbing most of the energy of other wavelengths.

Page 23: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

How to characterize light? If the light is achromatic (void of color) its only

attribute is its intensity (or amount) – determined by levels of gray (black-grays-

white).

Chromatic light spans the electromagnetic spectrum from approximately 400 to

720 nm. Three basic quantities are used to describe the quality of a chromatic

light source: radiance, luminance, and brightness.

- Radiance is the total amount of energy that flows from the light source

(usually measured in watts).

- Luminance (measured in lumens – lm) gives a measure of the amount of

energy an observer percieves from a light source. For example, the light

emitted from a source operating in the infrared region of the spectrum could

Page 24: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

have significant energy (radiance), but an observer would hardly perceive it

(the luminance is almost zero).

- Brightness is a subjective descriptor, that cannot be measured, it embodies

the achromatic notion of intensity and is a factor describing color sensation.

Cones are the sensors in the eye responsible for color vision. It has been

established that the 6 to 7 million cones in the human eye can be devided into

three principal sensing categories, corresponding roughly to red, green, and blue.

Approximately 65% of all cones are sensitive to red light, 33% are sensitive to

green light, an only about 2% are sensitive to blue (but the blue cones are the

most sensitive).

Page 25: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Due to these absorbtion characteristics of the human eye, colors are seen as

variable combinations of the so-called primary colors : red (R), green (G), and

blue (B).

Page 26: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

For the purpose of standardization, the CIE (Commission Internationale de

l’Eclairage) designated in 1931 the following specific wavelength values to the

three primary colors: blue= 435.8 nm, green = 546.1 nm, and red=700 nm. The

CIE standards correspond only approximately with experimental data.

These three standard primary colors, when mixed in various intensity

proportions, can produce all visible colors.

The primary colors can be added to produce the secondary colors of light –

magenta (red+blue), cyan (green+blue), and yellow (red+green). Mixing the

three primaries, or a secondary with its opposite primary color in the right

intensities produces white light.

We must differentiate between the primary colors of light and the primary

colors of pigments. A primary color for pigments is one that substracts or absorb

Page 27: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

a primary color of light and reflects or transmits the other two. Therefore, the

primary colors of pigments are magenta, cyan, and yellow, and the secondary

colors are red, green, and blue.

Page 28: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The characteristics usually used to distinguish one color from another are

brightness, hue, and saturation.

Brightness embodies the achromatic notion of intensity. Hue is an attribute

associated with the dominant wavelength in a mixture of light waves. Hue

represents dominat color as percieved by an observer (when we call an object to

be red, orange or yellow we refer to its hue). Saturation refers to the relative

purity or the amount of white light mixed with a hue. The pure spectrum colors

are fully saturated. Color such as pink (red+white) and lavender (violet+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.

Page 29: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The amounts of red, green, and blue needed to form any particular color are

called the tristimulus values and are denoted X, Y and Z, respectively. A color is

specified by its trichromatic coefficients, defined as:

Xx

X Y Z

Yy

X Y Z

Zz

X Y Z

1x y z

Page 30: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

For any wavelength of light in the visible spectrum, the tristimulus values

needed to produce the color coresponding to that wavelength can be obtained

from the existing curves or tables.

Another approach for specifying colors is to use the CIE chromaticity

diagram, which shows color compositin as a function of x (red) and y (green); z

(blue) is obtained from relation z = 1-x-y.

Page 31: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 32: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The positions of the various spectrum colors (from violet at 380 nm to red at

780 nm) are indicated around the boundary of the tongue-shaped chromaticity

diagram.

The chromaticity diagram is useful for color mixing because a straight-line

segment joining any two points in the diagram defines all the different color

variation that can be obtained by combining these two colors. This procedure

can be extended to three colors: to triangle determined by the three color-points

on the diagram embodies all the possible colors that can be obtained by mixing

the three colors.

Page 33: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 34: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Models

A color model (color space or color system) is a specification of a coordinate

system and a subspace within that system where each color is represented by a

single point.

http://www.colorcube.com/articles/models/model.htm

Most color models in use today are oriented either toward hardware (color

monitors or printers) or toward applications where color manipulation is a goal.

The most commonly used hardware-oriented model is RGB (red-green-blue) –

for color monitors, color video cameras.

The CMY (cyan-magenta-yellow) and CMYK (cyan-magenta-yellow-black)

models are in use for color printing.

Page 35: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The HSI (hue-saturation-intensity) model corespond with the way humans

describe and interpret colors. The HSI model has the advantage that it decoupes

the color and gray-scale information in an image, making it suitable for using

the gray-scale image processing techniques.

The RGB Color Model

In the RGB model, each color appears decomposed in its primary color

components: red, green, blue. This model is based on a Cartesian coordinate

system. The color subspace of interest is the unit cube (Figure 6.7), in which the

primary and the seconadary colors are at the corners; black is at the origin, and

white is at the corner farthest from the origin.

Page 36: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The gray scale (point of equal RGB values) extends from black to white along

the line joining these two points. The different colors in this model are points on

or inside the cube, and are defined by vectors extending from the origin.

Page 37: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Images represented in the RGB color model consist of three component images,

one for each primary color. 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 are an 8-bit image. In this case, each RGB color

pixel has a depth of 24 bits. 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

Page 38: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

3

82 16.777.216

A convenient way to view these colors is to generate color planes (faces or cross

sections of the cube).

A color image can be acquired by using three filters, sensitive to red, green, and

blue.

Page 39: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Because of the variety of systems in use, it is of considerable interest to have a

subset of colors that are likely to be reproduced faithfully, resonably

independently of viewer hardware capabilities. This subset of colors is called the

set of safe RGB colors, or the set of all-systems-safe colors. In Internet

applications, they are called safe Web colors or safe browser colors.

We assume that 256 colors is the minimum number of colors that can be

reproduced faithfully by any system. Forty of these 256 colors are known to be

Page 40: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

processed differently by varoius operating system. We have 216 colors that are

common to most systems, and are the safe colors, especially in Internet

applications. Each of the 216 safe colors has a RGB representation with:

, , 0,51,102,153,204,255R G B

We have (6)3=216 possible color values. It is costumary to express these values

in the hexagonal number system.

Each safe color is formed from three of the two digit hex numbers from the

above table. For example purest red if FF0000. The values 000000 and FFFFFF

represent black and white respectively.

Page 41: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Figure 6.10(a) shows the 216 safe colors, organized in descending RGB values.

Figure 6.10(b) shows the hex codes for all the possible gray colors in the 216

safe color system.

Figure 6.11 shows the RGB safe-color cube.

Page 42: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

http://www.techbomb.com/websafe/

The CMY and CMYK Color Models

Cyan, magenta, and yellow are the secondary colors of light but the primary

color of pigments. For example, when a surface coated with yellow pigment is

illuminated with white light, no blue light is reflected from the surface. Yellow

substracts blue light from reflected white light (which is composed of equal

amounts of red, green, and blue light).

Page 43: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Most devices that deposit color pigments on paper, such as color printers and

copiers, require CMY data input and perform RGB to CMY conversion.

Assuming that the color values were normalized to range [0,1], this conversion

is:

1

1

1

C R

M G

Y B

From this equation we can easily deduce, that pure cyan does not reflect red,

pure magenta does not reflect green, and pure yellow does not reflect blue.

Equal amount of pigments primary, cyan, magenta, and yellow should produce

black. In practice, combining these colors for printing produces a muddy-

looking black. In order to produce true black (which is the predominant color in

printing), a fourth color, black, is added, giving rise to the CMYK color model.

Page 44: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 45: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The HSI Color Model

The RGB, CMY, and other similar color models are not well suited for

describing colors in terms that are practical for human interpretation.

We (humans) describe a color by its hue, saturation and brightness. Hue is a

color attribute that describes a pure color, saturation gives a measure of the

degree to which a pure color is diluted by white light and brightness is a

subjective descriptor that embodies the achromatic notion of intensity.

The HSI (hue, saturation, intensity) color model, decouples the intensity

component from the color information (hue and saturation) in a color image.

What is the link between the RGB color model and HSI color model? Consider

again the RGB unit cube. The intensity axis is the line joining the black and the

white vertices. Consider a color point in the RGB cube. Let P be a plane

Page 46: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

perpedicular to the intensity axis and containing the color point. The intersection

of this plane with the intensity axis gives us the intensity of the color point. The

saturation (purity) of the considered color point increases as a function of

distance from the intensity axis (the saturation of the point on the intensity axis

is zero).

In order to determine how hue can be linked to a given RGB point, consider a

plane defined by black, white and cyan. The intensity axis is also included in

this plane. The intersection of this plane with the RGB-cube is a triangle. All

point contained in this triangle would have the same hue (i.e. cyan).

Page 47: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The HSI space is represented by a vertical intensity axis and the locus of color

points that lie on planes perpedicular to this axis. As the planes move up and

down the intensity axis, the boundary defined by the intersection of this plane

with the faces of the cube have either triangular or hexagonal shape.

Page 48: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

In the plane shown in Figure 6.13(a) primary colors are separated by 120º. The

secondary colors are 60º from the primaries. The hue of the point is determined

Page 49: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

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 countercloclwise 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.

Converting colors from RGB to HSI

if

if 360

B GH

B G

2

( ) ( )arccos

2 ( ) ( )( )

R G R B

R G R B G B

Page 50: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

31 min{ , , }S R G B

R G B

1

3I R G B

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 HSI space in Figure

6.13. Hue can be normalized to the range [0,1] by dividing it to 360º. The other

two HSI components are in this range if the RGB values are in the interval [0,1].

R=100, G=150, B=200 H=210º, S=1/3, I=150/255=0.588

Page 51: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Converting colors from HSI to RGB

Given values of HSI we now want to find the corresponding RGB values in the

same range.

RG sector (0º ≤ H < 120º)

(1 )

cos1

cos(60 )

3 ( )

B I S

S HR I

H

G I R B

Page 52: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

GB sector (120º ≤ H < 240º)

(1 )

cos120 , 1

cos(60 )

3 ( )

R I S

S HH H G I

H

B I R G

BR sector (120º ≤ H < 240º)

(1 )

cos240 , 1

cos(60 )

3 ( )

G I S

S HH H B I

H

R I G B

Page 53: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Lab color space

The effectiveness of such transformations is judged ultimately in print. The

transformations are developed and evaluated on monitors. It is necessary to have

a high degree of consistency between the monitors and the output devices. This

is best accomplished with a device-independent color model that relates the

color gamut of the monitors and output devices, as well as any other devices

being used, to one another. The model of choice for many color management

systems (CMS) is the CIE L*a*b* model, also called CIELAB. The L*a*b*

color components are given by the following equations:

Page 54: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

* 116 16W

YL h

Y

* 500W W

X Ya h h

X Y

* 200W W

Y Zb h h

Y Z

3 0.008856

( ) 167.787 0.008856

116

q q

h qq q

Page 55: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

, ,W W W

X Y Z are reference tristimulus values – typically the white of a

perfectly reflecting diffuser under CIE standard D65 illumination

( 0.3127 , 0.33290 , 1x y z x y ).

The L*a*b* color space is colorimetric (i.e. colors perceived as matching are

encoded identically), perceptually uniform (i.e. color differences among various

hues are perceived uniformly), and device independent. Like the HSI system, the

L*a*b* system is an excellent decoupler of intensity (represented by lightness

L*) and color (represented by a* for red minus green and b* for green minus

blue), making it useful in both image manipulation (tone and contrast editing)

and image compression applications.

Page 56: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Other color spaces

YIQ – for the NTSC (National Television System Committee) television system

in US

Y – luminance

I (in-phase), Q (quadrature) – chrominance

YUV – for the PAL (Phase Alternation Line) and SECAM (Séquentiel Couleur

à Mémoire) television system in Europe

(I, Q) – obtained by rotating (U,V)

YCbCr – digital video transmission

More about color spaces in: Andreas Koschan, Mongi Abidi, Digital Color

Image Processing, Wiley, 2008

Page 57: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Difference

RGB, CMY, Lab – Euclidean distance

HSI - F1=(H1, S1, I1), F2=(H2, S2, I2)

HSI

if

if

2 2

1 2 1 2

2 2

1 2 1 2

1 2 1 2

1 2 1 2

( , ) ( ) ( ) ,

2 cos

2

d F F I C I I I

C S S S S

H H H H

H H H H

Page 58: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

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 main use of

pseudo-color is for human visualization and interpretation of gray-scale events

in an image or sequence of images.

Intensity (Density) Slicing

If an image is viewed as a 3-D function, the method can be described as one of

placing planes parallel to the coordinate plane of the image; each plane then

“slices” the function in the area of intersection.

Page 59: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

The plane at ( , )i

f x y l slices the image function into two levels. If a

different color is assigned to each side of the plane, any pixel whose intensity

level is above the plane will be coded with one color and any pixel below the

plane will be coded with other color. Levels that lie on the plane itself may be

arbitrarily assigned one of the two colors. The result is a two color image whose

Page 60: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

relative appearance can be controlled by moving the slicing plane up and down

the intensity axis.

Let [0, L-1] represent the gray scale, let l0 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 , 0<P<L-1. The P planes partition

the gray scale into P+1 intervals, V1, V2, …, VP+1. Intensity to color assignments

are made according to the relation:

if ( , ) ( , )k k

f x y c f x y V .

Page 61: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Measurements of rainfall levels with ground-based sensors are difficult and

expensive, and total rainfall figures are even more difficult to obtain because a

significant portion of precipitations occurs over the ocean. One way to obtain

these figures is to use a satellite. The TRMM (Tropical Rainfall Measuring

Page 62: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Mission) satellite utilizes, among others, three sensors specially designed to

detect rain: a precipitation radar, a microwave imager, and a visible and infrared

scanner. The results from the various rain sensors are processed, resulting in

estimates of average rainfall over a given time period in the area monitored by

the sensors. From these estimates, it is not difficult to generate gray-scale

images whose intensity values correspond directly to rainfall, with each pixel

representing a physical land area whose size depends on the resolution of the

sensors.

Page 63: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 64: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Basics of Full-Color Image Processing

3 4

( , ) ( , )

: / , ( , ) ( , ) ( , )

( , ) ( , )

( , )

( , )( , )

( , )

( , )

R

G

B

c x y R x y

f D f x y c c x y G x y

c x y B x y

C x y

M x yf x y c

Y x y

K x y

Page 65: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Transformations

- processing the components of a color image within the context of a single-

color model

( , ) ( , )g x y T f x y

1 2( , , ..., ) , 1,2, ..., ( ( , ) , ( , ) )

i i ns T r r r i n f x y r g x y s

ri, si are the color components of f(x, y) and g(x, y), n is the number of color

components, and {T1, T2,…, Tn} is a set of transformations or color mapping

functions that operate on ri to produce si. (n=3 or n=4)

Page 66: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 67: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

In theory, any transformation can be performed in any color model. In practice,

some operations are better suited to specific color models.

Suppose we wish to modify the intensity of a color image, using

( , ) ( , ) , 0 1g x y k f x y k

In the HSI color space, this can be done with:

s1= r1 , s2= r2 , s3=k r3

In the RGB/CMY color model all components must be transformed

s1= kr1 , s2= kr2 , s3=kr3 (RGB)

si = kri+(1-k) , i=1,2,3 (CMY)

Although the HSI transformation involves the fewest number of operations, the

costs for converting an RGB or CMY(K) image to the HSI color space are much

bigger than the transformations.

Page 68: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 69: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Complements

The hues directly opposite one another on the above color circle are called

complements (analogous to the gray-scale negatives).

Page 70: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Unlike the intensity transformation, the RGB complement transformation

functions used in this example do not have straightforward HSI space

Page 71: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

equivalent. The saturation component of the complement cannot be computed

from the saturation component of the input image alone.

Color Slicing

Highlighting a specific range of colors in an image is useful for separating

objects from their surroundings. The basic idea is either to:

- display the colors of interest so they stand out from the background

- use the region defined by the colors as a mask for further processing.

One of the simplest ways to “slice” a color image is to map the colors outside

some range of interest to a neutral color. If the colors of interest are enclosed

by a cube (or hypercube, if n>3) of width W and centered at a prototypical

(e.g. average) color with components 1 2, , ...,

na a a the set of

transformations is:

Page 72: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

if

otherwise

0.5 , 1, 1,2, ...,2

j j

i

i

Wr a j n

s i n

r

These transformations highlight the colors around the prototype by forcing all

other colors to the midpoint of the reference color space (an arbitrarily chosen

neutral point).

For the RGB color space, for example, a suitable neutral point is middle gray or

color (0.5, 0.5, 0.5).

If a sphere is used to specify the colors of interest, the transformations are:

Page 73: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

if

otherwise

2 2

0

1

0.5 ( ), 1,2, ...,

n

j j

ji

i

r a Rs i n

r

where R0 is the radius of the enclosing sphere and 1 2, , ...,

na a a are the

components of its center.

Page 74: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 75: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Histogram Processing

It is not advisable to histogram equalize the components of a color image

independently. This can produce wrong colors. A more logical approach is to

spread the color intensity uniformly, leaving the colors (e.g., hues) unchanged.

The HSI color space is ideally suited for this type of approach.

The unprocessed image contains a large number of dark colors that reduce the

median intensity to 0.36. Histogram equalizing the intensity component, without

Page 76: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

altering the hue and saturation produced image Figure 6.37(c). The image is

brighter. Figure 6.37(d) was obtained by increasing also the saturation

component.

Color Image Smoothing

Let Sxy denote a neighborhood centered at (x,y) in an RGB color image. The

average of the RGB component vectors in this neighborhood is:

( , )

1( , ) ( , )

xys t S

c x y c s tK

( , )

( , )

( , )

1( , )

1( , ) ( , )

1( , )

xy

xy

xy

s t S

s t S

s t S

R s tK

c x y G s tK

B s tK

Page 77: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 78: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 79: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Color Image Sharpening

2( , ) ( , ) ( , )g x y f x y c f x y

2

2 2

2

( , )

( , ) ( , )

( , )

R x y

c x y G x y

B x y

Page 80: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Image Compression

Image compression is the art and science of reducing the

amount of data required to represent an image.

Consider a two-hour standard definition (SD) television

movie using 720480 24 bit pixel arrays. A digital movie is

a sequence of video frames in which each frame is a full-color

still image. Because video players must display the frames

sequentially at rates 30 fps (frames per second), SD digital

video must be accessed at:

Page 81: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

frames pixels bytesbytes/sec

sec frame pixel30 (720 480) 3 31.104.000

and a two-hour movie consist of

bytes sechours bytes( GB)

sec hour

2 1131.104.000 (60 ) 2 2.24 10 224

To put a two-hour movie on a DVD, each frame must be

compressed by a factor of 26.3(on average). The compression

must be even higher for high definition (HD) television where

image resolution reach 1920108024 bit/image.

Page 82: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Fundamentals

The term data compression refers to the process of reducing

the amount of data required to represent a given quantity of

information. Data and information are not the same thing;

data are the means by which information is expressed.

Because various amounts of data can be used to represent the

same amount of information, representations that contain

irrelevant or repeated information are said to contain

redundant data.

Page 83: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Let b and b′ denote the number of bits in two representations

of the same information, the relative data redundancy R of

the representation with b bits is:

11R

C

Where C, commonly called the compression ratio is

bC

b

If C=10 - the larger representation has 10 bits of data for

every 1 bit of data in the smaller representation. The

Page 84: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

corresponding relative data redundancy of the larger

representation is 0.9 (R=0.9), indicating that 90% of its data

is redundant.

In the context of digital image compression, b usually is the

number of bits needed to represent an image as a 2-D array of

intensity values. Two-dimensional intensity arrays (far from

optimal) suffer from three principal types of data

redundancies:

Page 85: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

1. Coding redundancy. A code is a system of symbols

(letters, numbers, bits…) used to represent a body of

information or set of events. Each piece of information

or event is assigned a sequence of code symbols, called a

code word. The number of symbols in each code word is

its length. The 8-bit codes that are used to represent the

intensities in most 2-D intensity arrays contain more bits

than are needed to represent the intensities.

Page 86: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

2. Spatial and temporal redundancy. Because the pixels

of most 2-D intensity arrays are correlated spatially (i.e.

each pixel is similar to or dependent on neighboring

pixels), information is unnecessarily replicated in the

representations of correlated pixels. In a video sequence,

temporally correlated pixels (i.e., those similar to or

dependent on pixels in nearby frames) also duplicate

information.

Page 87: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

3. Irrelevant information. Most 2-D intensity arrays

contain information that is ignored by the human eye.

This information is redundant in the sense that it is not

used.

Compression is achieved when one or more redundancy is

reduced or eliminated.

Page 88: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 89: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Code Redundancy

Assume that a discrete random variable rk in the interval

[0, L-1] is used to represent the intensities of an MN image

and that each rk occurs with probability p(rk).

( ) , 0,1,2,..., 1k

k

np r k L

M N

Where L is the number of intensity values, and nk is the

number of times that the k-th intensity appears in the image.

If the number of bits used to represent each value of rk is l(rk),

Page 90: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

then the average number of bits required to represent each

pixel is:

1

0

( ) ( )L

avg k k

k

L l r p r

The total number of bits required to represent an MN image

is avg

MNL . If the intensities are represented using a natural

m-bit fixed-length code, avg

L m .

Consider image in Figure 8.1 (a) (M=N=256) and the coding

Table 8.1.

Page 91: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

For Code 1 8avg

L . For Code 2 we have:

bits0.25 2 0.47 1 0.25 3 0.03 3 1.81avg

L

The total number of bits needed to represent the entire image

is 256 256 1.81 118.621avg

MNL .

Page 92: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

256 256 8 84.42

256 256 1.81 1.81C

1 11 1 0.774

4.42R

C

Thus, 77.4% of the data in the original 8-bit 2-D intensity

array is redundant.

The compression achieved by code 2 results from assigning

fewer bits to the more probable intensity values than to the

less probable ones, thus resulting a variable-length code. The

best fixed-length code that can be assigned to the intensities

Page 93: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

of the image in Figure 8.1(a) is the natural 2-bit counting

sequence {00, 01, 10, 11} but the resulting compression is

only C=8/2=4:1 which is about 10% less than the 4.42:1

compression of the variable-length code.

Coding redundancy is present when the codes assigned to a

set of events (such as intensity values) do not take full

advantage of the probabilities of the events. Coding

redundancy is almost always present when the intensities of

an image are represented using a natural binary code. Most

Page 94: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

images are composed of objects that have a regular and

somewhat predictable morphology (shape) and reflectance,

and are sampled so that the objects being depicted are much

larger than the picture elements. For most images, certain

intensities are more probable than others (that is, the

histograms of most images are not uniform). A natural binary

encoding assigns the same number of bits to both the most

and least probable values, failing to minimize the value of

avgL and resulting in coding redundancy.

Page 95: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Page 96: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Spatial and Temporal Redundancy

Consider the computer-generated image in Figure 8.1(b). In

the corresponding 2-D intensity array:

All 256 intensities are equally probable

Because the intensity of each line was selected randomly,

its pixels are independent of one another in the vertical

direction

Page 97: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Because the pixels along each line are identical, they are

maximally correlated (completely dependent on one

another) in the horizontal direction.

The first observation tells us that this image cannot be

compressed by variable-length coding alone. Observation 2

and 3 reveal a significant spatial redundancy that can be

eliminated, for instance, by representing this image as a

sequence of run-length pairs, where each run-length pair

specifies the start of a new intensity and the number of

Page 98: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

consecutive pixels that have that intensity. A run-length based

representation compresses the original 2-D, 8-bit intensity

array by

256 256 8128 :1

256 2 8C

Each 256-pixel line of the original representation is replaced

by a single 8-bit intensity value and length 256 in the

run-length representation.

In most images, pixels are correlated spatially (in both x and

y) and in time (in case of video sequences). Because most

Page 99: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

pixels’ intensities can be predicted reasonably well from

neighboring intensities, the information carried by a single

pixel is small. Much of its visual contribution is redundant in

the sense that can be inferred from its neighbors. To reduce

the redundancy associated with spatially and temporally

correlated pixels, a 2-D intensity array must be transformed

into a more efficient but usually ‘non-visual’ representation.

Transformations of this type are called mappings. A mapping

is said to be reversible if the pixels of the original 2-D

Page 100: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

intensity array can be reconstructed without error from the

transformed data set; otherwise the mapping is said to be

irreversible.

Irrelevant Information

One of the simplest ways to compress a set of data is to

remove superfluous data from the set. In the context of DIP,

information ignored by the system which uses the image

(human eye, computer programs) are obvious candidates for

omission. Thus, the computer-generated image in Figure

Page 101: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

8.1(c), because it appears to be a homogeneous field of grey,

can be represented by its average intensity alone – a single

8-bit value. The original 2562568 bit intensity array is

reduced to a single byte; the resulting compression is

65.536:1.

Page 102: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Figure 8.3(a) shows the histogram of the image in Figure

8.1(c) – there are some intensity values (125 through 131)

actually present. The human visual system averages these

intensities, perceives only the average value, and ignores the

small changes in intensity that are present in this case.

Page 103: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

Figure 8.3(b), a histogram equalized version of the image in

Figure 8.1 (c), makes the intensity changes visible and reveals

two previously undetected regions of constant intensity.

If the image in Figure 8.1 (c) is represented by its average

value alone, this ‘invisible’ structure is lost.

The kind of redundancy can be eliminated because the

information itself is not essential for normal visual processing

and/or the intended use of the image. Because its omission

results in a loss of quantitative information, its removal is

Page 104: Week 5 - Alexandru Ioan Cuza Universityancai/DIP/curs/DIP w5 2020.pdf · 2020. 11. 2. · Week 5. Digital Image Processing Week 4 The Hit-or-Miss Transformation The morphological

Digital Image Processing

Week 4

commonly referred to as quantization (mapping of a broad

range of input values to a limited number of output values).

Because information is lost, quantization is an irreversible

operation.