ComfyUI Node

Sketch

Turn a photo into pencil-drawing lines with XDoG

By licyk·Created 2 years ago·Updated 12 months ago· 14
Sketch
  • image
  • image
kernel_size0
sigma1.40
k_sigma1.60
epsilon-0.030
phi10
gamma1.000
color_mode
scalefalse

Sketch converts a photo into pencil/ink line art - not a stylized filter approximating a sketch, but an actual edge-detection algorithm. The parameter names give it away if you know computer vision: sigma, k_sigma, epsilon, phi, gamma are the textbook parameters of XDoG (eXtended Difference-of-Gaussians), a well-established non-photorealistic rendering technique for turning images into clean line drawings. This isn't a diffusion effect and it's not learned from anything - it's classic image processing, deterministic and fast.

How it works

Difference-of-Gaussians finds edges by blurring an image at two slightly different radii and subtracting one from the other - what's left is the detail that exists at one blur level but not the other, which lines up closely with actual edges in the image. XDoG extends this with a soft threshold instead of a hard on/off cutoff, which is what lets it produce continuous, ink-like lines rather than a broken, noisy edge map.

The inputs and outputs that matter

  • image - your source.
  • sigma (1–5, default 1.4) and k_sigma (1–5, default 1.6) - the two blur radii being differenced. k_sigma should generally stay larger than sigma; leave both near default unless you're specifically after thicker or thinner base lines.
  • epsilon (-0.2 to 0.2, default -0.03) - the threshold that decides what counts as an edge. More negative pushes toward cleaner, sparser lines with more white space; closer to zero (or positive) darkens the result and pulls in more detail as linework.
  • phi (1–50, default 10) - controls how sharp the transition is at that threshold. Higher values make the line/no-line boundary crisper; lower values give a softer, more graphite-like gradient instead of hard black lines.
  • gamma (0.75–1, default 1) - a soft toning adjustment on the non-edge areas.
  • color_mode (gray / rgb) - gray gives you the classic pencil-sketch look; rgb keeps the line art in the original colors instead of converting to grayscale.
  • scale (bool) - whether to rescale the output's value range.

One image output.

How to install it

Search ComfyUI-HakuImg in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone --recurse-submodules https://github.com/licyk/ComfyUI-HakuImg

Restart ComfyUI, find it under Image → HakuImg. No models involved - this is pure math on pixel values, runs instantly regardless of GPU.

Common issues & troubleshooting

Lines are too faint or sparse. Nudge epsilon toward zero, or raise phi a bit - both push more of the image's contrast into visible linework rather than white space.

Whole image comes out solid black or solid white. You've pushed a parameter outside its sane working range, most often epsilon too far positive or phi too extreme. Reset toward the defaults (sigma 1.4, k_sigma 1.6, epsilon -0.03, phi 10) and adjust one parameter at a time from there rather than several at once - with five interacting numbers, it's easy to lose track of which one broke it.

Result looks noisy rather than clean. Try increasing sigma slightly - a larger base blur radius smooths out fine texture noise before the edge-difference step, which tends to produce cleaner, more deliberate-looking lines on photos with a lot of surface detail (skin texture, fabric, foliage).

Categoryimage/HakuImg

Inputs (9)

NameTypeDefaultDescription
imageIMAGE
kernel_sizeINT00–25
sigmaFLOAT1.401–5
k_sigmaFLOAT1.601–5
epsilonFLOAT-0.030-0.2–0.2
phiFLOAT101–50
gammaFLOAT1.0000.75–1
color_modeCOMBO2 options: gray, rgb
scaleBOOLEANfalse

Outputs (1)

NameTypeDescription
imageIMAGE