EEM 463 Introduction to Image Processing Week 3: Intensity...

60
EEM 463 Introduction to Image Processing Week 3: Intensity Transformations Fall 2013 Instructor: Hatice Çınar Akakın, Ph.D. [email protected] Anadolu University

Transcript of EEM 463 Introduction to Image Processing Week 3: Intensity...

Page 1: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

EEM 463 Introduction to Image Processing

Week 3: Intensity Transformations

Fall 2013

Instructor: Hatice Çınar Akakın, Ph.D.

[email protected]

Anadolu University

Page 2: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Enhancement Domains

• Spatial Domain: image plane itself, direct manipulation of pixels

• Transform domain: process on the transform domain coefficients

( , ) [ ( , )])

( , ) : input image

( , ) : output image

: an operator on defined over

a neighborhood of point ( , )

g x y T f x y

f x y

g x y

T f

x y

Spatial domain

process

Page 3: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Enhanced Images

• For human vision• Evaluation of image quality is a highly subjective process

• No standard for a for a good image definition

• For machine perception• Evaluation of image quality is easier

• Best machine results represents the good image

• Trail and error is necessary to select an appropriate imageenhancement approach.

• e.g. a method that is quite useful for enhancing X-Ray images may not be thebest for satellite images taken in infrared band of EM specytrum.

Page 4: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 5: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Intensity Transformation

T : intensity transformation function

s = T( r )

Highercontrast

Two-level(binary) image

Point processşng

Page 6: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

• Tree basic gray-level transformation

f’ns.• Linear function: Negative and intensity

transformations

• Logarithmic function: Log snd inverse-log

transformations

• Power-law function: nth power and nth root

transformations

Page 7: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Image Negatives

Image negatives

1s L r

Suitable for enhancing white or gray detail

embedded in dark regions of an image, especially when black area is large.

Same visualcontent

Page 8: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Log Transformations

Log Transformations

log(1 )s c r

• Log curve maps a narrow range of low

graylevels in input image into a wider

range of output levels.

• Expands range of dark image pixels while

shrinking bright range.

• Inverse log expands range of bright image

pixels while shrinking dark range.

Page 9: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Power-Law Transformation

• It is also called Gamma Correction

s cr

Page 10: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

1/2.5s r

Cathode ray tube (CRT) devices have an intensity-to-voltage response that is a power function, with exponents varying from approximately 1.8 to 2.5

This darkens the picture.

• Gamma correction is done by

preprocessing the image

before inputting it to the

monitor.

Page 11: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

a) Dark MRI. Expand gray level

range for contrast manipulation

γ < 1

(b) γ = 0.6, c=1

(c) γ = 0.4 (best result)

(d) γ = 0.3 (limit of acceptability)

When γ is reduced too much, the

İmage begins to reduce contrast to

the point where it starts to have a

“washed-out” look,especially in

the background

Page 12: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

• Washed-out image. • Shrink gray level range

• γ > 1

Page 13: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Piecewise-Linear Transformation Functions

• Pro: can be arbitrarily complex

• Con: specification requires considerably more user input

Page 14: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

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 device.

Page 15: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Intensity level slicing

Highlights a specific range of intensities

Page 16: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Bit-plane slicing

highlight the contribution made to total image

appearance by specific bits

Page 17: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 18: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Originalimage

Page 19: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Histogram Processing

Normalized histogram ( )

: the number of pixels in the image of

size M N with intensity

kk

k

k

np r

MN

n

r

Histogram ( )

is the intensity value

is the number of pixels in the image with intensity

k k

th

k

k k

h r n

r k

n r

Estimate of theprobability of occurrence of intensity level

Page 20: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

• Basis for numerous spatial domain processing techniques

• Provides useful image statistics

• Useful for image enhancement, image compression andsegmentation

Components ofhistogram areconcentrated on the low side of the gray scale.

Components ofhistogram areconcentrated on the high side of the gray scale.

Page 21: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Histogram Equalization

• Probability density function (pdf) is wanted to be uniformly ditributed.

( ) 0 1s T r r L

