81
DREAM PLAN IDEA IMPLEMENTATION 1

DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: [email protected]@yahoo.com Email: [email protected]@aut.ac.ir

Embed Size (px)

Citation preview

Page 1: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

1

DREAMDREAM

PLANPLANIDEAIDEA

IMPLEMENTATIONIMPLEMENTATION

Page 3: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

3

Introduction to Image ProcessingIntroduction to Image Processing

Dr. Kourosh KianiEmail: [email protected]: [email protected]: [email protected]: www.kouroshkiani.com

Present to:Amirkabir University of Technology (Tehran

Polytechnic) & Semnan University

Page 4: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

4

Lecture 05

Mask processing orSpatial filter

Page 5: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

IMAGE FILTERING METHODS

Spatial Domain

Frequency Domain (i.e., uses Fourier Transform)

Page 6: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

POINT PROCESSING METHODS

Convert a given pixel value to a new pixel value based on some predefined function.

Page 7: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

AREA PROCESSING METHODS

Need to define:1. Area shape and size2. Operation

output image

Page 8: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

•Area shape is typically defined using a rectangular mask.

• Area size is determined by mask size.e.g., 3x3 or 5x5

• Mask size is an important parameter!

AREA SHAPE AND SIZE

Page 9: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

TERMINOLOGY

Neighborhood operation work with values of the image pixels and corresponding values of a sub image.

The sub image is called: Filter Mask Kernel Template Window

The values in a filter sub image are referred to as coefficients, rather than pixels.

Our focus will be on masks of odd sizes, e.g. 3x3, 5x5,…

Page 10: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

OPERATION

Typically linear combinations of pixel values. e.g., weight pixel

values and add them together.

Different results can be obtained using different weights. e.g., smoothing,

sharpening, edge detection).

mask

Page 11: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

EXAMPLE

0.50.5 00

0

0 00

mask

8

Modified image dataLocal image neighborhood

6 141 81

5 310

1

Page 12: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 13: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

COMMON LINEAR OPERATIONS

Correlation

Convolution

Page 14: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CORRELATION

A filtered image is generated as the center of the mask visits every pixel in the input image.

g(i,j)

h(i,j)

f(i,j)filteredimage

n x n mask

Page 15: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

HANDLING PIXELS CLOSE TO BOUNDARIES

0 0 0 ……

……

……

……

….0

• Option 1: Zero padding

• Option 2: Wrap around

• Option 3: Reflection

0 0 0 1 2 3 4 5 0 0 0

4 10 16 22 22

1 2 3*

3 4 5 1 2 3 4 5 1 2 3 4 5

19 10 16 22 23 5

3 2 1 1 2 3 4 5 5 4 3 2

7 10 16 22 27 5

Page 16: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 17: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 18: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CONVOLUTION PROPERTIES

Commutative:A*B = B*A

Associative:(A*B)*C = A*(B*C)

Linear: A*(B+C)= A*B+ A*B

Shift-InvariantA*B(x-x0,y-yo)= (A*B) (x-x0,y-yo)

Page 19: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

THE DELTA KERNEL

otherwise

xxifxx

0

1 00

0 1 0 x

A(x)*(x) = A(x)

otherwise

yyxxifyyxx

0

&1, 00

