0% found this document useful (0 votes)
11 views89 pages

Lect 3

The document discusses various point processing transformations in digital image processing, including linear, logarithmic, and power law transformations. It explains the applications and effects of these transformations, such as enhancing image contrast and adjusting intensity values. Additionally, it covers histogram analysis for grayscale and color images, including histogram equalization techniques to achieve uniform intensity distribution.

Uploaded by

techvention.ae
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)
11 views89 pages

Lect 3

The document discusses various point processing transformations in digital image processing, including linear, logarithmic, and power law transformations. It explains the applications and effects of these transformations, such as enhancing image contrast and adjusting intensity values. Additionally, it covers histogram analysis for grayscale and color images, including histogram equalization techniques to achieve uniform intensity distribution.

Uploaded by

techvention.ae
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
You are on page 1/ 89

Digital Image Processing

Week-3

1
Point Processing Transformations
 There are many different kinds of grey level
transformations
 Three of the most
common are shown
here
◼ Linear

⚫ Negative/Identity

◼ Logarithmic

⚫ Log/Inverse log

◼ Power law

⚫ nth power/nth root

2
Point Processing Example:
Negative Images
 Reverses the gray level order
 For L gray levels, the transformation has the
form:
s = ( L − 1) − r

 Negative images are useful for enhancing white or grey detail embedded in
dark regions of an image

3
Point Processing Example:
Negative Images

4
Logarithmic Transformations
 The general form of the log transformation is

s = c  log(1 + r )
 The log transformation maps a narrow range of low input grey level values into
a wider range of output values
 The inverse log transformation performs the opposite transformation

5
Logarithmic Transformations
 Properties
◼ For lower amplitudes of
input image the range of
gray levels is expanded
◼ For higher amplitudes of
input image the range of
gray levels is compressed

6
Logarithmic Transformations
 Application
◼ This transformation is suitable for the case when the
dynamic range of a processed image far exceeds the
capability of the display device (e.g. display of the
Fourier spectrum of an image)
◼ Also called “dynamic-range compression / expansion”

7
Logarithmic Transformations

Fourier spectrum: image values The result of log transformation


ranging from 0 to 1.5x106 with c = 1

8
Power Law Transformations
 Power law transformations have the following form

s = c  r
 Map a narrow range
of dark input values
into a wider range of
output values or vice
versa
 Varying γ gives a whole
family of curves

9
Power Law Transformations
 For < 1: Expands values of dark pixels, compress
values of brighter pixels
 For  > 1: Compresses values of dark pixels,
expand values of brighter pixels
 If =1 & c=1: Identity transformation (s = r)

 A variety of devices (image capture, printing, display)


respond according to a power law and need to be
corrected

 Gamma () correction


The process used to correct the power-law response
phenomena 10
Power Law Transformations: Gamma
Correction

11
Power Law Transformations
Contrast Enhancement

The images to the


right show a
magnetic resonance
(MR) image of a
fractured human
spine

12
Power Law Transformations
Contrast Enhancement
γ = 0.6
1
Transformed Intensities

0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Old Intensities

13
Power Law Transformations
Contrast Enhancement

γ = 0.4
1
0.9
Transformed Intensities

0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities

14
Power Law Transformations
Contrast Enhancement

γ = 0.3
1
0.9
Transformed Intensities

0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0 0.2 0.4 0.6 0.8 1
Original Intensities

15
Power Law Transformations
Contrast Enhancement

MR image of Result after Result after Result after


fractured human spine Power law Power law Power law
transformation transformation transformation
c = 1,  = 0.6 c = 1,  = 0.4 c = 1,  = 0.3
16
Power Law Transformations
Contrast Enhancement

When the γ is reduced too


much, the image begins to
reduce contrast to the
point where the image
started to have very slight
“wash-out” look.

17
Power Law Transformations
Contrast Enhancement

Image has a washed-out


appearance – needs γ > 1

18
Image Enhancement
Aerial Result of
Power law
Image
transformation
c = 1,  = 3.0
(suitable)

Result of
Power law
Result of transformation
Power law c = 1,  = 5.0
transformation (high contrast,
c = 1,  = 4.0 some regions are
(suitable) too dark)

19
Histogram of a Grayscale Image

 Let I be a 1-band (grayscale) image.


 I(r,c) is an 8-bit integer between 0 and
255.
 Histogram, hI, of I:
◼ a 256-element array, hI
◼ hI (g) = number of pixels in I that have value g.
for g = 0,1, 2, 3, …, 255