. T(r) is a strictly monotonically increasing function

in the interval 0 -1;

. 0 ( ) -1 for 0 -1.

a

r L

b T r L r L

Page 22: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

( ) is continuous and differentiable.T r ( ) ( )s rp s ds p r dr

0

( )( 1) ( )

r

r

ds dT r dL p w dw

dr dr dr

( 1) ( )rL p r

( ) 1( ) ( )

( )( 1) ( ) 1

r r rs

r

p r dr p r p rp s

L p rdsds L

dr

Cumulativedistribution function

(cdf)0( ) ( 1) ( )

r

rs T r L p w dw

Page 23: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 24: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Histogram Equalization

0

Discrete values:

( ) ( 1) ( )k

k k r j

j

s T r L p r

0 0

1( 1) k=0,1,..., L-1

k kj

j

j j

n LL n

MN MN

Page 25: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Example: 3-bit image (L=8), 64x64pixels

0

0 0

0

( ) 7 ( ) 7 0.19 1.33r j

j

s T r p r

1

1 1

0

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

j

s T r p r

Page 26: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 27: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Tend to spread the histogram of the input image

• intensity levels of the equalized image span a

wider range

• contrast enhancement

Page 28: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Histogram Matching (Specification)

• If uniform distribution is not a good approach• Generate a processed image that has a specified histogram

Let ( ) and ( ) denote the continous probability

density functions of the variables and . ( ) is the

specified probability density function.

Let be the random variable with the prob

r z

z

p r p z

r z p z

s

0

0

ability

( ) ( 1) ( )

Define a random variable with the probability

( ) ( 1) ( )

r

r

z

z

s T r L p w dw

z

G z L p t dt s

0

0

( ) ( 1) ( )

( ) ( 1) ( )

r

r

z

z

s T r L p w dw

G z L p t dt s

1 1( ) ( )z G s G T r

Page 29: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Procedure• Obtain pr(r) from the input image and then obtain the values of s

• Use the specified PDF and obtain the transformation function G(z)

• Mapping from s to z

• Obtain the output image by equalizing the input image. For each pixel withvalue s in the equalized image, perform the inverse mapping to obtainoutput pixels.

0( 1) ( )

r

rs L p w dw

0( ) ( 1) ( )

z

zG z L p t dt s

1( )z G s

pz(z) is given!

Page 30: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Discrete Formulation

• pz(zk): specified pdf

• Tansformation function:

• Mapping:

0 0

( 1)( ) ( 1) ( )

k k

k k r j j

j j

Ls T r L p r n

MN

0

( ) ( 1) ( )q

q z i k

i

G z L p z s

1( )q kz G s

Page 31: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 32: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

(1): G(z)(2): G-1(z)

Page 33: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

• For the details of histogram processing, read Chapter 3.1-3.3

Page 34: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Fundamentals of Spatial Filtering

• Spatial filter: spatial masks, kernels, templates or windows

• Filtering creates a new pixel with coordinates equal to the center of the neighborhood, with value of the result of filtering operation

( , ) ( , ) ( , )a b

s a t b

g x y w s t f x s y t

Page 35: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 36: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Spatial Correlation and Convolution

• Correlation is a process of moving a filter mask over the image andcomputing the sum of products at each location

• Convolution has the same mechanics but with a filter rotated by 180°.

Page 37: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 38: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Spatial Correlation and Convolution

The convolution of a filter ( , ) of size

with an image ( , ), denoted as ( , ) ( , )

w x y m n

f x y w x y f x y

( , ) ( , ) ( , ) ( , )a b

s a t b

w x y f x y w s t f x s y t

*

Page 39: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 40: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Smoothing Spatial Filters

• Output is the average of pixels caontained in the neighborhood of thefilter mask

• Averaging filters or lowpass filters

• Reduce sharp transitions in intensities

• Used for blurring and noise reduction• Blurring removes small details and connects small gaps in lines or curves

• They can be linear or nonlinear filters

Page 41: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

The general implementation for filtering an M N image

with a weighted averaging filter of size m n is given

