Turns the image into black-and-white vector paths: first it decides which pixels belong to the shapes (thresholding), then it follows their outlines, and finally it simplifies and smooths them. The steps, in the order they are applied, are as follows.
1. Working resolution and blur
The image is converted to 8-bit grayscale and enlarged s times (s = 1, 2 or 4) with bicubic interpolation. Working at a higher resolution places edges with sub-pixel accuracy, which greatly improves small images. If W·H·s² would exceed 4·107 pixels, s is reduced automatically. Then a Gaussian blur of σ·s is applied, if σ > 0. All parameters in pixels refer to pixels of the original image; internally they are multiplied by s.
2. Thresholding
Fixed: T is the same for the whole image, the chosen level (0–255).
3. Edge cleaning
4. Outlines
cv::findContours follows the border of every shape and every hole (Suzuki and Abe algorithm). OpenCV returns the centres of the border pixels, so each outline is shifted half a pixel towards the background to run along the actual pixel edges. Without this step shapes would be one pixel thinner and 1-px lines would vanish.
5. Simplification
6. Curves and corners
7. SVG file
All outlines form a single black path with the even-odd fill rule (fill-rule="evenodd"): a point is filled if a ray starting from it crosses the path an odd number of times, which is why holes are transparent. Coordinates are in pixels of the original image, with pixel (i, j) covering the square [i, i+1]×[j, j+1], written with two decimals. The "nodes" shown in the dialog are the segments (lines and curves) of the path.
Parameters
| Parameter | Meaning |
|---|---|
| Threshold method | How T is computed (step 2). |
| Threshold level (fixed method) | T for the fixed method, from 0 to 255. |
| Block size in px (adaptive method) | b, window side for the adaptive method (odd). It must be larger than the strokes: about 2–5 times their width. |
| Offset C (adaptive method) | C, in gray levels. Higher = only pixels clearly darker than their surroundings are traced (less noise). |
| Pre-blur (sigma, px) | σ of the pre-blur (step 1). Reduces noise and rounds jagged edges. |
| Trace light shapes (invert) | Traces light areas instead of dark ones. |
| Working resolution | s (step 1). |
| Edge cleaning (px) | r in step 3; 0 = no cleaning. |
| Ignore specks smaller than (px²) | Minimum area in px² (step 4). |
| Simplification (px) | ε in step 5, in pixels. 0 = no simplification: the SVG reproduces the thresholded image pixel by pixel. |
| Outline | Polygons or Bézier curves (step 6). |
| Keep corners sharper than (degrees) | θcorner in degrees (step 6). 0 = all corners (polygon); 180 = all curves. |
| White background in the SVG | Adds a white rectangle behind the path; otherwise the background is transparent. |
See also: Morphology, Interpolation and borders
References
- OpenCV 4.x documentation — Miscellaneous Image Transformations (threshold, adaptiveThreshold). docs.opencv.org/4.x/d7/d1b/group__imgproc__misc.html
- N. Otsu. "A threshold selection method from gray-level histograms." IEEE Transactions on Systems, Man, and Cybernetics, 9(1):62–66, 1979.
- OpenCV 4.x documentation — Structural Analysis and Shape Descriptors (findContours, approxPolyDP). docs.opencv.org/4.x/d3/dc0/group__imgproc__shape.html
- S. Suzuki, K. Abe. "Topological structural analysis of digitized binary images by border following." Computer Vision, Graphics, and Image Processing, 30(1):32–46, 1985.
- D. H. Douglas, T. K. Peucker. "Algorithms for the reduction of the number of points required to represent a digitized line or its caricature." Cartographica, 10(2):112–122, 1973.
- W3C. Scalable Vector Graphics (SVG) 1.1 (Second Edition), 2011 — paths and the fill-rule property. www.w3.org/TR/SVG11/