computing for engineers in python

33
1 Computing for Engineers in Python Autumn 2011- 12 Some slides incorporated from Benny Chor’s course Lecture 10: Signal (Image) Processing

Upload: makan

Post on 13-Jan-2016

52 views

Category:

Documents


0 download

DESCRIPTION

Computing for Engineers in Python. Lecture 10 : Signal (Image) Processing. Autumn 2011-12. Some slides incorporated from Benny Chor’s course. Lecture 9: Highlights. Sorting, searching and time complexity - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Computing for Engineers in Python

1

Computing for Engineers in

Python

Autumn 2011-12Some slides incorporated from Benny Chor’s course

Lecture 10: Signal (Image) Processing

Page 2: Computing for Engineers in Python

2

Lecture 9: Highlights

• Sorting, searching and time complexity

• Preprocessing (sorting) the data enables fast (O(log2n)) access to what we are interested in (searching)

• Binary search algorithm + time complexity analysis

• Comparing recursive vs. iterative implementations efficiency

• Bubble sort + time complexity analysis

• Is there a faster sorting algorithm?

• Yes! (Quick Sort in tirgul)

• Comparing Bubble sort to sorted efficiency

• Generic sorting

Page 3: Computing for Engineers in Python

3

More Sorting Algorithms

• Insertion, Selection O(n2) in tirgul

• Quick sort O(nlog2n) on average in tirgul

• Average versus worst case analysis

• (maybe next week) "בהזדמנות"

• Merge sort O(nlog2n) worst case

• Can we do better than O(nlog2n) in general?

• Bucket sort

Page 4: Computing for Engineers in Python

4

Signal Processing

• In the physical world, any quantity measurable through time or over space can be taken as a signal

• Signals are or electrical representations of time-varying or spatial-varying physical quantities

• Signal processing: applying mathematical techniques  for the extraction, transformation and interpretation of signals, in either discrete (digital) or continuous (analog) time

• Example signals: radio, telephone, radar, sound, images, video, sensor data

Page 5: Computing for Engineers in Python

5

Digital Images

• Digital image is a numeric representation of a two-dimensional image

• Examples: photos, microscopic, medical, astronomical

Page 6: Computing for Engineers in Python

6

Image Representation

• Encoded as a n-by-m matrix M • Each element M[x,y] in an image is called picture

element (pixel), representing the light intensity / color at that location

• RGB, gray-level images• Video – an image for each time t

http://www.youtube.com/watch?v=bgtHKR0aQpQ&feature=related

Page 7: Computing for Engineers in Python

7

ResolutionPixel resolution vs. spatial resolution

Same number of pixels, different spatial resolution :http://www.youtube.com/watch?v=i2AQjjZp6Jk

depends on properties of the system creating the image, not

just the pixel resolution

Pixel resolution == pixel count

Page 8: Computing for Engineers in Python

Image QuantizationNumber of bits per pixel

24 bit RGB 16 colors

Note that both images have the same pixel & spatial resolution

Page 9: Computing for Engineers in Python

9

Gray Level Images

• The remaining of class will deal with gray-level images (although can be applicable for color images)

• 8 bits per pixel (256 gray levels), 0 – black, 255 – white • Other representations:

• Binary – 1bit per pixel

• Some applications use more colors (medical imaging)

Page 10: Computing for Engineers in Python

10

An Example

Page 11: Computing for Engineers in Python

11

Image Processing

• Signal processing for which the input is an image• Typical operations:

• Color corrections / calibration

• Image segmentation

• Image registration / alignment

• Denoising

• Typical applications:• Machine vision

• Medical image processing

• Face detection

• Augmented reality

Page 12: Computing for Engineers in Python

12

In Python

• How to handle an image?• The Python Imaging Library http://www.pythonware.com/products/pil/

• Example tutorial: http://www.geeks3d.com/20100930/tutorial-first-steps-with-pil-python-imaging-library

• The Image Module: http://www.pythonware.com/library/pil/handbook/image.htm

• Capacities:• Read / write images• Display image• Basic image processing

Page 13: Computing for Engineers in Python

13

Loading and Viewing an Imagehttp://www.pythonware.com/library/pil/handbook/image.htm

http://en.wikipedia.org/wiki/Lenna

Page 14: Computing for Engineers in Python

14

Access Pixels

Page 15: Computing for Engineers in Python

15

Create and Save an Image

Page 16: Computing for Engineers in Python

16

Output

Page 17: Computing for Engineers in Python

17

Rotating an Image

Page 18: Computing for Engineers in Python

18

Edges• Sharp change in intensity between close pixels• Denoted edges• Usually captures much of the meaningful information in

the image• Edge detection algortihms:

Sobel Lena Laplacian

Page 19: Computing for Engineers in Python

19

Edge Detection Example

Page 20: Computing for Engineers in Python

20

Blur and Noise

Gaussian noise Lena Salt and pepper noise

Gaussian blur (sigma = 2)

Credit: Wikipedia

Page 21: Computing for Engineers in Python

21

Denoising Algorithms

• Examples:• Local means: replace observed pixel with neighborhood’s

(usually 3x3 mask) average

• Local medians: with neighborhood’s median

x

Page 22: Computing for Engineers in Python

22

Denoising Algorithms

• Local means: • Pros: reduces noise on smooth areas, fast

• Cons: blur edges, sensitivity to extreme values (e.g., as in salt and pepper noise)

• Local medians:• Pros: preserve edges, not sensitive to extreme values

• Cons: eliminate fine details (contours) in the image, slow

x

Page 23: Computing for Engineers in Python

23

Example

In Tirgul

Page 24: Computing for Engineers in Python

24

Image Manipulation Full Example

http://www.riisen.dk/dop/pil.html

Page 25: Computing for Engineers in Python

25

Image Segmentation

Page 26: Computing for Engineers in Python

26

Image Segmentation Algorithms

• Thersholding• Clustering• Region growing• Compression-based methods• Histogram-based methods• Model-based methods• Etc.

Page 27: Computing for Engineers in Python

27

Thresholding

• Simplest segmentation method• Apply a threshold to turn a gray-scale image into a

binary image• The key is to select the appropriate threshold value• Popular method – Otsu’s method (maximal variance)

Page 28: Computing for Engineers in Python

28

Example - Thresholding

Page 29: Computing for Engineers in Python

29

Example - Thresholding

Page 30: Computing for Engineers in Python

30

Results

TH = 20 TH = 80

TH = 140 TH = 180

Page 31: Computing for Engineers in Python

31

HW – The Whole Loop

• Input: noisy image • Output: segmented contours on top of input image• How?

• Denoising

• Edge detection

• Thresholding (histogram based – Otsu’s algorithm)

• Visualization

Page 32: Computing for Engineers in Python

32

Real World ApplicationFace Detection

Credit: Intel Technology Journal, Volume 09, Issue 01

Page 33: Computing for Engineers in Python

33