( , ) ( , )

( , )

( , )

where 2 1

a b

s a t b

a b

s a t b

w s t f x s y t

g x y

w s t

m a

, 2 1.n b

Sum of the mask coefficients: constantcomputed only once

Page 42: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

• To generate a mxn linear filter, we need to specify mn mask coefficients, selected based on the purpose of the filter

• Example: Spatial filter mask based on a continuous function of two variables, e.g. Gaussian Function:

Page 43: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Note that:

• big mask is used to eliminate small

objects from an image.

• the size of the mask establishes the

relative size of the objects that will be

blended with the background.

Page 44: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

- Blur to get gross representation of objects.- Intensity of smaller objects blend with background.- Larger objects become blob-like and easy to detect

Threshold value is chosen to be 25% of the

highest intensity

Page 45: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Order-Statistic (Nonlinear) Filters

• It is based on ordering (ranking) the pixels contained in the filter mask

• Center pixel value is replaced with the value of ranking result• Median filter

• Max filter

• Min filter

Page 46: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 47: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Sharpening Spatial Filters

• Objective is to highlight transitions in intensity

• Spatial differentiation enhances the edges and other discontinuities

Foundation

1. The first-order derivative of a one-dimensional function f(x) is the difference

2. The second-order derivative of f(x) as the difference

( 1) ( )f

f x f xx

2

2( 1) ( 1) 2 ( )

ff x f x f x

x

Page 48: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 49: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

The Laplacian Operator

• Isotropic filter: response independent of the direction of thediscontinuities in the image (rotation invariant)

• Laplacian of a function f(x,y):

• Discrete form:

2 22

2 2

f ff

x y

2

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

ff x y f x y f x y

x

2

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

ff x y f x y f x y

y

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

- 4 ( , )

f f x y f x y f x y f x y

f x y

Page 50: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 51: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 52: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Unsharp masking and Highboost Filtering

• Unsharp masking:• Blur the original image 𝑓(𝑥, 𝑦) 𝑓(𝑥, 𝑦)

• Subtract the blurred image 𝑓(𝑥, 𝑦) from the original image 𝑓(𝑥, 𝑦)mask

𝑔𝑚𝑎𝑠𝑘 = 𝑓 𝑥, 𝑦 − 𝑓(𝑥, 𝑦)

• Add the mask to the original image:

𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑘 ∗ 𝑔𝑚𝑎𝑠𝑘 𝑥, 𝑦 k≥0

k = 1 unsharp maskingk > 1 highboost filtering

Page 53: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 54: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values
Page 55: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Image Sharpening based on First-Order Derivatives

For function ( , ), the gradient of at coordinates ( , )

is defined as

grad( )x

y

f x y f x y

f

g xf f

fg

y

2 2

The of vector , denoted as ( , )

( , ) mag( ) x y

magnitude f M x y

M x y f g g

Gradient Image

Page 56: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

( , ) | | | |x yM x y g g

Robert’s cross-gradient operators

Sobel operators

Page 57: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

7 8 9 1 2 3

3 6 9 1 4 7

Sobel Operators

( , ) | ( 2 ) ( 2 ) |

| ( 2 ) ( 2 ) |

M x y z z z z z z

z z z z z z

Page 58: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Combining Spatial Enhamement Methods

Page 59: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Calculating the histogram

• %

% reading image from the file

im = imread('C:\Users\user\Documents\Documents\EEM463\Butterfly-yorkshire_rose.jpg');

im1 = double(rgb2gray(im));

% size of the image

[M N]= size(im1);

for k = 0:255

p(k+1) = sum(sum(im1==k));

end

bar(0:255,p);

Page 60: EEM 463 Introduction to Image Processing Week 3: Intensity ...eem.eskisehir.edu.tr/haticecinarakakin/EEM 463/icerik/EEM463_3.pdf · (r) from the input image and then obtain the values

Normalizing an image

i1 = load('clown');

whos i1

i1

figure;image(X); colormap(map);

mx = max(max(X));

mn = min(min(X));

imN = 255*(X-mn)/(mx-mn);