20
HISTOGRAM
• A discrete function h(rk)=nk
– rk is the kth gray level
– nk is the number of pixels having gray level rk in the
image
• Ex:
nk

6
5
0 1 2 3 4
1 3 3 0 3
0 1 3 0 2
1
3 0 3 1 rk
0 1 2 3

21
UNIQUENESS

22
Histogram of a Grayscale Image

lower RHC: number of pixels with intensity g

black marks pixels with intensity g


16-level (4-bit) image

23
Histogram of a Grayscale Image

Black marks
pixels with
intensity g

Plot of histogram:
number of pixels with intensity g

24
Histogram of a Grayscale Image

Black marks
pixels with
intensity g

Plot of histogram:
number of pixels with intensity g

25
Histogram of a Grayscale Image

hI ( g ) = the number
of pixels in I
with graylevel g.

26
Histogram of a Color Image

 If I is a 3-band image
 then I(r,c,b) is an integer between 0 and 255.
 I has 3 histograms:
◼ hR(g) = # of pixels in I(:,:,1) with intensity value g
◼ hG(g) = # of pixels in I(:,:,2) with intensity value g
◼ hB(g) = # of pixels in I(:,:,3) with intensity value g

27
Histogram of a Color Image

There is one histo-


gram per color band
R, G, & B. Luminosity
histogram is from 1
band = (R+G+B)/3

28
Histogram: Example

Dark Image

How would the


histograms of these
images look like?

Bright Image

29
Histogram: Example
Dark image
Components of
histogram are
concentrated on
the low side of
the gray scale

Bright image
Components of
histogram are
concentrated on
the high side of
the gray scale
30
HISTOGRAM INSIGHT INTO CONTRAST

31
Histogram: Example

Low Contrast Image

How would the


histograms of these
images look like?

High Contrast Image

32
Histogram: Example

Low contrast image


Histogram is narrow and
centered toward the
middle of the gray scale

High contrast image


Histogram covers broad
range of the gray scale
and the distribution of
pixels is not too far from
uniform with very few
vertical lines being much
higher than the others
33
Contrast Stretching

Improve the contrast in an


