HOME

TheInfoList



OR:

The Sobel operator, sometimes called the Sobel–Feldman operator or Sobel filter, is used in image processing and computer vision, particularly within
edge detection Edge detection includes a variety of mathematical methods that aim at identifying edges, curves in a digital image at which the image brightness changes sharply or, more formally, has discontinuities. The same problem of finding discontinuitie ...
algorithms where it creates an image emphasising edges. It is named after Irwin Sobel and Gary Feldman, colleagues at the
Stanford Artificial Intelligence Laboratory Stanford University has many centers and institutes dedicated to the study of various specific topics. These centers and institutes may be within a department, within a school but across departments, an independent laboratory, institute or center ...
(SAIL). Sobel and Feldman presented the idea of an " Isotropic 3 × 3 Image Gradient Operator" at a talk at SAIL in 1968. Technically, it is a discrete differentiation operator, computing an approximation of the
gradient In vector calculus, the gradient of a scalar-valued differentiable function of several variables is the vector field (or vector-valued function) \nabla f whose value at a point p is the "direction and rate of fastest increase". If the gr ...
of the image intensity function. At each point in the image, the result of the Sobel–Feldman operator is either the corresponding gradient vector or the
norm Naturally occurring radioactive materials (NORM) and technologically enhanced naturally occurring radioactive materials (TENORM) consist of materials, usually industrial wastes or by-products enriched with radioactive elements found in the envi ...
of this vector. The Sobel–Feldman operator is based on convolving the image with a small, separable, and integer-valued filter in the horizontal and vertical directions and is therefore relatively inexpensive in terms of computations. On the other hand, the gradient approximation that it produces is relatively crude, in particular for high-frequency variations in the image.


Formulation

The operator uses two 3×3 kernels which are
convolved In mathematics (in particular, functional analysis), convolution is a mathematical operation on two functions ( and ) that produces a third function (f*g) that expresses how the shape of one is modified by the other. The term ''convolution'' ...
with the original image to calculate approximations of the derivatives – one for horizontal changes, and one for vertical. If we define A as the source image, and G''x'' and G''y'' are two images which at each point contain the horizontal and vertical derivative approximations respectively, the computations are as follows: : \mathbf_x = \begin +1 & 0 & -1 \\ +2 & 0 & -2 \\ +1 & 0 & -1 \end * \mathbf \quad \mbox \quad \mathbf_y = \begin +1 & +2 & +1\\ 0 & 0 & 0 \\ -1 & -2 & -1 \end * \mathbf where * here denotes the 2-dimensional signal processing
convolution In mathematics (in particular, functional analysis), convolution is a mathematical operation on two functions ( and ) that produces a third function (f*g) that expresses how the shape of one is modified by the other. The term ''convolution'' ...
operation. Since the Sobel kernels can be decomposed as the products of an averaging and a differentiation kernel, they compute the gradient with smoothing. For example, \mathbf_x can be written as : \mathbf_x = \begin 1 \\ 2 \\ 1 \end * \left ( \begin +1 & 0 & -1 \end * \mathbf \right ) \quad \mbox \quad \mathbf_y = \begin +1 \\ 0 \\ -1 \end * \left ( \begin 1 & 2 & 1 \end * \mathbf \right ) The ''x''-coordinate is defined here as increasing in the "right"-direction, and the ''y''-coordinate is defined as increasing in the "down"-direction. At each point in the image, the resulting gradient approximations can be combined to give the gradient magnitude, using: :\mathbf = \sqrt Using this information, we can also calculate the gradient's direction: :\mathbf = \operatorname( \mathbf_y , \mathbf_x ) where, for example, \mathbf is 0 for a vertical edge which is lighter on the right side (for \operatorname see atan2).


More formally

Since the intensity function of a digital image is only known at discrete points, derivatives of this function cannot be defined unless we assume that there is an underlying differentiable intensity function that has been sampled at the image points. With some additional assumptions, the derivative of the continuous intensity function can be computed as a function on the sampled intensity function, i.e. the digital image. It turns out that the derivatives at any particular point are functions of the intensity values at virtually all image points. However, approximations of these derivative functions can be defined at lesser or larger degrees of accuracy. The Sobel-Feldman operator represents a rather inaccurate approximation of the image gradient, but is still of sufficient quality to be of practical use in many applications. More precisely, it uses intensity values only in a 3×3 region around each image point to approximate the corresponding image gradient, and it uses only integer values for the coefficients which weight the image intensities to produce the gradient approximation.


Extension to other dimensions

