Soble Filter
This is a gradient based mathematical operation in which the edge is detected using first order derivatives. It combines both differentiation and Gaussian Smoothing. So it is resistant to noises and hence prior smoothing before Soble is not necessary . There are 2 kernels representing the Sobel filter . One filters out the edges along the y-direction while the other filters out along the x-direction. The kernels are
Soble x
-1 | 0 | 1 |
-2 | 0 | 2 |
-1 | 0 | 1 |
Soble y
-1 | -2 | -1 |
0 | 0 | 0 |
1 | 2 | 1 |
import cv2 as cv img=cv.LoadImage(‘tiger small.jpg’) cv.NamedWindow(‘True’,cv.CV_WINDOW_NORMAL) cv.ShowImage(‘True’,img) sob=cv.CreateImage(cv.GetSize(img),8,3) cv.Sobel(img,sob,1,0,3) cv.NamedWindow(‘Soble x’,cv.CV_WINDOW_NORMAL) cv.ShowImage(‘Soble x’,sob) cv.Sobel(img,sob,0,1,3) cv.NamedWindow(‘Soble y’,cv.CV_WINDOW_NORMAL) cv.ShowImage(‘Soble y’,sob) cv.Sobel(img,sob,1,1,3) cv.NamedWindow(‘Sobel x y’,cv.CV_WINDOW_NORMAL) cv.ShowImage(‘Sobel x y’,sob) cv.WaitKey(20000) cv.DestroyAllWindows()
import cv2 import numpy as np img = cv2.imread(’j.png’,0) kernel = np.ones((3,3),np.uint8) erosion = cv2.erode(img,kernel,iterations = 2)