image by `stretching' the
range of intensity values it
contains to span a desired
range of values, e.g. the
the full range of pixel
values

34
Contrast Stretching

If rmax and rmin are the maximum and minimum


gray level of the input image and L is the total
gray levels of output image, the transformation
function for contrast stretch will be

255
L

 L −1 
s = T (r ) = (r − rmin )  

127
 max min 
r r

0
0 rmin 127 rmax255

35
Contrast Stretching

36
Histogram Equalization

Histogram equalization re-assigns the intensity values of pixels in the input


image such that the output image contains a uniform distribution of intensities

37
HISTOGRAM EQUALIZATION

38
AERIAL PHOTOGRAPH OF THE PENTAGON

Resulting image uses more of dynamic range.


39
Resulting histogram almost, but not completely, flat.
The Probability Distribution Function
of an Image
255
Let A =  hI ( g )
g =0

Note that since hI ( g ) is the number of pixels in


I with value g ,
A is the number of pixels in I . That is if I is
R rows by C columns then A = R  C.

Then, This is the probability


1 that an arbitrary pixel
pI ( g ) = hI ( g )
A from I has value g.

40
The Probability Distribution Function
of an Image

• p(g) is the fraction of pixels in an image that have


intensity value g.
• p(g) is the probability that a pixel randomly selected
from the given image has intensity value g.
• Whereas the sum of the histogram h(g) over all g from
0 to 255 is equal to the number of pixels in the image,
the sum of p(g) over all g is 1.
• p is the normalized histogram of the image

41
The Cumulative Distribution Function
of an Image
Let q = I(r,c) be the value of a randomly
selected pixel from I. Let g be a specific gray
level. The probability that q ≤ g is given by

g
1 g
 h ( )
I

PI ( g ) =  pI (  ) =  hI ( ) = =0
255
,
 h ( )
 =0 A  =0
I

=0

where hI(γ ) is
the histogram of This is the probability that
image I. any given pixel from I has
value less than or equal to g.

42
The Cumulative Distribution Function
of an Image
Let q = I(r,c) be the value of a randomly
selected pixel from I. Let g be a specific gray Also called CDF
level. The probability that q ≤ g is given by for “Cumulative
Distribution
Function”.
g

g
1 g
 h ( )
I

PI ( g ) =  pI (  ) =  hI ( ) = =0
255
,
 h ( )
 =0 A  =0
I

=0

where hI(γ ) is
the histogram of This is the probability that
image I. any given pixel from I has
value less than or equal to g.

43
The Cumulative Distribution Function
of an Image
• P(g) is the fraction of pixels in an image that have intensity
values less than or equal to g.
• P(g) is the probability that a pixel randomly selected from
the given band has an intensity value less than or equal to
g.
• P(g) is the cumulative (or running) sum of p(g) from 0
through g inclusive.
• P(0) = p(0) and P(255) = 1;

44
Histogram Equalization

Task: remap image I so that its histogram is as close to


constant as possible

Let PI (  )
be the cumulative (probability) distribution function of I.

The CDF itself is used as the LUT.

45
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

CDF

46
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

LUT

47
Histogram Equalization
The CDF (cumulative
distribution) is the
pdf
LUT for remapping.

LUT

48
Histogram Equalization

49
Histogram Equalization
Luminosity

before

J ( r , c ) = 255  PI  I ( r , c )  .
after

50
HISTOGRAM EQUALIZATION
IMPLEMENTATION

0 0 0 0 0
1 1 1 1 4
4 5 6 6 6
8 8 8 8 9

51
HISTOGRAM EQUALIZATION
IMPLEMENTATION

0 0 0 0 0 2 2 2 2 2
1 1 1 1 4 4 4 4 4 5
4 5 6 6 6 5 5 7 7 7
8 8 8 8 9 9 9 9 9 9

Gray levels 0 1 2 3 4 5 6 7 8 9
Counts (h(rk)) 5 4 0 0 2 1 3 0 4 1
r0 r1 r2 r3 r4 r5 r6

Normalized h (P(rk)) 5/20 4/20


0 0
2/20 1/20 3/20 0 4/20 1/20

cdf F(rk) 5/20 9/20 11/20 12/20 15/20 19/20 20/20

sk =round(9•F(rk)) 2 4 5 5 7 9 9
s0 s1 s2 s3 s4 s5 s6

52
Histogram Equalization: Example

Original Image Corresponding histogram (red) and cumulative


histogram (black)

Image after histogram equalization Corresponding histogram (red) and cumulative


histogram (black)
53
Histogram Equalization: Example
Equalized Histogram
Dark image
Bright image

Equalized Histogram
54
Histogram Equalization: Example
Equalized Histogram
Low contrast
High Contrast

Equalized Histogram
55
HISTOGRAM MATCHING
(SPECIFICATION)
• HISTOGRAM EQUALIZATION DOES NOT ALLOW
INTERACTIVE IMAGE ENHANCEMENT AND
GENERATES ONLY ONE RESULT: AN
APPROXIMATION TO A UNIFORM HISTOGRAM.
• SOMETIMES THOUGH, WE NEED TO BE ABLE TO
SPECIFY PARTICULAR HISTOGRAM SHAPES
CAPABLE OF HIGHLIGHTING CERTAIN GRAY-LEVEL
RANGES.

56
MAPPINGS

57
HISTOGRAM SPECIFICATION

• OBTAIN THE HISTOGRAM OF THE GIVEN IMAGE


• MAP EACH LEVEL rK TO A LEVEL SK
• OBTAIN THE TRANSFORMATION FUNCTION G FROM THE
GIVEN PZ (Z)
• PRECOMPUTE ZK FOR EACH VALUE OF SK
• FOR EACH PIXEL IN THE ORIGINAL IMAGE, IF THE VALUE
OF THAT PIXEL IS rk MAP THIS VALUE TO ITS
CORRESPONDING LEVEL SK, THEN MAP LEVEL SK INTO THE
FINAL VALUE ZK

58
HISTOGRAM SPECIFICATION
k nk pr(rk) sk pz(zk) vk nk
0 790 0.19 0.19 0 0 0
1 1023 0.25 0.44 0 0 0
2 850 0.21 0.65 0 0 0
3 656 0.16 0.81 0.15 0.15 790
4 329 0.08 0.89 0.2 0.35 1023
5 245 0.06 0.95 0.3 0.65 850
6 122 0.03 0.98 0.2 0.85 985
7 81 0.02 1.0 0.15 1.0 448

A 64X64 (4096 PIXELS) IMAGE WITH 8 GRAY LEVELS


59
GLOBAL/LOCAL HISTOGRAM EQUALIZATION
• IT MAY BE NECESSARY TO ENHANCE DETAILS OVER SMALL AREAS IN THE
IMAGE
• THE NUMBER OF PIXELS IN THESE AREAS MAY HAVE NEGLIGIBLE INFLUENCE
ON THE COMPUTATION OF A GLOBAL TRANSFORMATION WHOSE SHAPE
DOES NOT NECESSARILY GUARANTEE THE DESIRED LOCAL ENHANCEMENT
• DEVISE TRANSFORMATION FUNCTIONS BASED ON THE GRAY LEVEL
DISTRIBUTION IN THE NEIGHBORHOOD OF EVERY PIXEL IN THE IMAGE
• THE PROCEDURE IS:
– DEFINE A SQUARE (OR RECTANGULAR) NEIGHBORHOOD AND MOVE THE
CENTER OF THIS AREA FROM PIXEL TO PIXEL.
– AT EACH LOCATION, THE HISTOGRAM OF THE POINTS IN THE
NEIGHBORHOOD IS COMPUTED AND EITHER A HISTOGRAM
EQUALIZATION OR HISTOGRAM SPECIFICATION TRANSFORMATION
FUNCTION IS OBTAINED.
– THIS FUNCTION IS FINALLY USED TO MAP THE GRAY LEVEL OF THE PIXEL
CENTERED IN THE NEIGHBORHOOD.
– THE CENTER IS THEN MOVED TO AN ADJACENT PIXEL LOCATION AND THE
PROCEDURE IS REPEATED.

60
GLOBAL/LOCAL HISTOGRAM EQUALIZATION

61
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• LET r REPRESENT A GRAY LEVEL IN THE IMAGE [0, L-1], AND LET p(ri )
DENOTE THE NORMALIZED HISTOGRAM COMPONENT
CORRESPONDING TO THE ith VALUE OF r.
• THE nth MOMENT OF r ABOUT ITS MEAN IS DEFINED AS

L −1 n

 n (r ) =  (ri − m ) p(ri )
i =0
• WHERE m IS THE MEAN VALUE OF r (AVERAGE GRAY LEVEL)

m = i =0 ri p(ri )
L −1

62
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Global)
• THE SECOND MOMENT IS GIVEN BY

L −1 2

 2 (r ) =  (ri − m ) p(ri )
i =0

• WHICH IS THE VARIANCE OF r


• MEAN AS A MEASURE OF AVERAGE GRAY LEVEL IN THE IMAGE
• VARIANCE AS A MEASURE OF AVERAGE CONTRAST

63
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT (Local)
• LET (x,y) BE THE COORDINATES OF A PIXEL IN AN
IMAGE, AND LET SX,Y DENOTE A NEIGBORHOOD OF
SPECIFIED SIZE, CENTERED AT (x,y)
• THE MEAN VALUE mSXY OF THE PIXELS IN SX,Y IS

ms xy =  r s ,t p(rs ,t )
( s ,t
) S xy
• THE GRAY LEVEL VARIANCE OF THE PIXELS IN
REGION SX,Y IS GIVEN BY

S xy
2
=  r s ,t 
− msxy p(rs ,t )
2

( )
s ,t S xy
64
USE OF HISTOGRAM STATISTICS FOR IMAGE
ENHANCEMENT
• THE GLOBAL MEAN AND VARIANCE ARE MEASURED
OVER AN ENTIRE IMAGE AND ARE USEFUL FOR
GROSS ADJUSTMENTS OF OVERALL INTENSITY AND
CONTRAST.
• A USE OF THESE MEASURES IN LOCAL
ENHANCEMENT IS, WHERE THE LOCAL MEAN AND
VARIANCE ARE USED AS THE BASIS FOR MAKING
CHANGES THAT DEPEND ON IMAGE
CHARACTERISTICS IN A PREDEFINED REGION ABOUT
EACH PIXEL IN THE IMAGE.

65
TUNGSTEN FILAMENT IMAGE

66
USE OF HISTOGRAM STATISTICS FOR IMAGE ENHANCEMENT

• A PIXEL AT POINT (x,y) IS CONSIDERED IF:


– mSXY ≤ k0MG, where k0 is a positive constant less than 1.0, and MG is
global mean
– σsxy ≤ k2DG, where DG is the global standard deviation and k2 is a
positive constant
– k1DG ≤ σsxy ,, with k1 < k2
• A PIXEL THAT MEETS ALL ABOVE CONDITIONS IS
PROCESSED SIMPLY BY MULTIPLYING IT BY A SPECIFIED
CONSTANT, E, TO INCREASE OR DECREASE THE VALUE OF
ITS GRAY LEVEL RELATIVE TO THE REST OF THE IMAGE.
• THE VALUES OF PIXELS THAT DO NOT MEET THE
ENHANCEMENT CONDITIONS ARE LEFT UNCHANGED.

67
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

68
IMAGE ENHANCEMENT IN THE
SPATIAL DOMAIN

69
Spatial Filtering

70
Spatial Filtering

71
Spatial Filtering
Spatial Filtering: Basics
 The output intensity value at (x,y) depends not only on the input
intensity value at (x,y) but also on the specified number of
neighboring intensity values around (x,y)

 Spatial masks (also called window, filter, kernel, template) are used
and convolved over the entire image for local enhancement (spatial
filtering)

 The size of the masks determines the number of neighboring pixels


which influence the output value at (x,y)

 The values (coefficients) of the mask determine the nature and


properties of enhancing technique

73
Spatial Filtering: Basics
a b
g ( x, y ) =   w(s, t ) f ( x + s, y + t )
s =− a t =− b

m −1 n −1
where a = , b=
2 2
x = 0,1, 2,...., M − 1, y = 0,1, 2,..., N − 1

Filtering can be given in equation


form as shown above

74
Spatial Filtering: Basics
 Given the 3×3 mask with coefficients: w1, w2,…, w9
 The mask cover the pixels with gray levels: z1, z2,…, z9

w1 w2 w3 z1 z2 z3
w4 w5 w6 z4 z5 z6
w7 w8 w9 z7 z8 z9

9
z ⎯
⎯ z1w1 + z2 w2 + z3 w3 + + z9 w9 =  zi wi
i =1

 z gives the output intensity value for the processed image (to be
stored in a new array) at the location of z5 in the input image

75
Spatial Filtering: Basics

Origin x
Neighbourhood
operations: Operate on a
larger neighbourhood of
pixels than point
operations (x, y)
Neighbourhood

Neighbourhoods are mostly a


rectangle around a central
pixel
y Image f (x, y)

78
Spatial Filtering: Basics
Origin x
a b c r s t
d
g
e
h
f
i
* u
x
v
y
w
z
Original Image Filter
Simple 3*3 Pixels
e 3*3 Filter
Neighbourhood
eprocessed = v*e +
r*a + s*b + t*c +
u*d + w*f +
y Image f (x, y) x*g + y*h + z*i
The above is repeated for every pixel in the original image to generate the filtered image

79
Spatial Filtering: Basics
Original Image x Enhanced Image x
123 127 128 119 115 130

140 145 148 153 167 172

133 154 183 192 194 191

194 199 207 210 198 195

164 170 175 162 173 151

y y

80
Spatial Filtering: Basics
Mask operation near the image border: Problem arises when
part of the mask is located outside the image plane

Discard the problem pixels (e.g.


512x512 input 510x510 output if mask Pixel replication: We
size is 3x3) normally use the gray
Zero padding: Expand the input levels of border pixels to
image by padding zeros (512x512 fill up the expanded region
original image, 514x514 padded (for 3x3 mask). For larger
image, 512x512 output) masks a border region
Zero padding is not equal to half of the mask
recommended as it creates size is mirrored on the
artificial lines or edges on the expanded region.
border

81
Spatial Filtering: Basics
Mask operation near the border: Pixel
replication

83
Spatial Filtering: Basics

Moving window (kernel)


scans the 3x3
neighborhood of every
pixel in the image

Original Image

84
Spatial Filtering: Basics

85
Spatial Filtering: Basics

86
Spatial Filtering: Basics

87
Spatial Filtering: Basics

88
Spatial Filtering: Basics

89
Readings from Book (4th Edn.)
• Chapter – 3
– 3.3
Acknowledgements
 Statistical Pattern Recognition: A Review – A.K Jain et al., PAMI (22) 2000
 Pattern Recognition and Analysis Course – A.K. Jain, MSU
Material in these slides has been taken from, the following resources

 Pattern Classification” by Duda et al., John Wiley & Sons.


 Digital Image Processing”, Rafael C. Gonzalez & Richard E. Woods, Addison-Wesley, 2002
 Machine Vision: Automated Visual Inspection and Robot Vision”, David Vernon, Prentice Hall,
1991
 www.eu.aibo.com/
 Advances in Human Computer Interaction, Shane Pinder, InTech, Austria, October 2008

91

You might also like