spatial image enhancement

39
Sankalp Kallakuri [email protected] Spatial Image Enhancement

Upload: sankalpkallakur402

Post on 10-Apr-2015

421 views

Category:

Documents


5 download

DESCRIPTION

spatial image enhancement techniques for image processing

TRANSCRIPT

Page 1: Spatial Image Enhancement

Sankalp Kallakuri

[email protected]

Spatial Image Enhancement

Page 2: Spatial Image Enhancement

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.

Page 3: Spatial Image Enhancement

Transpose

• A(i,j) = B(j,i) i,j

Page 4: Spatial Image Enhancement

Vertical Flip

Page 5: Spatial Image Enhancement

Cropping an Image

• cutting out a portion of the image.Given X_start Y_start Width and Height

Page 6: Spatial Image Enhancement

Masks or Operators

• g(x,y) = T[(x,y)]

• Point processing

s = T(r)

Dark light

Light

Dark

Dark light

Light

Dark

Page 7: Spatial Image Enhancement

A simple transform

Dark light

Light

Dark

Digital negative

Page 8: Spatial Image Enhancement

Grey level Transformations

Square law transformation

Page 9: Spatial Image Enhancement

Power law and Log Transformations

• s = c log (1+r)

• s = c r

Page 10: Spatial Image Enhancement

Power Law Results

Worked on an RGB image

Page 11: Spatial Image Enhancement

Log Transform for Fourier Domain

DC level image in space domain

Page 12: Spatial Image Enhancement

2D Fourier Domain

2D Fourier transform

&

Unprocessed image

representation

Page 13: Spatial Image Enhancement

2D Fourier Image after Log transform

Page 14: Spatial Image Enhancement

Gamma Correction

Image Screen Image

Image Gamma Corrected

Image

Screen Image

Page 15: Spatial Image Enhancement

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

Page 16: Spatial Image Enhancement

Histogram

Image histogram

Page 17: Spatial Image Enhancement

Piecewise Linear Transformations

.Contrast stretching

.Thresholding

.Grey level slicing

.Bit plane slicing

Page 18: Spatial Image Enhancement

Contrast Stretching

Low contrast High Contrast

Piecewise linear

function

Page 19: Spatial Image Enhancement

How did I get the stretch function?

Low contrast histogram High contrast histogram

Page 20: Spatial Image Enhancement

Example contrast stretching

Original High Contrast

Page 21: Spatial Image Enhancement

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

Page 22: Spatial Image Enhancement

Examples of Thresholding

R 80-130 R 80-160

R 80-190 R 80-220

Page 23: Spatial Image Enhancement

Examples of Grey level slicing

originalGrey slice

88

R 80-130

Grey slice

128

R 80-130

Grey slice

168

R 80-130

Page 24: Spatial Image Enhancement

Histogram Types

dark light

Low contrastHigh Contrast

Page 25: Spatial Image Enhancement

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)

Page 26: Spatial Image Enhancement

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

Page 27: Spatial Image Enhancement

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

Page 28: Spatial Image Enhancement

Histogram Equalization Results

Original Histogram Equalized

Page 29: Spatial Image Enhancement

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

Page 30: Spatial Image Enhancement

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

Page 31: Spatial Image Enhancement

Arithmetic and Logical Operations

• AND OR NOT

• ADD SUB

Difference between original and histogram

equalized image.

Masks

for

logical

operators

Page 32: Spatial Image Enhancement

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

Page 33: Spatial Image Enhancement

Spatial Filtering

• Involves moving a kernel over the image to enhance the image

• Kernel size is << Image size

• Odd sized masks are more common

Page 34: Spatial Image Enhancement

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 ),(),(),(

Page 35: Spatial Image Enhancement

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.

Page 36: Spatial Image Enhancement

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

Page 37: Spatial Image Enhancement

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

Page 38: Spatial Image Enhancement

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.

Page 39: Spatial Image Enhancement

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