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