spatial image enhancement
DESCRIPTION
spatial image enhancement techniques for image processingTRANSCRIPT
Spatial Image Enhancement
. Images are usually represented as matrices
P (nxm)
P(0,0) P(0,1) P(0,2) . .. …….. P(0,M-1)
P(1,0) P(1,1) P(1,2) ………………. P(1,M-1)
.. ..
.. ..
P(N-2,0) P(N-2,1) P(N-2,2)……………P(N-2,M-1)
P(N-1,0) P(N-1,1) P(N-1,2)……………P(N-1,M-1)
=
Spatial enhancement is all about
neighborhoods and histograms.
Transpose
• A(i,j) = B(j,i) i,j
Vertical Flip
Cropping an Image
• cutting out a portion of the image.Given X_start Y_start Width and Height
Masks or Operators
• g(x,y) = T[(x,y)]
• Point processing
s = T(r)
Dark light
Light
Dark
Dark light
Light
Dark
A simple transform
Dark light
Light
Dark
Digital negative
Grey level Transformations
Square law transformation
Power law and Log Transformations
• s = c log (1+r)
• s = c r
Power Law Results
Worked on an RGB image
Log Transform for Fourier Domain
DC level image in space domain
2D Fourier Domain
2D Fourier transform
&
Unprocessed image
representation
2D Fourier Image after Log transform
Gamma Correction
Image Screen Image
Image Gamma Corrected
Image
Screen Image
Image Statistics
NM
jiG
sm
M
j
N
i
1
0
1
0
),(Mean Variance
NM
smjiG
s
M
j
N
i
1
0
21
0
)),((
var
Histogram
0 255
Histogram
Image histogram
Piecewise Linear Transformations
.Contrast stretching
.Thresholding
.Grey level slicing
.Bit plane slicing
Contrast Stretching
Low contrast High Contrast
Piecewise linear
function
How did I get the stretch function?
Low contrast histogram High contrast histogram
Example contrast stretching
Original High Contrast
Thresholding and Grey Level Slicing
.If you know the intensity values you would like to have
enhanced in an image
.If the background needs to be retained the grey level
slicing method is used
.If the background isn’t important the pixels can be thresholded
to two levels.
.
Grey Level Slicing Thresholding
Examples of Thresholding
R 80-130 R 80-160
R 80-190 R 80-220
Examples of Grey level slicing
originalGrey slice
88
R 80-130
Grey slice
128
R 80-130
Grey slice
168
R 80-130
Histogram Types
dark light
Low contrastHigh Contrast
Histogram Equalization
10 r1)(0 rT
10 r
s=T(r) for a normalized image in the range [0,1]
Satisfies
a) T(r) is single valued and monotonically increasing in .
b) for
CDF is integral of PDF
PDF is defined on [0,1] so is CDF and it satisfies above
mentioned conditions
dr
dsrpsp rs )()(
Relation between PDF of the two variables
(1)
Histogram Equalization
)()(
rpdr
rdT
dr
dsr
dwwprTs
r
r )()(0
1)( sps
CDF as a transform
We can prove that
Plugging this in eqn 1
(2)
(3)
(4)
This last equation states that the distribution is uniform.
10 s
T(r) depends on P(r) but P(s) will always be uniform
Discrete Domain Histogram Equalization
n
nrp kkr )( 1....2,1,0 Lk
n
nrTs k
k
kk 0
)(
PMF or the probabilities for the use of a particular grey level
can be found in the following manner.
Setting up T(r) as the CDF
1....2,1,0 Lk
Histogram Equalization Results
Original Histogram Equalized
Histogram Matching (Specification)
dwwprTs
r
r )()(0
sdwwpzG
z
z )()(0
.In contrast stretching we had control over the mapping
.In Equalization the mapping depended on the PDF of the image
.In matching we try to get the best of both worlds
Step 1: Equalization
Step 2: Define a variable z such that:
Step 3: Obtain mapping from r to z
)]([)( 11 rTGsGz
Statistics from Histograms
)()()(1
0
i
L
i
n
in rpmrru
)(1
0
i
L
i
i rprm
Let p(ri) be the PDF defined by the normalized histogram.
The nth moment about its mean can be defined as:
M being the sample mean
The second moment or variance
)()()(1
0
2
2 i
L
i
i rpmrru
Arithmetic and Logical Operations
• AND OR NOT
• ADD SUB
Difference between original and histogram
equalized image.
Masks
for
logical
operators
Image Averaging
),(),(),( yxyxfyxg
),(1
),(1
yxgK
yxgK
i
i
),(),( yxfyxgE
Image can be expressed as original image + noise
If the noise is uncorrelated and has zero mean. An image
formed by averaging K noisy images could be created.
The expected average image should be close to the
original image as the noise will cancel out.
The variance of the averaged image will be given by
),(1
),( yxK
nyxg
Spatial Filtering
• Involves moving a kernel over the image to enhance the image
• Kernel size is << Image size
• Odd sized masks are more common
Spatial Filtering
f(x-1,y-1) f(x,y-1) f(x+1,y-1)
f(x-1,y) f(x,y) f(x+1,y)
f(x-1,y+1) f(x,y+1) f(x+1,y+1)
m(-1,-1) m(0,-1) m(1,-1)
m(-1,0) m(0,0) m(1,0)
m(-1,1) m(0,1) m(1,1)
Mask coefficients
Image pixels under mask
R = m(-1,-1) f(x-1,y-1) + m(0,-1) f(x,y-1) + m(1,-1) f(x+1,y-1) + ………..
a
as
b
bt
tysxftsmyxg ),(),(),(
Spatial Filtering
• The operation is similar to Convolution. hence the masks are also called convolution masks.
• Non linear operations such as finding median may also be done on a neighborhood.
• Near the edges parts of the masks may lie beyond the image boundary.
• To avoid this either a smaller filtered image is accepted.
• Or zeros are padded along the image boundary.
Smoothing Spatial Filters
• Averaging or Low pass filters.
• Used to remove unwanted detail.
• Smooth out unwanted sharp noise transitions.
• May smooth out edges which should be sharp.
1 2 1
2 4 2
1 2 1
Examples
1 1 1
1 1 1
1 1 1
1/9 x 1/16 x
Box filter Weighted Average
Smoothing Spatial Filters
• The box filter does a simple average.
• The weighted average filter weighs the contribution by the
distance from the central image pixel.
a
as
b
bt
a
as
b
bt
tsm
tysxftsm
yxg
),(
),(),(
),(
Mathematical expressionOriginal
3 6 9 12
Home Work 2
• Write a matlab script to vertically flip an image.
• Write a matlab script to transpose an image.
• Write a matlab script to crop a circular region out from an image and place it in a new square image of appropriate size with a black background. The [x,y] coordinates of the center and the radius of the circle shall be given.
• Write a matlab script to get the digital negative of an image.
• 1) Read in the given image.
2) Crop out a circular region with center at x,y = 3L/4 ,
3L/4 and radius=25. where L is the length of the image.
3) Display the circular cropped region on a square image with
black background. Lets call this image A.
Home Work 2
4)Display the original image with the circular region darkened to black. Lets call this image B.
5)Vertically flip image B and display it.Lets call this image C.
6) Digitally invert a circular region at center x,y = 3L/4,3L/4 and radius 25 for image C and display this image. Lets call this image D.
7) Transpose image D and display. This last image should be labeled E.
DUE : 22nd February 2007 at 11:59 pm
Read IP tool box functions at
www.Mathworks.com