image enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/project2/020410.pdfexample:...

23
Image Enhancement Department of Electrical and Computer Engineering Temple University Outline Spatial Operations Point processing Local processing Point processing Contrast stretching Logarithmic transformation Histogram equalization Histogram matching Local processing Spatial filtering Image sharpening

Upload: others

Post on 24-Sep-2020

38 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Image Enhancement

Department of Electrical and Computer Engineering

Temple University

Outline

• Spatial Operations

– Point processing

– Local processing

• Point processing

– Contrast stretching

– Logarithmic transformation

– Histogram equalization

– Histogram matching

• Local processing

– Spatial filtering

– Image sharpening

Page 2: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Image Enhancement

• Goal

– To process an image so that the result is more suitable than the original

image for visual interpretation

• Spatial domain approaches

– Direct manipulation of pixels in an image

– Intensity transformations (Point processing)– Intensity transformations (Point processing)

– Spatial filtering (working in a neighborhood of every pixel in an image)

• Transform domain approaches

– Enhancement carried out in the transform domain

– Processing transform coefficients of an image

Spatial Operations

• Point processing

– The output value at a specific coordinate is dependent only on the input

value at that same coordinate

T

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

• Local processing

– The pixel value at a specific coordinate in an output (processed) image

is determined by a specified operation on the input values in the

neighborhood of that same coordinate

T

{ }( , ) ( , )g x y T N f x y = ( , )f x y

Page 3: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Point Processing

• Gray-level transformation (mapping) applied to each pixel

– Gray scale manipulations

– Contrast manipulation

– Image thresholding

( )s T r=

• Manipulation of histograms for image enhancement

– Histogram stretching

– Histogram equalization

– Histogram matching (specification)

Basic Intensity Transformation Functions

• Intensity transformations

Page 4: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Contrast Stretching

• Contrast Stretching

– Increase the dynamic range of the gray levels

s

1( )

1 ( / )Es T r

m r= =

+

rm

Contrast stretchedOriginal image

Thresholding

• Binarization

– Converts a gray-scale image to a binary (black-and-white) image

s

L-1

