Skip to content

Sobel

Image processingfunctionOpenCV 5.0.0
import { Sobel } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

example: samples/cpp/tutorial_code/ImgTrans/Sobel_Demo.cpp Sample code using Sobel and/or Scharr OpenCV functions to make a simple Edge Detector Sample screenshot Check tutorial_sobel_derivatives "the corresponding tutorial" for more details Calculates the first, second, third, or mixed image derivatives using an extended Sobel operator.

In all cases except one, the \texttt{ksize} \times \texttt{ksize} separable kernel is used to calculate the derivative. When \texttt{ksize = 1}, the 3 \times 1 or 1 \times 3 kernel is used (that is, no Gaussian smoothing is done). ksize = 1 can only be used for the first or the second x- or y- derivatives.

There is also the special value ksize = #FILTER_SCHARR (-1) that corresponds to the 3\times3 Scharr filter that may give more accurate results than the 3\times3 Sobel. The Scharr aperture is

\vecthreethree{-3}{0}{3}{-10}{0}{10}{-3}{0}{3}

for the x-derivative, or transposed for the y-derivative.

The function calculates an image derivative by convolving the image with the appropriate kernel:

\texttt{dst} =  \frac{\partial^{xorder+yorder} \texttt{src}}{\partial x^{xorder} \partial y^{yorder}}

The Sobel operators combine Gaussian smoothing and differentiation, so the result is more or less resistant to the noise. Most often, the function is called with ( xorder = 1, yorder = 0, ksize = 3) or ( xorder = 0, yorder = 1, ksize = 3) to calculate the first x- or y- image derivative. The first case corresponds to a kernel of:

\vecthreethree{-1}{0}{1}{-2}{0}{2}{-1}{0}{1}

The second case corresponds to a kernel of:

\vecthreethree{-1}{-2}{-1}{0}{0}{0}{1}{2}{1}

See: Scharr, Laplacian, sepFilter2D, filter2D, GaussianBlur, cartToPolar

Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number, ksize: number, scale: number, delta: number, borderType: number): void;
5 available overloads
Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number): void;
Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number, ksize: number): void;
Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number, ksize: number, scale: number): void;
Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number, ksize: number, scale: number, delta: number): void;
Sobel(src: Mat, dst: Mat, ddepth: number, dx: number, dy: number, ksize: number, scale: number, delta: number, borderType: number): void;
src

input image.

dst

Output destination, filled by the native operation. output image of the same size and the same number of channels as src .

ddepth

output image depth, see filter_depths "combinations"; in the case of 8-bit input images it will result in truncated derivatives.

dx

order of the derivative x.

dy

order of the derivative y.

ksize

size of the extended Sobel kernel; it must be 1, 3, 5, or 7.

scale

optional scale factor for the computed derivative values; by default, no scaling is applied (see #getDerivKernels for details).

delta

optional delta value that is added to the results prior to storing them in dst.

borderType

pixel extrapolation method, see #BorderTypes. #BORDER_WRAP is not supported.

These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.