Edge Detection (Sobel)

Find the edges in a photo with the 3 × 3 Sobel operator, as clean black-and-white lines above a threshold or as a greyscale sketch, with the gradient worked out for any pixel.

Tool Media & Files Updated Oct 16, 2026
How to Use
  1. Drop an image on the box, click to browse, or paste one. TIFF, PSD, HEIC, TGA and camera RAW files open too. A built-in sample is loaded so you can try the presets straight away.
  2. Choose Edges for clean lines wherever the gradient passes the threshold, or Strength for a greyscale sketch whose lines get darker or brighter with the edge.
  3. Move the Threshold until the lines you want stay and the noise goes; the histogram below the picture shows where the threshold sits. Tick Invert for dark lines on white.
  4. Click the picture to see the 3 × 3 grey values around that pixel and its Gx, Gy, magnitude and direction in Show Work.
  5. Save the result in any format from the Save panel; large photos are processed again at full size when you save.
Image & Edges
|G|, 0–1,141
Presets
Result
The ring marks the pixel in Show Work.
Largest Gradient
—
Mean Gradient
—
Edge Pixels
—
Output
—

Worked Example

A vertical step from grey 50 to grey 200. Take a pixel just left of the step: every row of its 3 × 3 block reads 50, 50, 200. Gx = (200 + 2 × 200 + 200) − (50 + 2 × 50 + 50) = 800 − 200 = 600, and Gy = 0 because the top and bottom rows are identical. |G| = √(600² + 0²) = 600, pointing at 0° (brightness rises to the right), well above a threshold of 150, so the pixel is an edge.

A diagonal edge. With rows 50, 50, 50 / 50, 50, 200 / 50, 200, 200, Gx = 450 and Gy = 450, so |G| = √(450² + 450²) = 636.4 at 45°, pointing down and to the right, the way brightness increases. The diagonal weights mean a slanted edge is not penalised compared with a straight one.

The common mistake: a threshold below the noise. Sensor noise of only ±5 grey levels can produce |G| up to 44.7 on a perfectly flat wall, and texture such as grass far more. With a threshold of 40, flat areas fill with speckles; 100 or more keeps only real edges. The histogram under the picture shows the noise as the tall hump near zero.

Show Work

Load an image to see the gradient worked out for one pixel.

Formulas

Grey value
Y = 0.299R + 0.587G + 0.114B
Rec. 601 luma of each pixel, kept as a decimal
Horizontal kernel
Gx = [−1 0 +1; −2 0 +2; −1 0 +1] ∗ Y
Right column minus left column, middle row counted twice
Vertical kernel
Gy = [−1 −2 −1; 0 0 0; +1 +2 +1] ∗ Y
Bottom row minus top row, y increasing downwards
Magnitude and direction
|G| = √(Gx² + Gy²)   θ = atan2(Gy, Gx)
|G| is at most 255 × √20 = 1,140.4 on 0–255 values
Output
Edges: 255 if |G| > t, else 0
Strength: min(255, |G| × k) if |G| > t
t = threshold, k = gain; Invert gives 255 − value

Sobel and Feldman, 1968

The operator is named after Irwin Sobel and Gary M. Feldman, colleagues at the Stanford Artificial Intelligence Laboratory, who presented an “Isotropic 3 × 3 Image Gradient Operator” in a talk there in 1968. It is often called the Sobel-Feldman operator. It only looks at the eight neighbours of each pixel, so it is a rough approximation of the true image gradient, but it is fast and good enough for a great many uses, and it is still a standard first step in edge detection.

Each kernel is separable: Gx is a smoothing step [1, 2, 1] down the column followed by a difference [−1, 0, +1] across the row, and Gy is the same turned through 90°. The smoothing is why Sobel is less upset by noise than a plain difference of neighbouring pixels, and it is why the middle row and column carry weight 2.

About This Tool

This tool runs the Sobel operator on every pixel, including the border, and shows the result as thresholded edges or as greyscale edge strength, with an optional invert. It reports the largest and mean gradient and the share of edge pixels, plots the gradient histogram with the threshold marked, and works through the 3 × 3 block of any pixel you click. Settings can be put in the page address, for example ?mode=strength&gain=1.5&invert=1.

Images are decoded and saved in your browser by the engine behind the Universal Image Converter, so TIFF, PSD, HEIC, TGA and RAW files work too. Nothing is uploaded.

Related tools: Image Adjustments, Floyd-Steinberg Dithering, and ASCII Art Generator.

Frequently Asked Questions

How does the Sobel operator find edges?

For every pixel it compares the grey values on either side. Gx subtracts the left column of the 3 × 3 block from the right column, weighting the middle row twice, and Gy does the same for the bottom row minus the top row. The edge strength is √(Gx² + Gy²): zero on a flat area, large where brightness changes fast.

What threshold should I use?

Gradient strength runs from 0 to 1,140.4 (255 × √20). A hard black-to-white boundary gives 1,020 and a step from grey 50 to 200 gives 600, while fine noise of ±5 grey levels can reach 44.7. Start around 100 to 150 for clean outlines and raise it until texture such as grass or skin drops out.

Why does an edge between two colours sometimes disappear?

The operator works on brightness, Y = 0.299R + 0.587G + 0.114B. Two colours with the same brightness have no edge between them: pure red (255, 0, 0) has Y = 76.2, almost exactly the same as the grey (76, 76, 76), so a red shape on that grey vanishes.

What is the difference between Edges and Strength?

Edges makes every pixel either white (above the threshold) or black, which gives clean line art. Strength keeps the gradient as a grey level, min(255, |G| × gain), so strong edges are bright and weak ones faint, like a pencil sketch. In Strength mode the threshold works as a noise floor: anything below it stays black.

What happens at the border of the picture?

The 3 × 3 block needs a neighbour on every side, so at the border the nearest edge pixel is repeated outwards. Every pixel gets a real result, and there is no blank frame around the picture.

How do I use the Edge Detection (Sobel)?

Simply type your numbers and read the result, which refreshes the instant you change something. There is nothing to submit and nothing to wait for.

Do I need to install or sign up for anything?

Not at all — it runs in the browser with nothing to install and no account. After it loads once, it even works without an internet connection.

Is my information private?

Yes. Everything happens in your browser. Nothing you type is sent to a server or saved anywhere.

Common Use Cases

Colouring pages and line art

Edges with Invert at threshold 150 turns a photo of a house or pet into black outlines on white.

Pencil-sketch effect

Strength mode, gain 1.5 and Invert give soft grey strokes whose darkness follows the edge strength.

Checking focus

Of two shots of the same scene, the sharper one has the higher Mean Gradient readout.

Plotter and laser engraving prep

A clean 1-bit edge map is a starting point for a vector trace or an engraving outline.

Last updated: