Field From Edges
Sobel, Scharr, Laplacian — and a Canny That Behaves
- image
- mask
Edge detection, with the boring problems already solved
Every ComfyUI install has an edge detector - the ControlNet preprocessor pile has a dozen. Field From Edges is not trying to beat Canny's output quality. It's trying to give you an edge field: a soft, normalised, resolution-aware mask you can feed into the rest of the Field pack's maths without spending an afternoon on thresholds.
The difference is in two defaults. First, a frame-relative pre-blur runs before any operator, which is what stops a 4K render from coming back as a field of pure grain. Second, the result is normalised so coverage is exact: ask for the top 5% of edge energy and you get the top 5%, whether you're on a photo or line art.
The four operators
sobel is the default and the general-purpose one. scharr is Sobel's better-behaved cousin - a different kernel with the same idea, less directional bias at 45°. laplacian is second-derivative, sensitive to fine structure and noisy as a result; it's the one you'd pick for texture rather than contours.
hysteresis is the interesting one - it's the Canny-style step. Two thresholds: pixels above the strong one seed connected components, and only the weak pixels connected to a strong pixel survive. That's what turns a scatter of speckle into continuous contours, and it's the classic answer to "my edge map is broken lines and dust". Both thresholds are given as coverages rather than levels, which is the fix for the usual problem that a measured edge magnitude has a median around 0.004 - no fixed level default survives a change of image, so nobody ever finds one that works. You get strong_coverage (default 0.02) and weak_coverage (default 0.08).
Nor are the ranges guessed. Each operator declares its exact maximum response, derived by enumerating all 512 binary 3×3 patches: Sobel 2*sqrt(5) ≈ 4.4721, Scharr ≈ 18.8680, Laplacian 4.0. That's what makes the coverage control meaningful instead of decorative.
The inputs that matter
image- the IMAGE to analyse.operator-sobel,scharr,laplacian,hysteresis.smooth- 0 to 0.05, default 0.002, a frame-relative pre-blur sigma. This is your anti-grain knob. Turn it up before you turn thresholds down.strong_coverage/weak_coverage- hysteresis only. Ignored otherwise.distribution- defaultuniform, and that default really matters here. Normalised Sobel on a real photograph has a median around 0.0043 with a p99 of 0.115; innativemode that's a near-black frame with a few bright lines and you'll assume the node is broken.coveragelikewise defaults to 0.5 on top of the rank transform.
Output is a single mask.
What you'd wire it into
Edge fields are how you make an effect follow structure instead of location. Multiply the edge field by Perlin noise with Field Combine and you've got an effect that lands on the contours of the image and nowhere else, in a random pattern. Threshold it with Field Threshold's band mode and you get a contour stroke. Run it through Field Morphology's outline and you've grown that stroke into a band.
If you're thinking "isn't this what a ControlNet preprocessor does" - sort of, and not. A preprocessor gives you a conditioning image for a model. This gives you a mask for compositing and blending. Different target, different normalisation, and the mask version is the one that composes with the rest of this pack.
Install
Manager → ComfyUI Field; or:
cd ComfyUI/custom_nodes
git clone https://github.com/jeremieLouvaert/ComfyUI-Field
Restart ComfyUI. No model files. It's under AKURATE/Fields/Derive. Hysteresis uses SciPy for connected-component labelling, imported lazily inside the node; SciPy already ships with ComfyUI, and the other three operators don't touch it at all. If you've somehow got a SciPy-less environment, sobel/scharr/laplacian still work and only hysteresis will complain.
Honest limits
A finite-difference operator has a pixel-scale kernel. So this field is approximately resolution-independent, not exactly - the pack says so plainly, and it's the same category of caveat as Field From Detail. The procedural generators (Noise, Gradient, Shape, Tile, Scatter) are the ones with the bitwise cross-resolution guarantee; the derived filters can't have it.
The other trap is expecting laplacian to give you contours. It gives you fine structure, which on a textured image is a lot of fine structure. Reach for scharr or hysteresis when you want lines; reach for laplacian when you're hunting micro-detail you intend to threshold aggressively afterward.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| operator | COMBO | sobel | 4 options: sobel, scharr, laplacian, hysteresis |
| smooth | FLOAT | 0.0020–0.05 | — |
| strong_coverage | FLOAT | 0.0200.001–0.5 | — |
| weak_coverage | FLOAT | 0.0800.001–0.5 | — |
| distribution | COMBO | uniform | 2 options: uniform, native |
| coverage | FLOAT | 0.500–1 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |