Remove Paper Texture From a Scan Before Vectorizing
Clean grain and uneven paper shading from scanned line art. Compare a global threshold with local cleanup and check that faint marks survive in the SVG.
On this page
- Tell paper grain from a shadow
- Use local cleanup when the page brightness varies
- Reproduce the local cleanup with Pillow
- Compare the paper and the faintest line in the traced SVG
- Decide when to stop cleaning
- FAQ
- Why does my vector trace have hundreds of tiny shapes?
- Will a stronger blur remove all the texture?
- Can I keep pencil shading and still remove the paper?
- Sources
Remove paper texture on a copy of the scan before you trace the drawing. If a global black-and-white threshold turns a dark corner into specks while erasing faint lines on a bright part of the page, clean up small grain and estimate the background locally. Compare the result with the original at the thinnest mark you need to keep.
Tell paper grain from a shadow
Start with two crops. Choose one where the page should be blank, and a second with a delicate pencil stroke or a small break between lines. At 100%, grain appears as fine variation from pixel to pixel. A shadow changes brightness across a much wider area. Both can turn into black shapes when the tracing tool reads a two-tone image.
Test a global threshold first. It applies the same brightness cutoff across the image. If the background in both crops turns white and the faint stroke stays visible, the scan may be ready to trace. GIMP's Threshold tool lets you preview the black-and-white change. GIMP Threshold documentation
Use local cleanup when the page brightness varies
- Keep a copy of the original. Crop away the scanner bed and paper border on a working copy. Keep any reference marks you need beside the drawing.
- Reduce fine grain. Test a small median filter, which replaces each pixel with the middle brightness of its neighborhood. Start with the smallest neighborhood and recheck the thinnest line. A filter that cleans the paper can also remove dots or narrow strokes. Pillow image filter reference
- Estimate the paper brightness near each mark. Use a maximum filter with a window wider than the thin strokes, then smooth its output to estimate slow changes in the paper. Subtract the working image from this estimate. Dark marks stand out when they sit on lighter nearby paper, even in a dim corner. Pillow channel operations reference
- Threshold the resulting difference. Keep pixels that are substantially darker than the nearby paper. Leave the mask black on white for tracing, then compare the two crops again. If a heavy filled area loses its center, try a larger background window or keep that area from a separate mask.
Reproduce the local cleanup with Pillow
This example uses Python with Pillow and a grayscale copy named scan.png. The settings are from the 960 × 575 pixel drawing below. On a different scan, adjust the cutoff as you compare the blank area and faint stroke.
from PIL import Image, ImageChops, ImageFilter
scan = Image.open("scan.png").convert("L")
quiet = scan.filter(ImageFilter.MedianFilter(3))
paper = quiet.filter(ImageFilter.MaxFilter(19))
paper = paper.filter(ImageFilter.GaussianBlur(15))
difference = ImageChops.subtract(paper, quiet)
mask = difference.point(lambda value: 0 if value >= 42 else 255)
mask.save("clean.pgm")The 42 is a difference in grayscale brightness. Increase it to reject weaker marks, or decrease it to retain fainter ones. Once the mask looks right, open it in a vector editor that can trace bitmaps, or use Potrace to get editable paths. Potrace manual
potrace --svg --turdsize 2 --output cleaned.svg clean.pgmCompare the paper and the faintest line in the traced SVG
We drew a stem with thin leaf veins and added digital grain and a broad shadow to simulate a scan. We saved three masks of that same image and traced each with Potrace 1.16 using identical settings. We rendered the SVGs at the original pixel size and counted dark pixels in the known paper and vein regions. The paper count excludes the one-pixel border next to the original lines.
| Mask before tracing | Dark pixels in the paper region | Leaf-vein pixels retained out of 4,518 |
|---|---|---|
| Global threshold at 125 | 36,454 | 2,443 |
| Global threshold at 158 | 106,367 | 4,241 |
| Median filter and local paper estimate | 1 | 4,398 |

A higher global threshold kept more of the veins and also picked up more of the shaded paper. Local cleanup kept more veins in this simulated example, but still lost some fine-line pixels after tracing. The count describes this drawing and these settings. Visible continuity, open gaps, and recognizable detail matter more than getting the same numbers.
Decide when to stop cleaning
Open the resulting SVG over a light background and inspect the blank area for stray shapes. Check the top and bottom of the same thin stroke for breaks. Compare small marks against the original before deleting them. Dark pencil shading, textured outlines, and intentional stippling may be part of the drawing. If their tone matters, consider keeping that part as raster art.
When you have a clean raster copy, you can convert the cleaned line drawing to vector paths. For general setup, see the line-art tracing guide. If the scan includes printed blue rules instead of neutral grain, use the blue-line cleanup workflow.
FAQ
Why does my vector trace have hundreds of tiny shapes?
The tracing tool may be following paper grain, dust, or shaded areas that turned dark in the mask. Clean a copy of the scan before tracing again, then inspect regions that should be blank.
Will a stronger blur remove all the texture?
A stronger blur mixes more of the surrounding pixels into the drawing and may weaken small marks. Start with a small filter and inspect an enlarged crop next to the original.
Can I keep pencil shading and still remove the paper?
A two-tone mask turns shading into solid shapes, gaps, or specks depending on the cutoff. Keep a cleaned raster copy when gradual pencil shading is part of the artwork. Use a separate vector trace for the outlines if that helps the job.
Sources
- GIMP — Threshold — previewing how an intensity range becomes a black-and-white mask.
- Pillow — ImageFilter — the median, maximum, and Gaussian filters in the example.
- Pillow — ImageChops — subtracting the working image from the background estimate.
- Potrace — Command-line manual — tracing a PGM mask to SVG and the speckle-area argument.
After the paper is clean, trace the drawing with PerfectVector. Open the SVG over a light background and check the area around the faintest line for stray specks and breaks.
More from the blog
Coloring Page Line Thickness: Check the Printed Size
Choose coloring-page line thickness at the final size. Compare stroke weights, preserve small coloring spaces, and check whether your SVG uses strokes or fills.
Scan or Photograph Line Art Before Vectorizing?
Choose a scan or photo for line art by checking flatness, size, lighting, and detail. Compare capture with the original before turning pixels into SVG paths.


