Download as pdf or txt
Download as pdf or txt
You are on page 1of 66

Image 

Processing 

Intensity Transformations
Ch
Chapter 33

Prof. Vidya Manian
Dept. of Electrical and Comptuer Engineering

INEL 5327 ECE, UPRM Intensity Transformations ‐ 1


Overview
• Background
• Basic intensity transformation functions
• Histogram processing
i i

INEL 5327 ECE, UPRM 2
3x3 neighborhood of a point (x,y)
3x3 neighborhood of a point (x,y)

INEL 5327 ECE, UPRM 3
Intensity or gray‐level or mapping 
transformation function
f f
• S=T(r)
• Resulting image has higher contrast  by 
darkening the intensity levels below k and
darkening the intensity levels below k and 
brightening the levels above k
• Contrast stretching‐values of r lower than k 
C hi l f l h k
are compressed by the transformation 
f
function into a narrow range of s, toward 
i i f d
black, vice versa for values of r higher than k

INEL 5327 ECE, UPRM 4
Contrast stretching and thresholding
functions

INEL 5327 ECE, UPRM 5
Thresholding function
• T(r)
T(r) produces a two
produces a two‐level
level (binary) image 
(binary) image –
limiting case
• Intensity transformations are used for image 
Intensity transformations are used for image
enhancement
• Also for image segmentation
Al f i i
• Two types: point processing and 
neighborhood processing

INEL 5327 ECE, UPRM 6
Basic intensity transformation 
functions
• S=T(r)
• Mapping from r to s are implemented via a 
lookup table
lookup table
• For 8‐bits, lookup table has 256 entries.
• Types of functions: linear (negative and 
identity transformations)
• Power‐law (nth power and nth root 
transformations))
INEL 5327 ECE, UPRM 7
Basic intensity transformation 
functions

INEL 5327 ECE, UPRM 8
Image negatives
Image negatives
• Negative transformation s=L‐1‐r
g
• Log transformation: s=c log (1+r)
• c is a constant, r≥0
• Maps range of low intensity values in the input to 
wider range of output levels
• Expands dark pixels in an image and compresses 
E d d k i l i i d
the higher‐level values (white pixels)
• Useful for Fourier spectrum: spectra values range 
Useful for Fourier spectrum: spectra values range
from 0 to 10^6 or higher.
• Detail lost in the display of Fourier spectrum

INEL 5327 ECE, UPRM 9
Original image and negative image 
obtained using the negative
obtained using the negative 
transormation

INEL 5327 ECE, UPRM 10
Fourier spectrum and log 
transformation
f

INEL 5327 ECE, UPRM 11
• Fourier
Fourier spectrum with values in range of 0 to 
spectrum with values in range of 0 to
1.5 x 10^6 (Fig. 3.5 a) only few pixels are 
white.
white
• First use log transformation with c=1, range of 
values become 0 to 6 2
values become 0 to 6.2
• Fig 3.5b has better scaling and shows more 
d il
detail.

INEL 5327 ECE, UPRM 12
Power law (Gamma) transformations
Power law (Gamma) transformations
• s=cr
Where c and  are positive constants. 
• s=c(r+) to account for an offset due to display 
calibration
• power‐law curves with fractional values of  map a 
narrow range of dark input values to a wider range of 
output values, and opposite for higher values of input 
t t l d it f hi h l fi t
levels
• >1 has opposite effect of <1. Also called Gamma 
 pp 
correction
• Device dependent, CRT displays, image capture, 
printing
INEL 5327 ECE, UPRM 13
INEL 5327 ECE, UPRM 14
• Preprocess image before input to monitor by 
p g p y
s=r^(1/2.5)=r^(0.4)
• Gamma corrected output has appearance close 
to original
to original
• Applicable to scanners, printers
• Use of digital images for commercial purpose 
Use of digital images for commercial purpose
over Internet has increased
• Solution –display image after gamma correction 
p y g g
to value that represents “average” of the types of 
monitors and computer systems to be used to 
display the image
display the image.
INEL 5327 ECE, UPRM 15
INEL 5327 ECE, UPRM 16
INEL 5327 ECE, UPRM 17
Contrast stretching
Contrast stretching

INEL 5327 ECE, UPRM 18
INEL 5327 ECE, UPRM 19
INEL 5327 ECE, UPRM 20
Bit plane representation of an 8‐bit 
image

INEL 5327 ECE, UPRM 21
INEL 5327 ECE, UPRM 22
INEL 5327 ECE, UPRM 23
Four basic image types

INEL 5327 ECE, UPRM 24
Histogram equalization
Histogram equalization

INEL 5327 ECE, UPRM 25
Transformation functions for 
Histogram equalization in Fig. 3. 20
l

INEL 5327 ECE, UPRM 26
Example of histogram equalization
Example of histogram equalization

INEL 5327 ECE, UPRM 27
Histogram

