class: center, middle ## Image Filtering & Edge Detection By: Eslam Adel email: eslam.a.mahmoud@eng1.cu.edu.eg Inspired by slides of TA.Mohamed Hisham 2016 --- class: top, left ## 2D Convolution
--- class: top, left ## 2D Convolution Cont'd Basic Steps are : -- 1. Flip the Kernel in both horizontal and vertical directions (center of the kernel must be provided) -- 2. Move over the array with kernel centered at interested point. -- 3. Multiply kernel data with overlapped area. -- 4. Sum or accumulate the output. --- class: top, left ## Image Denoising -- Clear Image --
--- class:top,left ## Image Denoising Cont'd -- Adding Noise --
--- class: top, left ### Box, mean or average filter
--- class: top, left ### Gaussian filter -- Derived from 2D gaussian function $$\begin{equation} h(u,v) = \frac{1}{2 \pi \sigma^2} e^{(- \frac{u^2 + v^2}{\sigma^2})} \end{equation} $$ --
--- class: top, left ### Median Filter -- * Nonlinear digital filter -- * efficient in removal of salt and pepper noise.
--- class: top, left ## Edge detection kernels Edges represents the object boundaries. -- Edge detection is a very important preprocessing step object detection -- ### Prewitt operator For Ix(x,y) and Iy(x,y)
--- class: top, left ## Edge detection kernels Cont'd ### Sobel operator For Ix(x,y) and Iy(x,y)
--- class: top, left ## Edge detection kernels Cont'd ### Laplacian It is an approximation of second order derivative that defines zeros crossing. For Example 3x3 laplacian is :
Laplacian usually is applied after gaussian smoothing. So LOG refers to laplacian of gaussian. --- class: top, left ## Gradient magnitude and direction Gradient magnitude is given by $$ \begin{equation} I_{xy} = \sqrt{I_x(x,y)^2 + I_y(x,y)^2} \end{equation} $$ and Gradient direction: $$ \begin{equation} I_{\theta} = tan^{-1}(\frac{I_y(x,y)}{I_x(x,y)}) \end{equation} $$ --- class: left, top ## Canny edge detection algorithm It was developed by [John F. Canny](https://en.wikipedia.org/wiki/John_Canny) in 1986. **Stages** 1. **Smoothing for noise removal.** 2. Finding Gradients. 3. None-maximum suppression. 4. Double Thresholding. 5. Edge Tracking by hysteresis. --- class:top ,left ## Smoothing The first stage in canny edge detection algorithm is smoothing to remove noise that may cause false edges. Kernel used in this step is 5x5 gaussian kernel with $\sigma = 1.4$ and that it
--- class: top, left ##Smoothing Cont'd Original Image
---
--- class: left, top ## Canny edge detection algorithm **Stages** 1. Smoothing for noise removal. 2. **Finding Gradients.** 3. None-maximum suppression. 4. Double Thresholding. 5. Edge Tracking by hysteresis. --- class:top , left ### Finding Gradients using sobel operator in both x and y .
--- class: left, top ## Canny edge detection algorithm **Stages** 1. Smoothing for noise removal. 2. Finding Gradients. 3. **None-maximum suppression.** 4. Double Thresholding. 5. Edge Tracking by hysteresis. --- class: top, left ### None-maximum suppression Compare pixel with pixels in the gradient directions and Suppress if not max.
--- class: top, left ### None-maximum suppression Cont'd Direction must be quantized to 8 directions or angles to use 8-Connectivity.
--- class: top, left ### None-maximum suppression Cont'd The result of this stage would be an edge image with thin edges.
--- class: left, top ## Canny edge detection algorithm **Stages** 1. Smoothing for noise removal. 2. Finding Gradients. 3. None-maximum suppression. 4. **Double Thresholding.** 5. Edge Tracking by hysteresis. --- class: top, left ### Double thresholding we globally eliminate weak edges. We have two threshlods $T_l$ and $T_h$ selected by user. ```python if image[x,y] < TL: image[x,y] = 0 elif image(x,y) > TH: image[x,y] = 1 ``` --- class: top, left ### Double thresholding Cont'd
-- What about pixels with in-between values ? --- class: left, top ## Canny edge detection algorithm **Stages** 1. Smoothing for noise removal. 2. Finding Gradients. 3. None-maximum suppression. 4. Double Thresholding. 5. **Edge Tracking by hysteresis.** --- class: top, left ### Edge tracking by hysteresis For in-between $T_l$ and $T_h$ check neighbors keep it if strong else Suppress.
--- class: top, left ## Demo ```bash $ git clone https://github.com/sbme-tutorials/cv-week4-demo ``` ## Useful links * [matplotlib gallery](https://matplotlib.org/gallery/index.html) * [scikit-image examples](http://scikit-image.org/docs/dev/auto_examples/) --- class: center, middle # Thanks