Lecture #5 - Case Western Reserve...

52
EECS490: Digital Image Processing Lecture #5 Point transformations (cont.) Histogram transformations – Equalization – Specification Local vs. global operations Intro to neighborhoods and spatial filtering

Transcript of Lecture #5 - Case Western Reserve...

Page 1: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Lecture #5

• Point transformations (cont.)

• Histogram transformations– Equalization

– Specification

– Local vs. global operations

• Intro to neighborhoods and spatial filtering

Page 2: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Brightness & Contrast

© 2002 R. C. Gonzalez & R. E. Woods

Page 3: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Input Output

I , point

operator JImage:

I(r,c)function,

f J(r,c)Pixel:

[ ]IJ =

( )

( )

( ) .,

,

kcrJ

kgf

gcrI

=

=

=

then

and

If

The transformation of image I into image J is

accomplished by replacing each input intensity, g, with

a specific output intensity, k, at every location (r,c)

where I(r,c) = g.

The rule that associates k with g is usually

specified with a function, f, so that f (g) = k.

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 4: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) ( )( )

( ).,

,,

cr

crIfcrJ

locations pixels all for

,=One-band Image

Three-band Image ( ) ( )( )

( ) ( )( )

( ).,3,2,1

,,,,

,,,,

crb

bcrIfbcrJ

bcrIfbcrJ

b

all and for

,

or ,

=

=

=

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 5: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) ( )( )

( ).,

,,

cr

crIfcrJ

locations pixels all for

,=One-band Image

Three-band Image ( ) ( )( )

( ) ( )( )

( ).,3,2,1

,,,,

,,,,

crb

bcrIfbcrJ

bcrIfbcrJ

b

all and for

,

or ,

=

=

=

Either all 3 bandsare mapped throughthe same function,f, or …

… each band ismapped througha separate func-tion, fb.

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 6: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( )1+= IJ LUT

A look-up table (LUT)

implements a

functional mapping.

( )

,255,,0

,

…=

=

g

gfk

for

If

{ }…… in values

on takes if and

,255,,0

k

… then the LUT

that implements f

is a 256x1 array

whose (g +1)th

value is k = f (g).

To remap a 1-band

image, I, to J :

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 7: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( )

( ) ( )( ) .3,2,11:,:,:,:,

1

=+=

+=

bbIbJ

IJ

b for LUT b)

,LUT a) or

If I is 3-band, then

a) each band is mapped separately using the same

LUT for each band or

b) each band is mapped using different LUTs – one

for each band.

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 8: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

0 127 255

0127

255

input value

ou

tpu

t v

alu

e

index value

...

101

102

103

104

105

106

...

...

64

68

69

70

70

71

...

E.g.:

input output

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 9: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

cell

index

conte

nts

0 0

64 32

128 128

192 224

255 255

...

...

...

...

...

...

...

...

input output

a pixel withthis value

is mapped tothis value

Point Ops via Functional Mappings

1999-2007 by Richard Alan Peters II

Page 10: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

How to Generate a Look-Up Table

{ }

( )32/)127(1

255;

255,,0

.2

+=

=

xae

ax

x

a

… Let

Let

For example:

a = 2;

x = 0:255;

LUT = 255 ./ (1+exp(-a*(x-127)/32));

Or in Matlab:

This is justone example.

1999-2007 by Richard Alan Peters II

Page 11: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( )( ) ( )

( ) 255,

256,

255

,,,

>+

<++=

gcrI

gcrIgcrIcrJ

k

kk

k if

if

,

0 127 255

0127

255

g

transform mapping{ } index. band the is and 3210 ,,kg

Point Processes: Increase Brightness

1999-2007 by Richard Alan Peters II

I =R +G + B

3

Page 12: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

0 127 255

0127

255

transform mapping

25

5-g

{ } index. band the is and 3210 ,,kg

( )( )

( )

( )crI

gcrI

gcrIcrJ

k

k

k

k,

0,

,,

0,

if

if

, <=

Point Processes: Decrease Brightness

1999-2007 by Richard Alan Peters II

Page 13: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) ( )