000 0 00 1 00 0 0

),( yx

A(x,y)*(x,y) = A(x,y)

Page 20: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Due to shift-invariance:

A(x,y)*(x-x0,y-y0) = A(x-x0,y-y0)

0 0 0

0 1 00 0 0

0 0 0

0 0 00 0 1

(x,y) (x-1,y-1)

1 2 3

4 5 67 8 9

A

*

0 0 0

0 0 00 0 1

(x-1,y-1)

=0 0 0

0 1 20 4 5

A(x-1,y-1)

(Zero padding)

9 7 8

3 1 26 4 5

A(x-1,y-1)

(Wrap around)=

Page 21: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CORRELATION – EXAMPLE

Page 22: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GEOMETRIC INTERPRETATION OF CORRELATION

Suppose x and y are two n-dimensional vectors:

The dot product of x with y is defined as:

Correlation generalizes the notion of dot product

1 2 1 2( , ,..., ) ( , ,..., )n nx x x x y y y y

1 1 2 2. ... n nx y x y x y x y

. | || |cos( )x y x y using vectornotation:

x

y

θ

Page 23: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GEOMETRIC INTERPRETATION OF CORRELATION (CONT’D)

cos(θ) measures the similarity between x and y

Normalized correlation (i.e., divide by lengths)

2 2

2 2

2 2 2 22 1/2 2 1/2

2 2 2 2

( , ) ( , )

( , )

[ ( , )] [ ( , )]

n n

n nk l

n n n n

n n n nk l k l

h k l f i k j l

N i j

h k l f i k j l

. | || |cos( ) cos( )| || |

x yx y x y or

x y

Page 24: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

NORMALIZED CORRELATION

• Measure the similarity between images or parts of images.

=

mask

Page 25: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

APPLICATION : TV REMOTE CONTROL

Page 26: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

• Traditional correlation cannot handle changes due to:

• size• orientation • shape (e.g., deformable objects).

NORMALIZED CORRELATION

?

Page 27: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CONVOLUTION

Same as correlation except that the mask is flipped, both horizontally and vertically.

h * f = f * h

Notation:

1 2 3

4 5 6

7 8 9

7 8 9

4 5 6

1 2 3

9 8 7

6 5 4

3 2 1

H V

2 2 2 2

2 2 2 2

( , ) ( , ) ( , ) ( , ) ( , )

n n n n

n n n nk l k l

g i j h k l f i k j l h i k j l f k l

For symmetric masks (i.e., h(i,j)=h(-i,-j)), convolution is equivalent to correlation!

Page 28: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CORRELATION/CONVOLUTION EXAMPLES

Correlation:

Convolution:

Page 29: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 30: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

A = [10 20 30;40 50 60;70 80 90]A =10. 20. 30. 40. 50. 60. 70. 80. 90. H = [1 2 3;4 5 6;7 8 9]H =1. 2. 3. 4. 5. 6. 7. 8. 9.

Correlation result = (10 x 1) + (20 x 2) + (30 x 3) + (40 x 4) + (50 x 5) + (60 x 6) + (70 x 7) + (80 x 8) + (90 x 9) = 2850

Convolution and Correlation in Image Processing is quite similar except that the kernel are rotated 180 degree between these 2 operation.

Convolution and Correlation in Image Processing

Page 31: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

A = [10 20 30;40 50 60;70 80 90]A =10. 20. 30. 40. 50. 60. 70. 80. 90. H = [1 2 3;4 5 6;7 8 9]H =1. 2. 3. 4. 5. 6. 7. 8. 9.H180= 9 8 76 5 43 2 1

Convolution and Correlation in Image Processing

Convolution result = (10 x 9) + (20 x 8) + (30 x 7) + (40 x 6) + (50 x 5) + (60 x 4) + (70 x 3) + (80 x 2) + (90 x 1) = 1650

Page 32: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

In the real Image convolution and correlation, the kernel is sliding over every single pixel and performs above operation to form a new image

Convolution and Correlation in Image Processing

Page 33: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 34: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 35: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 36: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 37: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 38: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir
Page 39: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

A = [10 20 30;40 50 60;70 80 90]A =10. 20. 30. 40. 50. 60. 70. 80. 90. H = [1 2 3;4 5 6;7 8 9]H =1. 2. 3. 4. 5. 6. 7. 8. 9.

corr_result = imfilter(A,H)corr_result =1350. 1680. 1950. 2520. 2850. 3120. 3150. 3480. 3750. -->conv_result = imfilter(A,rot90(H,2))conv_result =750. 1020. 1350. 1380. 1650. 1980. 2550. 2820. 3150.

Convolution and Correlation in Image Processing

Page 40: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Most of the time the choice of using the convolution and correlation is up to the preference of the users, and it is identical when the kernel is symmetrical. For example, a smoothing filter which is:

Convolution and Correlation in Image Processing

Page 41: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

TWO 3X3 SMOOTHING LINEAR FILTERS

1 1 1

1 1 1

1 1 1

1 2 1

2 4 2

1 2 1

9

1 16

1

Standard average Weighted average

Page 42: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

000

010

000

H

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Page 43: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

010

111

010

5

1H

Origin

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Blur

Page 44: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

00100

01110

11111

01110

00100

13

1H

Origin

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Blur

Page 45: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Motion Blur Origin

100000000

010000000

001000000

000100000

000010000

000001000

000000100

000000010

000000001

9

1H

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Motion blur is achieved by blurring in only 1 direction

Page 46: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Find Edges

00000

00000

00211

00000

00000

H

Origin

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

A filter of 5x5 instead of 3x3 was chosen, because the result of a 3x3 filter is too dark on the current image. Note that the sum of all the elements is 0 now, which will result in a very dark image where only the edges it detected are colored.

Page 47: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

111

191

111

H

Origin

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Sharpen

Page 48: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

111

171

111

H

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

Extra Edge

Here's a filter that shows the edges excessively

Origin

Page 49: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

110

101

011

H

kk=imread(‘nice.jpg');corr_result = imfilter(kk,H); imshow(corr_result)

OriginEmboss

An emboss filter gives a 3D shadow effect to the image, the result is very useful for a bumpmap of the image

Page 50: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

30 10 20

10 25 250

20 25 30

10 ,10 ,20 ,20 ,25 ,25 ,30 ,30 ,250

min max

Min filter:

Max filter

yxNnmnmfyxf ,,,min,

yxNnmnmfyxf ,,,max,

Min & Max Filters

Page 51: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

30 10 20

10 25 250

20 25 30

10 ,10 ,20 ,20 ,25 ,25 ,30 ,30 ,250

median

The Median Filter

yxNnmnmfmedyxf ,,,,

Page 53: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

AVERAGE FILTER FOR NOISE REDUCTION

Noisy image

3x3 average 5x5 average 7x7 average median

Page 54: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

AVERAGING FILTER VS. MEDIAN FILTER

Filtering is often used to remove noise from imagesSometimes a median filter works better than an averaging filter

Original ImageWith Noise

Image AfterAveraging Filter

Image AfterMedian Filter

Page 55: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

NOISY IMAGES

Original

Gaussian noise

salt & pepper

Page 56: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Median filter3x3 window

Gaussian blurstd=1.5

Salt & Pepper Noise:

Page 57: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Median filter5x5 window

Gaussian blurstd=1.5

Gaussian Noise:

Page 58: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

RESULT OF MEDIAN FILTER

Noise from Glass effectRemove noise by median filter

Page 59: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CONVOLUTION Separable Filter 1 2 1

12 4 2

161 2 1

0 1 0 0 0 01 1

= 0 2 0 1 2 1 .4 4

0 1 0 0 0 0V H

h

h h

Page 60: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

PROPERTIES OF GAUSSIAN

Convolution with self is another Gaussian

• Special case: convolving two times with Gaussian kernel of width is equivalent to convolving once with kernel of width

* =

Page 61: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

PROPERTIES OF GAUSSIAN

• Separable kernel: a 2D Gaussian can be expressed as the product of two 1D Gaussians.

Page 62: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

PROPERTIES OF GAUSSIAN

2D Gaussian convolution can be implemented more efficiently using 1D convolutions:

Page 63: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

PROPERTIES OF GAUSSIAN (CONT’D)

row get a new image Ir

Convolve each column of Ir with g

Page 64: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

EXAMPLE

2D convolution(center location only)

The filter factorsinto a product of 1D

filters:

Perform convolutionalong rows:

Followed by convolutionalong the remaining column:

*

*

=

=

O(n2)

O(2n)=O(n)

Page 65: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

CONVOLUTION Complexity of non-separable filter: N2

Complexity of separable filter: 2N

Complexité (nb mult/add versus N)

0

50

100

150

200

250

300

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16

Non séparable

Séparable

Page 66: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

HOW DO WE CHOOSE THE MASK WEIGHTS?

Depends on the application. Usually by sampling certain functions and

their derivatives.

Gaussian1st derivativeof Gaussian

2nd derivativeof Gaussian

Good forimage smoothing

Good for image sharpening

Page 67: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

NORMALIZATION OF MASK WEIGHTS

Sum of weights affects overall intensity of output image. Positive weights

Normalize them such that they sum to one. Both positive and negative weights

Should sum to zero (but not always)

1/9 1/16

Page 68: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

• Idea: replace each pixel by the average of its neighbors.

• Useful for reducing noise and unimportant details.

•The size of the mask controls the amount of smoothing.

SMOOTHING USING AVERAGING

Page 69: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

SMOOTHING USING AVERAGING

Trade-off: noise vs blurring and loss of detail.

3x3 5x5 7x7

15x15 25x25

original

Page 70: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GAUSSIAN SMOOTHING

Idea: replace each pixel by a weighted average of its neighbors

Mask weights are computed by sampling a Gaussian function

Note: weight values decrease with distance from mask center!

Page 71: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GAUSSIAN FILTER

The Gaussian kernel is separable and symmetric.

To construct the kernel we must sample and quantize! (basically, we “image” the function)

The kernel below is an example where sigma = 1.

1 4 7 4 1

4 16 28 16 4

7 28 49 28 7

4 16 28 16 4

1 4 7 4 1

Page 72: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GAUSSIAN SMOOTHING

mask size depends on σ :

• σ determines the degree of smoothing!σ=3

Page 73: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

GAUSSIAN SMOOTHING - EXAMPLE

= 30 pixels= 1 pixel = 5 pixels = 10 pixels

Page 74: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

AVERAGING VS GAUSSIAN SMOOTHING

Averaging

Gaussian

Page 75: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

IMAGE SHARPENING

Idea: compute intensity differences in local image regions.

Useful for emphasizing transitions in intensity (e.g., in edge detection).

1st derivativeof Gaussian

Page 76: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

EXAMPLE

Page 77: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Zooming as a Convolution Application Example

1 3 2

4 5 6

Zerointerlace

1 0 3 0 2 0

0 0 0 0 0 0

4 0 5 0 6 0

0 0 0 0 0 0

Convolve

1 1 1

1 1 1

1 1 1

The value of a pixel in the enlarged image is the average of the value of around pixels. The difference between insert 0 and original value of pixels is “smoothed” by convolution

Original Image

(1+0+3+0+0+0+4+0+5) ÷(1+1+1+1+1+1+1+1+1) = 13/9

Page 78: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Zooming as a Convolution Application Example

Page 79: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

f

y

EXAMPLE

f

x

Page 80: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

Questions? Discussion? Suggestions?

Page 81: DREAM PLAN IDEA IMPLEMENTATION 1. 2 3 Introduction to Image Processing Dr. Kourosh Kiani Email: kkiani2004@yahoo.comkkiani2004@yahoo.com Email: Kourosh.kiani@aut.ac.irKourosh.kiani@aut.ac.ir

81