Reputation: 1120
What is the exact mask for Sobel (Gx and Gy)? What I saw is there are two types on how people wrote it such as below,
Style 1
Gx = [-1 -2 -1
0 0 0
1 2 1]
Gy = [-1 0 1
-2 0 2
-1 0 1]
Style 2
Gx = [-1 0 1
-2 0 2
-1 0 1]
Gy = [-1 -2 -1
0 0 0
1 2 1]
Edited
@Aurelis
In Matlab --> (row x col)
In OpenCV --> (col x row)
However, the diagram below is correct for both
-->column
^
|row
|
Probably in Matlab will output Gx == horizontal edge, Gy == vertical edge if Style 1 is used and Gx == horizontal edge, Gy ==vertical edge if Style 2 is used. Both will produce same output (internal operation might be different due to the col-row major order).
@Abhishek You are using style 1 to compute the horizontal and vertical edge? and Gx correspond to horizontal edge while Gy correspond to vertical edge? Does that mean style 2 is complement of that? For eg. computing Gx will gives vertical edge and Gy gives horizontal edge?
Upvotes: 0
Views: 1417
Reputation: 17015
Style 2 is correct. However, using both the styles we will get the same result, as the kernels are convolved with the image
Gx = [-1 -2 -1 0 0 0 <--- will extract features in Y direction and not in X direction. 1 2 1]
Gy = [-1 0 1 -2 0 2 <--- will extract features in X direction and not in Y direction. -1 0 1]
This can be verified by using a simple 2-D convolution.
original image:
using Style1,Gx:
using style1, Gy:
Upvotes: 3
Reputation: 11329
If you are using mathematical notation, the proper mask is Style 2 (see here).
Your confusion may be arising from the difference between matrices in MATLAB and OpenCV. MATLAB matrices are specified in column-major order, while OpenCV matrices are specified in row-major order.
Style 1 is representing the Sobel mask in a column-major fashion, and Style 2 represents the same mask in row-major order.
Upvotes: 1