Visualization in Medicine Lecture: Convolution

32
Dr. Engr. Sami ur Rahman Assistant Professor Department of Computer Science University of Malakand Visualization in Medicine Lecture: Convolution

description

Visualization in Medicine Lecture: Convolution. Overview. Function Signal Impulse Function Impulse Function Decomposition Impulse Response Convolution Convolution 1D Implementing 1D Convolution Convolution 2D Implementing 2D Convolution Image Filter. Function. Source: Wikipedia. - PowerPoint PPT Presentation

Transcript of Visualization in Medicine Lecture: Convolution

Page 1: Visualization in Medicine  Lecture: Convolution

Dr. Engr. Sami ur RahmanAssistant Professor

Department of Computer ScienceUniversity of Malakand

Visualization in Medicine

Lecture: Convolution

Page 2: Visualization in Medicine  Lecture: Convolution

Overview

Function Signal Impulse Function Impulse Function Decomposition Impulse Response Convolution

Convolution 1D Implementing 1D Convolution Convolution 2D Implementing 2D Convolution

Image Filter

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 2

Page 3: Visualization in Medicine  Lecture: Convolution

Function

A function is a relation between a set of inputs and a set of permissible outputs with the property that each input is related to exactly one output.

A function f takes an input x, and returns an output f(x)

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 3

Source: Wikipedia

Page 4: Visualization in Medicine  Lecture: Convolution

Signal

Signal: A function that conveys information about the behaviour or attributes of some phenomenon.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 4

Discrete-time signal created from a continuous signal by sampling

Page 5: Visualization in Medicine  Lecture: Convolution

Impulse Function (δ function)

The Impulse function (δ function) is a generalized function that is zero everywhere except at zero.

The impulse function, δ[n] is 1 at n=0, and zeros at n ≠ 0.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 5

Page 6: Visualization in Medicine  Lecture: Convolution

Impulse Function Decomposition

0 1 2 3

2

3

1

0 1 2 3

2

0 1 2 3

3

0 1 2 3

1

0 1 2 3

2

0 1 2 3

3

0 1 2 3

1 nx .20 1.30 nx 2.10 nx

A signal can be decomposed as a weighted sum of impulse function

Weighted sum of impulse functions

Page 7: Visualization in Medicine  Lecture: Convolution

Impulse Function Decomposition

A signal can be decomposed as a weighted sum of impulse function

The signal, x[n] can be represented by adding the shifted and scaled impulse functions

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 7

2.21.10.0

2.12.221.31.110.2.00

nxnxnxnxnnxxnnxx

nnxx

2.12

1.31.20

nxnxnx

Page 8: Visualization in Medicine  Lecture: Convolution

Impulse Function Decomposition

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 8

In general, a signal can be written as sum of scaled and shifted delta functions.

k

knkxnx .

2.21.10.0

2.12.221.31.11

.2.00

nxnxnxnx

nnxxnnxx

nnxx

Page 9: Visualization in Medicine  Lecture: Convolution

Impulse Response

Impulse response is the output of a system resulting from an impulse function as input. Impulse response is denoted as h[n]. 

Impulse response of time shifted impulse function

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 9

n nhSystem

kn knh System

0 1 2 3

2 1 1

2

0 1 2 3

1* = 0 1 2 3

2

System= any signal * impulse function

Page 10: Visualization in Medicine  Lecture: Convolution

Impulse Response: Scaling factor

If the system is linear, a scaled in input signal causes an identical scaling in the output signal.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 10

nc. nhc.System

Page 11: Visualization in Medicine  Lecture: Convolution

Additive Property of Impulse Response

If the input has 3 components

then the output is simply

This is called additive property of linear system.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 11

2.

1..

ncnbna

2.

1..

nhcnhbnha

System

2.1.. ncnbna

2.1.. nhcnhbnha

Page 12: Visualization in Medicine  Lecture: Convolution

Additive Property of Impulse Response

The response resulting from several inputs can be computed as the sum of the responses each input acting alone. 

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 12

knck

k knhck

k .System

Page 13: Visualization in Medicine  Lecture: Convolution

Additive Property of Impulse Response (cont)

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 13

We see that if the input signal is

then the output will be

To summarize, a signal is decomposed into a set of impulses and the output signal can be computed by adding the scaled and shifted impulse responses.

knkxnx .

knhkxny .

Page 14: Visualization in Medicine  Lecture: Convolution

Convolution

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 14

Page 15: Visualization in Medicine  Lecture: Convolution

Convolution

Convolution is the most important and fundamental concept in signal processing and analysis. By using convolution, we can construct the output of system for any arbitrary input signal, if we know the impulse response of system. 

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 15

Page 16: Visualization in Medicine  Lecture: Convolution

Convolution

General concept of convolution: A signal is decomposed into a set of impulses and the output

signal can be computed by adding the scaled and shifted impulse responses

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 16

Page 17: Visualization in Medicine  Lecture: Convolution

Convolution: An Important Fact

The only thing we need to know about the system's characteristics is the impulse response of the system, h[n]. If we know a system's impulse response, then we can easily find out how the system reacts for any input signal.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 17