The Sobel–Feldman operator consists of two separable operations: * Smoothing perpendicular to the derivative direction with a triangle filter: h(-1) = 1, h(0) = 2, h(1) = 1 * Simple central difference in the derivative direction: h'(-1) = 1, h'(0) = 0, h'(1) = -1 Sobel–Feldman filters for
image derivative Image derivatives can be computed by using small convolution filters of size 2 × 2 or 3 × 3, such as the Discrete Laplace operator, Laplacian, Sobel operator, Sobel, Roberts cross, Roberts and Prewitt operator, Prewitt operato ...
s in different dimensions with x,y,z,t \in \left\ : 1D: h_x'(x) = h'(x); 2D: h_x'(x,y) = h'(x)h(y) 2D: h_y'(x,y) = h(x)h'(y) 3D: h_y'(x,y,z) = h(x)h'(y)h(z) 3D: h_z'(x,y,z) = h(x)h(y)h'(z) 4D: h_x'(x,y,z,t) = h'(x)h(y)h(z)h(t) Thus as an example the 3D Sobel–Feldman kernel in ''z''-direction: : h_z'(:,:,-1) = \begin +1 & +2 & +1 \\ +2 & +4 & +2 \\ +1 & +2 & +1 \end \quad h_z'(:,:,0) = \begin 0 & 0 & 0 \\ 0 & 0 & 0 \\ 0 & 0 & 0 \end \quad h_z'(:,:,1) = \begin -1 & -2 & -1 \\ -2 & -4 & -2 \\ -1 & -2 & -1 \end


Technical details

As a consequence of its definition, the Sobel operator can be implemented by simple means in both hardware and software: only eight image points around a point are needed to compute the corresponding result and only integer arithmetic is needed to compute the gradient vector approximation. Furthermore, the two discrete filters described above are both separable: :\begin 1 & 0 & -1 \\ 2 & 0 & -2 \\ 1 & 0 & -1 \end = \begin 1 \\ 2 \\ 1 \end \begin 1 & 0 & -1 \end = \begin 1 \\ 1 \end * \begin 1 \\ 1 \end \begin 1 & -1 \end * \begin 1 & 1 \end :\begin \ \ 1 & \ \ 2 & \ \ 1 \\ \ \ 0 & \ \ 0 & \ \ 0 \\ -1 & -2 & -1 \end = \begin \ \ 1 \\ \ \ 0 \\ -1 \end \begin 1 & 2 & 1 \end = \begin 1 \\ 1 \end * \begin \ \ 1 \\ -1 \end \begin 1 & 1 \end * \begin 1 & 1 \end and the two derivatives G''x'' and G''y'' can therefore be computed as : \mathbf_x = \begin 1 \\ 2 \\ 1 \end * \left ( \begin 1 & 0 & -1 \end * \mathbf \right ) \quad \mbox \quad \mathbf_y = \begin \ \ 1 \\ \ \ 0 \\ -1 \end * \left ( \begin 1 & 2 & 1 \end * \mathbf \right ) In certain implementations, this separable computation may be advantageous since it implies fewer arithmetic computations for each image point. Applying convolution ''K'' to pixel group ''P'' can be represented in pseudocode as: :N(x,y) = Sum of , for i,j running from -1 to 1. N(x,y) represents the new matrix resulted after applying the Convolution ''K'' to ''P'', where ''P'' is pixel matrix.


Example

The result of the Sobel–Feldman operator is a 2-dimensional map of the gradient at each point. It can be processed and viewed as though it is itself an image, with the areas of high gradient (the likely edges) visible as white lines. The following images illustrate this, by showing the computation of the Sobel-Feldman operator on a simple image. The images below illustrate the change in the direction of the gradient on a grayscale circle. When the sign of \mathbf and \mathbf are the same the gradient's angle is positive, and negative when different. In the example below the red and yellow colors on the edge of the circle indicate positive angles, and the blue and cyan colors indicate negative angles. The vertical edges on the left and right sides of the circle have an angle of 0 because there is no local change in \mathbf. The horizontal edges at the top and bottom sides of the circle have angles of − and respectively because there is no local change in \mathbf. The negative angle for top edge signifies the transition is from a bright to dark region, and the positive angle for the bottom edge signifies a transition from a dark to bright region. All other pixels are marked as black due to no local change in either \mathbf or \mathbf, and thus the angle is not defined. Since the angle is a function of the ratio of \mathbf to \mathbf pixels with small rates of change can still have a large angle response. As a result noise can have a large angle response which is typically undesired. When using gradient angle information for image processing applications effort should be made to remove
image noise Image noise is random variation of brightness or color information in images, and is usually an aspect of electronic noise. It can be produced by the image sensor and circuitry of a scanner or digital camera. Image noise can also originate in ...
to reduce this false response.


Alternative operators

