imsobel {imageUtilities} | R Documentation |
3x3 sobel operator
imsobel(img, which = c("both", "horizontal", "vertical"))
img |
image to apply operator to |
which |
leave as is ('both') to calculate the traditional sobel gradient. Use 'horizontal' or 'vertical' to calculate *just* those gradients. |
The horizontal sobel gradient is:
G_x = [-1 0 +1; -2 0 +2; -1 0 +1] * img
The vertical is:
G_y = [-1 -2 -1; 0 0 0; +1 +2 +1] * img
where '*' is the 2D convolution.
These filters are decomposible:
G_x = t([1 2 1]) * ([-1 0 1] * img)
G_y = t([-1 0 1]) * ([1 2 1] * img)
The sobel image is given by:
G = √{ G_x^2 + G_y^2 }
If the user specifies which='both'
(default), they
will get
G
. If they specify
which='horizontal'
they'll get
G_x
, and if
they specify which='vertical'
they'll get
G_y
.
Note: one can also calculate the *direction* of the gradient via:
theta = atan2(G_y,G_x)
sobel gradient image: same size as input (the border will be NA because of the convolution).