INEL 5327 ECE, UPRM 28
Histogram equalized image
Histogram equalized image

INEL 5327 ECE, UPRM 29
Specified Histogram
Specified Histogram

INEL 5327 ECE, UPRM 30
Steps for Histogram Matching
Steps for Histogram Matching
• Obtain Pr(r) from input image and obtain values of s
• Use specified pdf
Use specified pdf to obtain the transformation function 
to obtain the transformation function
G(z)
• Obtain the inverse transformation z=G‐1(s); mapping 
( ); pp g
from s to z
• Obtain output image by first equalizing input image . 
F
For each pixel with value s, perform inverse mapping 
h i l ith l f i i
z=G‐1(s) to obtain corresponding output pixel
• When all pixels are processed the pdf
When all pixels are processed the pdf of output image 
of output image
is equal to specified pdf

INEL 5327 ECE, UPRM 31
Local Histogram equalization
Local Histogram equalization

INEL 5327 ECE, UPRM 32
Global and local histogram 
equalization
l

INEL 5327 ECE, UPRM 33
Fundamentals of spatial filtering
Fundamentals of spatial filtering
• Filter:
Filter: accepting(passing) or rejecting certain 
accepting(passing) or rejecting certain
frequency components
• Spatial filter consists of (1) a neighborhood (a 
Spatial filter consists of (1) a neighborhood (a
small rectangle) and (2) predefined operation 
performed on the image pixels encompassed
performed on the image pixels encompassed 
by the neighborhood
• Linear and non‐linear filters
Li d li fil

INEL 5327 ECE, UPRM 34
Basics of Spatial Filtering
Basics of Spatial Filtering
• Neighborhood
Neighborhood subimage
subimage‐filter,
filter, mask, kernel, 
mask, kernel,
template, or window
• Values in mask 
Values in mask –coefficients
coefficients
• Response R of linear filtering with the filter 
mask at a point (x,y) in the image is:
mask at a point (x,y) in the image is:
• R=w(‐1,‐1)f(x‐1,y‐1)+w(‐1,0)f(x‐1,y)+…
• +w(0,0)f(x,y)+…+w(1,0)f(x+1,y)+w(1,1)f(x+1,y+
+w(0 0)f(x y)+ +w(1 0)f(x+1 y)+w(1 1)f(x+1 y+
1)

INEL 5327 ECE, UPRM 35
Mechanics of spatial filtering
Mechanics of spatial filtering
• W(0
W(0,0) center coefficient of the filter
0) center coefficient of the filter
• Mask of size mxm, m=2a+1 and n=2b+1, 
where a and b are positive integers
where a and b are positive integers
• Smallest size 3x3

INEL 5327 ECE, UPRM 36
Spatial correlation and convolution
Spatial correlation and convolution
• Co
Correlation is the process of moving a filter mask 
e at o s t e p ocess o o g a te as
over the image and computing the sum of 
products at each location.
• Convolution is the same except that the filter is 
rotated by 180 degrees. 
• Rotation is equivalent to horizontal flipping
• In 2Drotation is equivalent to flipping the mask 
along  one axis and then the other
l i d th th th
• Fig. 3.29 shows 1‐D convolution and correlation

INEL 5327 ECE, UPRM 38
INEL 5327 ECE, UPRM 39
Correlation and convolution
Correlation and convolution

INEL 5327 ECE, UPRM 40
Smoothing spatial filters
Smoothing linear filters
Smoothing linear filters
• An
An mxn
mxn mask would have a normalizing 
mask would have a normalizing
constant equal to 1/mn. 
• A spatial averaging filter in which all 
A spatial averaging filter in which all
coefficients are equal is called a box filter
• The diagonal terms are further away from 
The diagonal terms are further away from
center and hence are weighted less than the 
immediate neighbors
• Sum of coefficients =16 is useful for easy 
computer implementation ( a power of 2)
INEL 5327 ECE, UPRM 42
Effect of smoothing as a function of 
fl
filter size
• Average
Average filters of sizes m
filters of sizes m=3,5,9,15
3,5,9,15 and 35 
and 35
pixels
• Larger size windows for blurring removes 
Larger size windows for blurring removes
smaller objects from image
• A gross representation of objects of interest is 
A gross representation of objects of interest is
obtained
• Intensity of smaller objects blends with 
Intensity of smaller objects blends with
background and larger objects become 
bloblike
INEL 5327 ECE, UPRM 43
INEL 5327 ECE, UPRM 44
Order‐statistics
Order statistics (nonlinear) filters
(nonlinear) filters
• Response of nonlinear filters based on 
p
ordering(ranking) the pixels contained in the 
image area encompassed by the filter
• Median filter‐
Median filter to remove impulse noise (salt and 
to remove impulse noise (salt and
pepper noise)
• Sort the pixel values in the window (say 3x3 ) and 
Sort the pixel values in the window (say 3x3 ) and
assign the median value to the center pixel
• Forces pixels with distinct intensity levels to be 
more like its neighbors
lik i i hb
• Max, min filters

INEL 5327 ECE, UPRM 45
Image filtered with a 15x15 averaging 
maskk

INEL 5327 ECE, UPRM 46
INEL 5327 ECE, UPRM 47
Sharpening spatial filters
Sharpening spatial filters
• Highlights transition in intensities
Highlights transition in intensities
• Blurring by pixel averaging
• Sh
Sharpening by spatial differentiation
i b i l diff i i
• Enhances edges and other discontinuities such 
as noise
• Based on first and second order derivatives

INEL 5327 ECE, UPRM 48
First and second derivatives of a 1D 
signall

INEL 5327 ECE, UPRM 49
Sharpening spatial filters
Sharpening spatial filters

f
 f ( x  1)  f ( x )
x
2 f
 f ( x  1)  f ( x  1)  2 f ( x )
x
x 2

Change between adjacent pixels
First and second derivative
First and second derivative
(1) Must be zero in flat areas;
(2) Non zero at the onset of gray‐level step or ramp
(3) First derivative‐non zero along ramps; second derivative‐
Zero along ramps of cnstant slope

INEL 5327 ECE, UPRM 50
The Laplacian for enhancement (the 
second derivative)
dd i i )

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

x y
In the x direction
2 f
 f ( x  1, y )  f ( x  1, y )  2 f ( x, y )
x 2

In the y direction
2 f
 f ( x, y  1)  f ( x, y  1)  2 f ( x, y )
x 2
Sum min g
2 f  [ f ( x, y  1)  f ( x, y  1)  f ( x  1, y )  f ( x  1, y )]  4 f ( x, y )

INEL 5327 ECE, UPRM 51
INEL 5327 ECE, UPRM 52
Second derivative‐the
Second derivative the Laplacian
Laplacian

INEL 5327 ECE, UPRM 53
Blurring using Gaussian filter
Blurring using Gaussian filter

INEL 5327 ECE, UPRM 54
INEL 5327 ECE, UPRM 55
The Gradient for enhancement (the first 
d i i )
derivative)

 f 
Gx   x 
f      
G y   f 
 y 
f  mag (f )
 [Gx 2  G y 2 ]1/ 2
2 1/ 2
 f   f  
2

      
 x   y  

f  ( z7  2 z8  z9 )  ( z1  2 z1  z3 )  ( z3  2 z6  z9 )  ( z1  2 z4  z7 )
INEL 5327 ECE, UPRM 56
INEL 5327 ECE, UPRM 57
Composite Laplacian mask
p p
Sobel gradient

INEL 5327 ECE, UPRM 59
INEL 5327 ECE, UPRM 60
INEL 5327 ECE, UPRM 61
Exercise in group
Exercise in group
• Propose
Propose a set of intensity
a set of intensity‐slicing
slicing 
transformations capable of producing all the 
individual bit planes of an 8bit monochrome 
image. T(r)=0 in range [0,127] and T(r)=255 for 
r in range [128,255] produces an image of the 
8th bit plane in an 8‐bit image.
bi l i 8 bi i
• Given the Gaussian pdf what is the 
transformation function you would use for 
f i f i ld f
histogram equalization. 

INEL 5327 ECE, UPRM 62
Exercises on spatial filtering
Exercises on spatial filtering
• 3.1,3.2,3.4, 3.5, 3.6, 3.7, 3.8 to 3.11, 3.13
3 1 3 2 3 4 3 5 3 6 3 7 3 8 to 3 11 3 13
• 3.15, 3.17, 3.19, 

• 3.21, 3.23, 3.24, 3.25, 3.27, 3.28, 3.29

INEL 5327 ECE, UPRM 63
• 3
3.1)Give a single intensity transformation 
1)Give a single intensity transformation
function for spreading the intensities of an 
image so the lowest intensity is 0 and highest
image so the lowest intensity is 0 and highest 
is L‐1.
• 3.5) What effect would setting to zero the 
3 5) What effect would setting to zero the
lower‐order bit planes have on the histogram 
of an image in general
of an image in general.

INEL 5327 ECE, UPRM 64
• 3
3.6) Explain why discrete histogram 
6) Explain why discrete histogram
equalization does not in general yield a flat 
histogram.
histogram
• Answer: To get a flat histogram, pixel 
intensities should be redistributed so that
intensities should be redistributed so that 
there are L groups of n/L pixels with same 
intensity and n=MN
intensity and n=MN.

INEL 5327 ECE, UPRM 65
• 3
3.7) Suppose that a digital image is subjected 
7) Suppose that a digital image is subjected
to histogram equalization. Show that a second 
pass of histogram equalization (on the
pass of histogram equalization (on the 
histogram equalized image) will produce 
exactly the same result as the first pass
exactly the same result as the first pass.

INEL 5327 ECE, UPRM 66

You might also like