Page 18: Visualization in Medicine  Lecture: Convolution

Convolution

The mathematical definition of convolution 

x[n] is input signal h[n] is impulse response y[n] is output * denotes convolution

Notice: The terms of x[k] are multiplied by the terms of a time-

shifted h[n] and add them up 

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 18

k

knhkxnhnxny .*

Page 19: Visualization in Medicine  Lecture: Convolution

Convolution in 1D

Example of convolution for 1 dimensional signal. x[n] = { 3, 4, 5 } 

h[n] = { 2, 1 } x[n] has only non-zero values at n=0,1,2, and impulse response, h[n] is

not zero at n=0,1.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 19

x[n] = { 3, 4, 5 } h[n] = { 2, 1 }

Page 20: Visualization in Medicine  Lecture: Convolution

Convolution in 1D

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 20

Wikipedia

Page 21: Visualization in Medicine  Lecture: Convolution

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 21

0 1 2

4 3

5

0 1

2 1

0 1

2 1

0 1 2

4 3

5 2

1

62.30.00.0

hxkhkxyk

112.41.30.11.011.101.01.1

hxhxhxhxkhkxyk

142.51.40.30.21.12.0

22.212.102.02.2

hxhxhx

hxhxhxkhkxy

k

501.5000.31.22.13.0

33.323.213.103.03.3

hxhxhxhx

hxhxhxhxkhkxyk

k

knhkxnhnxny .*

044.434.324.214.104.04.4

hxhxhxhxhxkhkxyk

x[n] = { 3, 4, 5 } h[n] = { 2, 1 } Inverse of h[n]

Page 22: Visualization in Medicine  Lecture: Convolution

Next time2D Convolution

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 22

Page 23: Visualization in Medicine  Lecture: Convolution

Let's look more closely the each output. In order to see a pattern clearly, the order of addition is swapped. The last term comes first and the first term goes to the last. And, all zero terms are ignored.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 23

y[0] = x[0]·h[0] y[1] = x[1]·h[0] + x[0]·h[1] y[2] = x[2]·h[0] + x[1]·h[1] y[3] = x[3]·h[0] + x[2]·h[1]

Page 25: Visualization in Medicine  Lecture: Convolution

Sources

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 25

http://www.songho.ca/dsp/convolution/convolution.html

Page 26: Visualization in Medicine  Lecture: Convolution

Impulse Function Decomposition

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 26

0 1 2 3

2

3

1

0 1 2 3

2

0 1 2 3

3

0 1 2 3

1

0 1 2 3

2

0 1 2 3

3

0 1 2 3

1 nx 20 130 nx 20 nx

Page 27: Visualization in Medicine  Lecture: Convolution

Impulse Function Decomposition

A signal can be decomposed as a weighted sum of impulse function Example

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 27

Page 28: Visualization in Medicine  Lecture: Convolution

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 28

0 1 2

4 3

5

0 1

2

1

0 1

2

1

0 1 2

4 3

5 2

1

0 1 2

4 3

5 2

1

0 1 2

4 3

5 2

1

0 1 2

4 3

5 2

1

2

1

0 1 2

4 3

5

6 11 14 5 0

Page 29: Visualization in Medicine  Lecture: Convolution

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 29

0 1 2

4 3

5

0 1

2

1

0 1

2

1

0 1 2

4 3

5 2

1

Page 30: Visualization in Medicine  Lecture: Convolution

Convolution in 1D

One thing to note before we move on: Try to figure out yourself how this system behaves, by only looking at the impulse response of the system. When the impulse signal is entered the system, the output of the system looks like amplifier and echoing. At the time is 0, the intensity was increased (amplified) by double and gradually decreased while the time is passed.

From the equation of convolution, the output signal y[n] will be . 

Let's compute manually each value of y[0], y[1], y[2], y[3], ...

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 30

knhkxny .

Page 31: Visualization in Medicine  Lecture: Convolution

Convolution in 1D

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 31

k

knhkxnhnxny .*

62.30.00.0

hxkhkxyk

112.41.30.11.011.101.01.1

hxhxhxhxkhkxyk

142.51.40.3

0.21.12.022.212.102.02.2

hxhxhxhxhxhxkhkxyk

501.5000.31.22.13.0

33.323.213.103.03.3

hxhxhxhx

hxhxhxhxkhkxyk

044.434.324.214.104.04.4

hxhxhxhxhxkhkxyk

Page 32: Visualization in Medicine  Lecture: Convolution

Notice that y[0] has only one component, x[0]h[0], and others are omitted, because others are all zeros at k ≠ 0. In other words, x[1]h[-1] = x[2]h[-2] = 0. The above equations also omit the terms if they are obviously zeros. 

If n is larger than and equal to 4, y[n] will be zeros. So we stop here to compute y[n]and adding these 4 signals (y[0], y[1], y[2], y[3]) produces the output signal y[n] = {6, 11, 14, 5}.

University Of Malakand | Department of Computer Science | Visual Computing Research Group | Dr. Engr.Sami ur Rahman | 32