( )

( )

( ) .255,

,255,0

,0,

,255

,,

,0

,

>

<

=

crT

crT

crT

crTcrJ

k

k

k

kk

if

if

if

( )[ ] 0.1127127,),( >+= acrIacrTkk

where, Let

0 127 255

0127

255

transform mapping{ }321 ,,k

Point Processes: Increase Contrast

1999-2007 by Richard Alan Peters II

Page 14: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( )[ ]

{ }.3,2,10.10

127127,),(

<

+=

ka

crIacrTkk

and where

,

0 127 255

0127

255

transform mapping

Point Processes: Decrease Contrast

1999-2007 by Richard Alan Peters II

Page 15: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( )[ ] ( )[ ]( )[ ] ( )[ ]

( ) ( )( )

. ,

,

Then,

.,max , ,min

,,max , ,min Let

J

II

I

JJ

JJ

II

mmM

mcrImMcrJ

crJMcrJm

crIMcrIm

+=

==

==

0 127 255

0127

255

transform mappingmI MI

mJ

MJ

Point Processes: Contrast Stretch

1999-2007 by Richard Alan Peters II

Page 16: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

orig

lo-c

hi-c

histograms

Information Loss from ContrastAdjustment

1999-2007 by Richard Alan Peters II

Page 17: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

orig

orig

orig

lo-c hi-c

lo-c

hi-c

rest

rest

lo-c

hi-c

diff

diff

abbreviations: original low-contrast high-contrast restored difference

difference betweenoriginal and restoredlow-contrast

difference betweenoriginal and restoredhigh-contrast

Information Loss from ContrastAdjustment

1999-2007 by Richard Alan Peters II

Page 18: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

0 127 255

0127

255

transform mapping

( )( )

0.1255

,255,

/1

>= for crI

crJ

Point Processes: Increased Gamma

1999-2007 by Richard Alan Peters II

Page 19: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

0 127 255

0127

255

transform mappingm M

( )( )

0.1255

,255,

/1

<= for crI

crJ

Point Processes: Decreased Gamma

1999-2007 by Richard Alan Peters II

Page 20: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Gamma Correction: Effect onHistogram

1999-2007 by Richard Alan Peters II

Page 21: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ). Let

=

+=255

0

1

g

I ghAk

( )

. then columns by rows

is if is That . in pixels of number the is

, value with) image of band color th (the

in pixels of number the is since that Note

CRACR

IIA

gIkI

gh

k

Ik

=

+1

( ) ( )

Then,

1 1 1

is the graylevel probability density function of .

k kI I

k

p g h gA

I

+ = +

This is the probabilitythat an arbitrary pixelfrom Ik has value g.

pdf[lower case]

The Probability Density Function of an Image

1999-2007 by Richard Alan Peters II

Page 22: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

• pband(g+1) is the fraction of pixels in (a specific band of) an

image that have intensity value g.

• pband(g+1) is the probability that a pixel randomly selected

from the given band has intensity value g.

• Whereas the sum of the histogram hband(g+1) over all g from

1 to 256 is equal to the number of pixels in the image, the

sum of pband(g+1) over all g is 1.

• pband is the normalized histogram of the band.

The Probability Density Function of an Image

1999-2007 by Richard Alan Peters II

Page 23: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) ( ) ( )( )

( ),

1

1

11

11 255

0

0

0 0

=

=

= = +

+

=+=+=+

k

k

kkk

I

g

Ig g

III

h

h

hA

pgP

This is the probability thatany given pixel from Ik hasvalue less than or equal to g.

PDF[upper case]

Let q = [q1 q2 q3] = I(r,c) be the value of a

randomly selected pixel from I. Let g be a

specific gray level. The probability that qk

g is given by

where hIk( +1) is

the histogram of

