Cs3430 lecture 13


Published on

Published in: Education
  • Be the first to comment

  • Be the first to like this

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Cs3430 lecture 13

  1. 1. Python & Perl Lecture 13 Department of Computer Science Utah State University
  2. 2. PIL Examples
  3. 3. Exercise: Luminosity & Binarization Write a PIL program that converts RGB images to grayscale and binarizes them.
  4. 4. Exercise: Luminosity & Binarization RGB Grayscale Binary
  5. 5. Luminosity
  6. 6. 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)
  7. 7. Gradients
  8. 8. Gradients • Gradient is the directional change in image intensity or color
  9. 9. Gradients • Gradient orientation : • Gradient magnitude :
  10. 10. Gradients • dy= 255 - 0 • dx= 0 - 0 ≈ 1
  11. 11. Edge Detection using Gradients
  12. 12. 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).
  13. 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
  14. 14. 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.
  15. 15. 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.
  16. 16. 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].
  17. 17. 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).
  18. 18. Reading & References ● www.python.org ● http://www.pythonware.com ● http://effbot.org/imagingbook/imagefilter.htm