The Sobel–Feldman operator, while reducing artifacts associated with a pure central differences operator, does not exhibit a good rotational symmetry (about 1° of error). Scharr looked into optimizing this property by producing kernels optimized for specific given numeric precision (integer, float…) and dimensionalities (1D, 2D, 3D). Optimized 3D filter kernels up to a size of 5 x 5 x 5 have been presented there, but the most frequently used, with an error of about 0.2° is: : h_x'(:,:) = \begin +3 & 0 & -3 \\ +10 & 0 & -10 \\ +3 & 0 & -3 \end \ \ \ \ \ \ \ \ \ h_y'(:,:) = \begin +3 & +10 & +3 \\ 0 & 0 & 0 \\ -3 & -10 & -3 \end This factors similarly: * \begin 3 & 10 & 3 \end = \begin 3 & 1 \end * \begin 1 & 3 \end Scharr operators result from an optimization minimizing weighted mean squared angular error in the
Fourier domain In physics, electronics, control systems engineering, and statistics, the frequency domain refers to the analysis of mathematical functions or signals with respect to frequency, rather than time. Put simply, a time-domain graph shows how a sig ...
. This optimization is done under the condition that resulting filters are numerically consistent. Therefore they really are derivative kernels rather than merely keeping symmetry constraints. The optimal 8 bit integer valued 3x3 filter stemming from Scharr's theory is : h_x'(:,:) = \begin 47 & 0 & -47 \\ 162 & 0 & -162 \\ 47 & 0 & -47 \end \ \ \ \ \ \ \ \ \ h_y'(:,:) = \begin 47 & 162 & 47 \\ 0 & 0 & 0 \\ -47 & -162 & -47 \end A similar optimization strategy and resulting filters were also presented by Farid and Simoncelli. They also investigate higher-order derivative schemes. In contrast to the work of Scharr, these filters are not enforced to be numerically consistent. The problem of derivative filter design has been revisited e.g. by Kroon. Derivative filters based on arbitrary cubic splines was presented by Hast. He showed how first and second order derivatives can be computed correctly using cubic or trigonometric splines by a double filtering approach giving filters of length 7. Another similar operator that was originally generated from the Sobel operator is the Kayyali operator, a perfect rotational symmetry based convolution filter 3x3. Orientation-optimal derivative kernels drastically reduce systematic estimation errors in
optical flow Optical flow or optic flow is the pattern of apparent motion of objects, surfaces, and edges in a visual scene caused by the relative motion between an observer and a scene. Optical flow can also be defined as the distribution of apparent veloci ...
estimation. Larger schemes with even higher accuracy and optimized filter families for extended optical flow estimation have been presented in subsequent work by Scharr. Second order derivative filter sets have been investigated for transparent
motion estimation Motion estimation is the process of determining ''motion vectors'' that describe the transformation from one 2D image to another; usually from adjacent frames in a video sequence. It is an ill-posed problem as the motion is in three dimensions ...
.Scharr, Hanno
''OPTIMAL SECOND ORDER DERIVATIVE FILTER FAMILIES FOR TRANSPARENT MOTION ESTIMATION''
15th European Signal Processing Conference (EUSIPCO 2007), Poznan, Poland, September 3–7, 2007.
It has been observed that the larger the resulting kernels are, the better they approximate derivative-of-Gaussian filters.


Example comparisons

Here, four different gradient operators are used to estimate the magnitude of the gradient of the test image.


MATLAB implementation

clc clear all close all test_img = imread('gantrycrane.png'); gray_img = rgb2gray(test_img); sobel_img = sobel(gray_img); figure imshow(test_img) figure imshow(gray_img) figure imshow(sobel_img) function output_image = sobel(A) Gx = 1 0 1; -2 0 2; -1 0 1Gy = 1 -2 -1; 0 0 0; 1 2 1 rows = size(A, 1) columns = size(A, 2) mag = zeros(size(A)); A = double(A); for i=1:rows-2 for j=1:columns-2 S1 = sum(sum(Gx.*A(i:i+2, j:j+2))); S2 = sum(sum(Gy.*A(i:i+2, j:j+2))); mag(i + 1, j + 1) = sqrt(S1.^2 + S2.^2); end end threshold = 70 % varies for application –255output_image = max(mag, threshold); output_image(output_image

round(threshold)) = 0; end
The above
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementa ...
code will use an image which is packaged with MATLAB itself ('gantrycrane.png') to demo the Sobel filter. There will be outputs with original image, grayscale version of original image and the output from the Sobel filter.


See also

*
Digital image processing Digital image processing is the use of a digital computer to process digital images through an algorithm. As a subcategory or field of digital signal processing, digital image processing has many advantages over analog image processing. It allo ...
*
Feature detection (computer vision) In computer vision and image processing, a feature is a piece of information about the content of an image; typically about whether a certain region of the image has certain properties. Features may be specific structures in the image such as poi ...
*
Feature extraction In machine learning, pattern recognition, and image processing, feature extraction starts from an initial set of measured data and builds derived values (features) intended to be informative and non-redundant, facilitating the subsequent learning a ...
*
Discrete Laplace operator In mathematics, the discrete Laplace operator is an analog of the continuous Laplace operator, defined so that it has meaning on a graph or a discrete grid. For the case of a finite-dimensional graph (having a finite number of edges and vertice ...
* Prewitt operator


References


External links


Sobel edge detection in OpenCV


in the
SciPy SciPy (pronounced "sigh pie") is a free and open-source Python library used for scientific computing and technical computing. SciPy contains modules for optimization, linear algebra, integration, interpolation, special functions, FFT, ...
Python Library
Bibliographic citations for Irwin Sobel
in
DBLP DBLP is a computer science bibliography website. Starting in 1993 at Universität Trier in Germany, it grew from a small collection of HTML files and became an organization hosting a database and logic programming bibliography site. Since Novem ...

Sobel edge detection example using computer algorithms
{{DEFAULTSORT:Sobel Operator Feature detection (computer vision)