the kth band of I.

The Probability Distribution Function of anImage

1999-2007 by Richard Alan Peters II

Page 24: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) ( ) ( )( )

( ),

1

1

11

11 255

0

0

0 0

=

=

= = +

+

=+=+=+

k

k

kkk

I

g

Ig g

III

h

h

hA

pgP

Let q = [q1 q2 q3] = I(r,c) be the value of a

randomly selected pixel from I. Let g be a

specific gray level. The probability that qk

g is given by

where hIk( +1) is

the histogram of

the kth band of I.

This is the probability thatany given pixel from Ik hasvalue less than or equal to g.

Also called CDFfor “CumulativeDistributionFunction”.

The Probability Distribution Function of anImage

1999-2007 by Richard Alan Peters II

Page 25: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

• Pband(g+1) is the fraction of pixels in (a specific band of) an

image that have intensity values less than or equal to g.

• Pband(g+1) is the probability that a pixel randomly selected from

the given band has an intensity value less than or equal to g.

• Pband(g+1) is the cumulative (or running) sum of pband(g+1)

from 0 through g inclusive.

• Pband(1) = pband(1) and Pband(256) = 1; Pband(g+1) is non-

decreasing.

A.k.a. Cumulative Distribution Function.

Note: the Probability Distribution Function (PDF, capital letters) and the Cumulative Distribution Function (CDF)

are exactly the same things. Both PDF and CDF will refer to it. However, pdf (small letters) is the density function.

The Probability Distribution Function of anImage

1999-2007 by Richard Alan Peters II

Page 26: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Intensity Transform Requirements

© 2002 R. C. Gonzalez & R. E. Woods

a) A monotonically increasing intensity transformation prevents anintensity reversal which could cause artifacts in the transformedimage.

b) A strictly monotonically increasing intensity transformationguarantees that the inverse transformation (from s=T(r) back tor) will be 1:1 preventing ambiguities

Page 27: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

s = T r( ) = L 1( ) pr w( )dw0

r

Cumulative Distribution Function (CDF)

© 2002 R. C. Gonzalez & R. E. Woods

Uniform Histogram Transform

These are pdf’s.Gonzalez uses PDFinstead of pdf.

L is the number ofgray levels.

Page 28: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

© 2002 R. C. Gonzalez & R. E. Woods

Histogram Equalization Example

Note: this same 3-bit (8 gray level) 64x64 pixel image willbe used for several examples

Page 29: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Equalization Example

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II

s0 = T r0( ) = 8 1( ) pr rj( )j=0

0

= 7pr r0( ) = 7 0.19( ) = 1.33

s1 = T r1( ) = 8 1( ) pr rj( )j=0

1

= 7pr r0( ) + 7pr r1( ) = 7 0.19( ) + 7 0.25( ) = 1.33+1.75 = 3.08

s2 = T r2( ) = 8 1( ) pr rj( )j=0

2

= 7 0.19( ) + 7 0.25( ) + 7 0.21( ) = 1.33+1.75 +1.47 = 4.55

s3 = 5.67 s4 = 6.23 s5 = 6.65 s6 = 6.86 s7 = 7.00

Discrete CDF (transformation)Input Output Discrete Output0 1.33 11 3.08 32 4.55 53 5.67 64 6.23 65 6.65 76 6.86 77 7.00 7

pdf

Computed PDF

Page 30: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

sk = T rk( ) = L 1( ) pr rj( )j=0

k

Must round off tonearest integer valuesince only L integerlevels in output

Resulting histogramwhen trying to achieveuniform* equalizedhistogram

Histogram Equalization

© 2002 R. C. Gonzalez & R. E. Woods

*Resulting histogramis usually not uniformdue to discretenature of transform.In this case we onlyhave five outputlevels.

Page 31: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Equalization

© 2002 R. C. Gonzalez & R. E. Woods

dark

light

Low contrast

high contrast

Page 32: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Equalization