{ 0 if 1 if

r ms

L r m<= − ≥

r

Binary-level image

L-1

L-1

m

Original image

Page 5: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Image Negatives

• Reversal of gray scale

– Reverse the intensity levels of an image

– To enhance white or gray detail embedded in dark regions

s

1s L r= − −

rL-1

L-1

Image negativeOriginal image

Image Negatives – Application

• Digital mammogram

– Black areas are dominant in size

– Details are in the dark region

Original image Image negative

Page 6: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Log Transformation

• Logarithmic contrast enhancement

– Brighten dark images

s

log(1 )s c r= +

Log transformationOriginal image

rL-1

L-1

Log Transformation – Applications

Log transformation

Fourier magnitude

Page 7: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Power-Law (Gamma) Transformations

• Basic form

– Gamma < 1: Maps a narrow range of dark input values into a wider

range of output values

s crγ=

1c =

Gamma Correction

0 0.5 10

0.5

1

Gamma = 0.42

0 0.5 10

0.5

1

Gamma = 2.1

Page 8: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Gamma Correction – Applications

• Correction of monitor response

Gamma Correction – Applications

• MR image of human spine

– c = 1, γ = 0.6

• Aerial image

– c = 1, γ = 3.0

Enhanced imageOriginal image

Page 9: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Piecewise Linear Transformations

• Low contrast images

– Can result from poor illumination, lack of dynamic range in the

imaging sensor, or wrong setting of a lens aperture

• Contrast stretching

– Expands the range of intensity levels in an image so that it spans the

full intensity range of the recording medium or display devicefull intensity range of the recording medium or display device

Contrast

• Contrast is a property based on human perception

• An approximate definition of contrast

– F and B are the mean gray-levels of two regions whose contrast is

evaluated

contrastF B

F B

−=

+

• The larger the contrast between image parts, the larger the

enhancement

contrastF B

=+

Page 10: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Contrast Stretching

• Contrast stretching

Brightness Adjustment

• Brightness adjustment

0.5

1

Intensity Transformation

0 0.5 10

Page 11: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Obtaining Image Histogram

• Initialize frequency bins

– For a B-bit image, initialize the array h of 2B counters with zero

• For all pixels (x,y) of the image f, increment h[f(x,y)] by 1

( )h k

k( , )f x y

Cumulative Histogram

• Sum of pixels under a certain gray level

• Relationship with histogram

Cumulative histogram Histogram

{ } [ ]( ) ( , ) | ( , ) , 0, 1H k n f x y f x y k k L= < ∈ −

0

( ) ( )k

i

H k h i=

=∑ ( ) ( ) ( 1)h k H k H k= − −

Cumulative histogram Histogram

Page 12: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Processing

• Provides the frequency of the brightness value in the image

– An estimate of the probability density function (pdf) of brightness levels as a

random process

• Histogram

– The histogram of an M×N digital image with intensity levels in the

range [0, L-1] is a discrete functionrange [0, L-1] is a discrete function

– rk: k-th intensity value

– nk: the number of pixels in the image with intensity rk

– Often normalize a histogram by the total number of pixels

( ) , 0,1,2, , 1kk

np r k L

MN= = −⋯

( )k kh r n=

Histogram Processing

• Four basic image types

– Dark, light, low-contrast, high-contrast

Page 13: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Stretching

• Stretch the histogram over the entire dynamic range

min

max min

( , )( , ) ( 1)

f x y fg x y L

f f

−= −

Histogram stretched

Window and Level Contrast Enhancement

• Expansion of the contrast of the pixels within a given window range

– Level (L): Middle point

– Window (W): Width of the range

• Example: Window and Level contrast enhancement technique

– The window ranges from the minimum to the maximum pixel values of

the image

Page 14: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Example: Window and Level

• Original CT image

– Pixel values: [1024, 1862]

• Enhanced image

– Window = 100, Level = 1100

Original CT image Enhanced CT image

Example: Window and Level

• Contrast Adjustment

0.5

1

Intensity Transformation

0 0.5 10

Page 15: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Equalization

• To produce an image with uniformly distributed brightness levels

over the whole brightness scale

• Automatically determines a transformation function that seeks to

produce an output image that has a uniform histogram

s

( )s T r=

( )rp r

r

( )sp s

s

s

r

Input histogram equalized histogram

Histogram Equalization Mapping

• (Continuous) intensity mapping

• Assumptions

– T(r): monotonically increasing function

( ) , 0 1s T r r L= ≤ ≤ −

0 ( ) 1 for 0 1T r L r L≤ ≤ − ≤ ≤ −

Page 16: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Review: Probability Density Functions

• Transformation

• Probability density function of the transformed variable

( ) ( )s r

drp s p r

ds=

( ) , 0 1s T r r L= ≤ ≤ −

( ) ( )s rp s p rds

=

Histogram Equalization

• Consider a transformation

– Cumulative distribution function (cdf)

0

( )

( 1) ( )

( 1) ( )

r

r

ds dT r

dr dr

dL p w dw

dr

L p r

=

= − = −

0( ) ( 1) ( )

r

rs T r L p w dw= = − ∫

• PDF of the transformed intensity levels

( 1) ( )rL p r= −

( ) ( )

1( )

( 1) ( )

1, 0 1

1

s r

r

r

drp s p r

ds

p rL p r

s LL

=

=−

= ≤ ≤ −−

Page 17: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Equalization – Example

• Input PDF

• The transformation

2

20 1

( 1)( )

0 otherwise

r

rr L

Lp r

≤ ≤ − −=

2

0 0

2( ) ( 1) ( )

1 1

r r

r

rs T r L p w dw wdw

L L= = − = =

− −∫ ∫

• Output PDF

1 1L L− −

1

2

12

2

2

2( ) ( )

( 1)

2

( 1) 1

2 1 1

( 1) 2 1

s r

dr r dsp s p r

ds L dr

r d r

L dr L

r L

L r L

= = −

= − −

− = = − −

Histogram Equalization (Discrete)

• Histogram (PDF estimate)

• Histogram equalization transformation

– Discrete form of the transformation

( ) , 0,1,2, , 1kr k

np r k L

MN= = −⋯

0

0

( ) ( 1) ( )

( 1)

k

k k r j

j

k

j

j

s T r L p r

Ln

MN

=

=

= = −

−=

Page 18: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Example

• A 3-bit image of size 64×64 pixels

– L = 8, MN = 4,096

• Histogram equalization transformation

0

0 0 0

0

( ) 7 ( ) 7 ( ) 7(0.19) 1.33r j r

j

s T r p r p r=

= = = = =∑

( )1

1 1 0 1

0

( ) 7 ( ) 7 ( ) ( ) 7(0.19 0.25) 3.08r j r r

j

s T r p r p r p r=

= = = + = + =∑

2 3 4 5 6 74.55, 5.67, 6.23, 6.65, 6.86, 1.0s s s s s s= = = = = =

Example

• Output histogram

– Rounding to the nearest integer

0 4

1 5

2 6

1.33 1 6.23 6

3.08 3 6.65 7

4.55 5 6.86 7

5.67 6 7.00 7

s s

s s

s s

s s

= → = →

= → = →

= → = →

= → = →3 7

5.67 6 7.00 7s s= → = →

Page 19: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Example: Histogram Equalization

Example: Histogram Equalization

Page 20: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Example: Histogram Equalization

• Histogram equalized images

– Center

Histogram Matching (Specification)

• Generalization of histogram equalization

– Uniform histogram is not the best approach

– Specify the shape of the histogram that the processed image must have

• Histogram matching (specification)

– To generate a processed image that has a specified histogram

Input histogram Specified histogram( )z W r=

( )zp z( )rp r

r

r

z

z

Page 21: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Matching

• Idea

– Gray-level transformations

• Histogram equalization

1( ) ( ), ( ) , ( ) , ( )

s T r z G s

r s zr p r s p s z p z−= =→ →

( ) ( 1) ( )r

rs T r L p w dw= = − ∫

• Histogram matching transformation

0( ) ( 1) ( )rs T r L p w dw= = − ∫

0( ) ( 1) ( )

z

zG z L p t dt s= − =∫

[ ]1 1( ) ( )z G s G T r− −= =

Histogram Matching – Example

• PDFs

• Procedure

– Histogram equalization

2

20 1

( 1)( )

0 otherwise

r

rr L

Lp r

≤ ≤ − −=

2

3

30 1

( ) ( 1)

0 otherwise

z

zz L

p z L

≤ ≤ −

= −

– Histogram specification

2

0 0

2( ) ( 1) ( )

( 1) ( 1)

r r

r

rs T r L p w dw wdw

L L= = − = =

− −∫ ∫

32

2 20 0

3( ) ( 1) ( )

( 1) ( 1)

r z

z

zG z L p w dw w dw

L L= − = =

− −∫ ∫

Page 22: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Matching – Example

• Require

• Desired transformation

3

2( )

( 1)

zs G z

L= =

1/31/32

1/32 2

1/32

( 1) ( 1)( 1)

( 1)

( )

rz L s L

L

L r

W r

= − = − −

= −

=

Histogram Matching (Discrete Implementation)

• Obtain the histogram of the given image

• Histogram equalization

0

0

( ) ( 1) ( )

( 1), 0,1,2, , 1

k

k k r j

j

k

j

j

s T r L p r

Ln k L

MN

=

=

= = −

−= = −

∑ ⋯

( ), 0,1, , 1r ip r i L= −⋯

• Find the transformation G from the given pz(z)

• Inverse transformation

• For each pixel in the original image, map rk to sk then into final level zk

0

( ) ( 1) ( )k

k z i

i

G z L p z=

= − ∑

1( ) ( )k k k kG z s z G s−= → =

Page 23: Image Enhancementread.pudn.com/downloads290/sourcecode/graph/1305239/Project2/020410.pdfExample: Histogram Equalization • Histogram equalized images –Center Histogram Matching

Histogram Specification – Example

• Histogram equalization

• Find the transformation G from the given pz(z)

0 1 2 3

4 5 6 7

1 3 5 6

6 7 7 7

s s s s

s s s s

= = = =

= = = =

0

0( ) 7 ( ) 0.00z jG z p z= =∑

[ ]

0

0

1

1 0 1

0

( ) 7 ( ) 0.00

( ) 7 ( ) 7 ( ) ( ) 0.00

z j

j

z j z z

j

G z p z

G z p z p z p z

=

=

= =

= = + =

∑⋯

0 4

1 5

2 6

3 7

( ) 0.00 0 ( ) 2.45 2

( ) 0.00 0 ( ) 4.55 5

( ) 0.00 0 ( ) 5.95 6

( ) 1.05 1 ( ) 7.00 7

G z G z

G z G z

G z G z

G z G z

= → = →

= → = →

= → = →

= → = →

Histogram Specification – Example

• Find the mapping from s to z

– Find the smallest value of z so that the value G(z) is the closest to s

r s z

0 1 3

1 3 4

2 5 5

3 6 6

4 6 6

5 7 7

6 7 7

7 7 7