cs3430 lecture 13

18

Click here to load reader

Upload: tanwir-zaman

Post on 25-May-2015

27 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Cs3430 lecture 13

Python & Perl

Lecture 13

Department of Computer ScienceUtah State University

Page 2: Cs3430 lecture 13

PIL Examples

Page 3: Cs3430 lecture 13

Exercise: Luminosity & Binarization

Write a PIL program that converts RGB images to grayscale and binarizes them.

Page 4: Cs3430 lecture 13

Exercise: Luminosity & Binarization RGB Grayscale Binary

Page 5: Cs3430 lecture 13

Luminosity

Page 6: Cs3430 lecture 13

Luminosity

● The first component is a luminosity function that converts an RGB pixel to a gray level intensity coefficient.

● We will use this function as we iterate through an RGB image and compute the luminosity coefficients of various pixels

● http://en.wikipedia.org/wiki/Luminance_(relative)

Page 7: Cs3430 lecture 13

Gradients

Page 8: Cs3430 lecture 13

Gradients

• Gradient is the directional change in image intensity or color

Page 9: Cs3430 lecture 13

Gradients

• Gradient orientation :

• Gradient magnitude :

Page 10: Cs3430 lecture 13

Gradients

• dy= 255 - 0

• dx= 0 - 0 ≈ 1

Page 11: Cs3430 lecture 13

Edge Detection using Gradients

Page 12: Cs3430 lecture 13

Edge Detection

● Computing edges is a pixel-level operation: a given pixel (pivot pixel) either belongs to an edge or not

● The edges can be detected via gradients, i.e., changes in luminosity between two horizontal and two vertical neighbor pixels of the pivot pixel at (x, y).

Page 13: Cs3430 lecture 13

Border pixels

● What to do with border pixels that do not have a complete set of neighbors?

● Two simple approaches are 1) padding the image and

2) ignoring the border pixels.

We will choose (2) for the sake of simplicity

Page 14: Cs3430 lecture 13

Calculate dx and dy

● The function rgb_pix_dx computes the luminosity change in the x direction as the difference between the two luminosity levels of the pivot pixel's horizontal neighbors.

● The function rgb_pix_dy computes the luminosity change in the y direction as the difference between the two luminosity levels of the pivot pixel's vertical neighbors.

Page 15: Cs3430 lecture 13

Magnitude

● The magnitude of the gradient is the length of the hypotenuse of the right triangle whose vertical side is returned by rgb_pix_dy and whose horizontal side is computed by rgb_pix_dx.

Page 16: Cs3430 lecture 13

Gradient Angle

● The direction of the gradient is computed as math.atan2(pdy,pdx)*(180/math.pi), where pdy and pdx are the values returned by rgb_pix_dy and rgb_pix_dx, respectively.

● The function math.atan2(pdy,pdx) returns values between -pi and +pi. If pdy and equal to pdx, are both equal to the default_delta value (i.e., there is no change in the y and x intensities) we return -200, an arbitrary value outside of [-180, +180].

Page 17: Cs3430 lecture 13

Edges

● Python generators are used to iterate through image and detect edges.

● A pixel belongs to an edge if its direction is within [-90, +90] and its magnitude is at least 20.

● Edge pixels are set to 255 (white); non-edge pixels to 0 (black).

Page 18: Cs3430 lecture 13

Reading & References● www.python.org● http://www.pythonware.com● http://effbot.org/imagingbook/imagefilter.htm