sk = T rk( ) = L 1( ) pr rj( )j=0

k

Page 33: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification

1. Compute pdf (histogram) for inputimage

2. Compute CDF sk for this PDF

3. Compute CDF vq for desired histogram

4. Match CDF’s for each sk tocreate mapping table byinverting G

© 2002 R. C. Gonzalez & R. E. Woods

G(z) would be astraight line forequalization.

Inverting a discrete function isfar easier than inverting acontinuous function

Page 34: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification

Actual transformedimage pdf

Specified pdf

CDF of specified pdf

Original pdf

Page 35: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification Example

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II

s0 = T r0( ) = 8 1( ) pr rj( )j=0

0

= 7pr r0( ) = 7 0.19( ) = 1.33

s1 = T r1( ) = 8 1( ) pr rj( )j=0

1

= 7pr r0( ) + 7pr r1( ) = 7 0.19( ) + 7 0.25( ) = 1.33+1.75 = 3.08

s2 = T r2( ) = 8 1( ) pr rj( )j=0

2

= 7 0.19( ) + 7 0.25( ) + 7 0.21( ) = 1.33+1.75 +1.47 = 4.55

s3 = 5.67 s4 = 6.23 s5 = 6.65 s6 = 6.86 s7 = 7.00

Discrete CDF of input histogramInput Output Discrete Output0 1.33 11 3.08 32 4.55 53 5.67 64 6.23 65 6.65 76 6.86 77 7.00 7

1. Compute the PDF of the image to be transformed

Output CDF(not discrete)

Rounded off

Page 36: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification Example

© 2002 R. C. Gonzalez & R. E. Woods 1999-2007 by Richard Alan Peters II

G z0( ) = 8 1( ) pz z j( )j=0

0

= 7pz z0( ) = 7 0( ) = 0

G z1( ) = 8 1( ) pz z j( )j=0

1

= 7pz z0( ) + 7pz z1( ) = 7 0( ) + 7 0( ) = 0

G z2( ) = 8 1( ) pz z j( )j=0

2

= 7 0( ) + 7 0( ) + 7 0( ) = 0

G z3( ) = 1.05 G z4( ) = 2.45 G z5( ) = 4.55 G z6( ) = 5.95 G z7( ) = 7.00

Discrete CDF of desired histogramInput Output Discrete Output0 0 01 0 02 0 03 1.05 14 2.45 25 4.55 56 5.95 67 7.00 7

2. Compute the PDF for the specified histogram

Rounded off

Page 37: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification Example

Discrete CDF desiredPixel CDF Discrete CDF0 0 01 0 02 0 03 1.05 14 2.45 25 4.55 56 5.95 67 7.00 7

3. Match the PDFs to get the transformation

Discrete CDF of input histogramInput CDF input CDF desired New Value0 1 (1.33) 1 (1.05) 31 3 (3.08) 2 (2.45) 42 5 (4.55) 5 (4.55) 53 6 (5.67) 6 (5.95) 64 6 (6.23) 6 (5.95) 65 7 (6.65) 7 (7.00) 76 7 (6.86) 7 (7.00) 77 7 (7.00) 7 (7.00) 7

Discrete CDF of input histogramInput CDF Discrete CDF0 1.33 11 3.08 32 4.55 53 5.67 64 6.23 65 6.65 76 6.86 77 7.00 7

Page 38: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification Example

4. Put mapping in a LUT

Input Transformed Value0 --> 31 --> 42 --> 53 --> 64 --> 65 --> 76 --> 77 --> 7

Page 39: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

MATLAB: Histogram Equalization

HISTOGRAM EQUALIZATION IN MATLAB

>> f=imread(‘fig10.10(a).jpg’); % load in figure 3.15(a)>> imshow(f) % show image in a window>> figure, imhist(f) % show histogram in a new window % This histogram is not normalized.>> ylim(‘auto’) % set histogram tick marks and % axis limits automatically>> g=histeq(f,256); % Create histogram equalized image % you can also do this with % the cumsum function>> hnorm=imhist(f)./numel(f); % compute normalized histogram>> figure, imshow(g) % show this figure in a new window>> figure, imhist(g) % generate a histogram of % the equalized image>> ylim(‘auto’) % set limits again

SEE GWE, Section 3.3.3 for a discussion of histogram specification using MATLAB

Page 40: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

MATLAB: Useful Transformations

THRESHOLDING

>> f=imread(‘fig10.10(a).jpg’); % load in an image>> g=(f>100)*255 % show figure in a new window

(f>100) evaluates to 1 (true) if the pixel is >100, or 0 (false) if the pixel is 100

Multiplying by 255 is necessary to have a uint8 255 level image.

ROTATION

>> f=imread(‘fig10.10(a).jpg’); % load in an image>> g=imrotate(f,angle,’method’); % rotate it by angle

%Supports methods: ‘nearest’, ‘bilinear’, ’bicubic’

bilinear

Page 41: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

MATLAB: Getting Picture Coordinates

INPUT CURSOR VALUES

%(Very useful for specifying reference points in an image)>> [x,y]=ginput%Displays the graph window, displays a cross hair. Will input%coordinate pairs from the graph window until you type return.%Position cursor using mouse and click to input each coordinate pair.

x = 778.3362 619.7249 844.4242 465.5196

y = 213.0831 327.6357 470.8264 609.6112

>> [x,y]=ginput(n)Will input n coordinate pairs until you press return

Page 42: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

original + gamma- gamma + brightness- brightness

original + contrast- contrast histogram EQhistogram mod

Examples of Point Processing

1999-2007 by Richard Alan Peters II

Page 43: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram

Page 44: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Equalization

Page 45: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Histogram Specification

Manuallyspecifiedhistogram h

(1) CDF sk=G(zq)corresponding to h

(2) Inverse transform z=G-1(sk)for intensity mapping

Resultinghistogram

Page 46: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Local Histogram Operations

Page 47: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Local Histogram Operations

g x, y( ) =Ei f x, y( ) if mSxy

k0mg AND k1 G Sxyk2 G

f x, y( ) otherwise

compare to globalmean mG and standarddeviation G

Page 48: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Spatial Neighborhoods

1999-2007 by Richard Alan Peters II

Page 49: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

( ) [ ]( )

( ) { } { }{ }( ).,...,...,,,...,...,,

,,

dccdcvsrrsruvuIf

crITcrJ

++

==

That is, the value of the transformed image, J, at pixel location

(r,c) is a function of the values of the original image, I, in a 2s+1

2d+1 rectangular neighborhood centered on pixel location (r,c).

Let I and J be images such that J = T [I].

T [·] represents a transformation, such that,

Spatial Filtering

1999-2007 by Richard Alan Peters II

Page 50: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

• The value, J(r,c) = T[I](r,c), is a function of a rectangular

neighborhood centered on pixel location (r,c) in I.

• There is a different neighborhood for each pixel location,

but if the dimensions of the neighbor-hood are the same for

each location, then trans-form T is sometimes called a

moving window transform.

Moving Windows

1999-2007 by Richard Alan Peters II

Page 51: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Spatial Filtering

© 2002 R. C. Gonzalez & R. E. Woods

Page 52: Lecture #5 - Case Western Reserve Universityengr.case.edu/merat_francis/eecs490f07/Lectures/Lecture5.pdf · 2012-02-16 · 4 = 6.23 s 5 = 6.65 s 6 = 6.86 s 7 = 7.00 Discrete CDF (transformation)

EECS490: Digital Image Processing

Moving-Window Transformations

NeutralBuoyancyFacility atNASAJohnsonSpaceCenter

We’ll take asection ofthis image todemonstratethe MWT

photo: R.A.Peters II, 1999

1999-2007 by Richard Alan Peters II