(tutorial) Edge & Blob Tracking Visuals *Script Setup & How to Use* (Patreon)
Videos
-
545531915.mp4
Downloads
Content
Edge Tracking Visuals – Turning Motion into Lines | TouchDesigner Tutorial
Hello, this is Xtal!
In this tutorial, we transform motion into flowing trails of light using edge detection and Python scripting inside TouchDesigner.
Three different script networks are combined to generate evolving visual layers typographic trails, fine-edge tracking, and line connections all reacting to the contours of your input video.
Through this process, motion data becomes a dynamic visual fabric where letters, paths, and shapes continuously trace and dissolve, forming an organic, data-driven aesthetic.
Core Steps Covered
Building edge extraction with threshold and blur
Creating letter-based motion trails via Script TOP
Generating fine-edge character tracking with random jitter
Drawing dynamic line connections that react to movement
Compositing all layers for a final cinematic output
Control Guide
THRESH adjusts the contour sensitivity
POINTS increases density and line intersections
FADE controls trail length and persistence
JITTER defines the organic roughness of the lines
Script Setup & How to Use
Script 1: Typographic Trail – generates fading text traces that follow motion edges.
Script 2: Fine-Edge Tracking – places letters in real time along micro-contours.
Script 3: Dynamic Line Tracer – connects sampled points per frame to form living line structures.
All Python scripts used in this tutorial are provided.Simply paste each code block into the onCook callback of its Script TOP while following the video, and you will reproduce the same results.
Steps to follow
Add three Script TOPs and name them script1, script2, and script3.
In each Script TOP, enable Python callbacks and paste the provided code into the onCook function.
Wire the network as shown in the tutorial:
script1: preprocessed input (Blur/Threshold) → typographic trail
script2: fine edge (Threshold) → alphabet tracking
script3: same or variant input → line tracing
Merge the three outputs in a Composite node (e.g., Screen operation).
Tune THRESH, POINTS, FADE, JITTER to taste.
Use Render → Null → Movie File Out to export when ready.
Note: Behavior may vary by TouchDesigner build; using the same version as in the tutorial is recommended.
Script 1: Typographic motion trail – leaves fading text traces that follow the edge of motion.
import numpy as np rng = np.random.default_rng(20251002)
prevgray = None canvas = None char_i = 0
_ALPHA = { 'A':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'B':np.array([[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,0,0]],dtype=np.uint8), 'C':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'D':np.array([[1,1,1,0,0],[1,0,0,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,1,0],[1,1,1,0,0]],dtype=np.uint8), 'E':np.array([[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), 'F':np.array([[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]],dtype=np.uint8), 'G':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,0],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'H':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'I':np.array([[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1]],dtype=np.uint8), 'J':np.array([[0,1,1,1,1],[0,0,0,1,0],[0,0,0,1,0],[0,0,0,1,0],[1,0,0,1,0],[1,0,0,1,0],[0,1,1,0,0]],dtype=np.uint8), 'K':np.array([[1,0,0,0,1],[1,0,0,1,0],[1,0,1,0,0],[1,1,0,0,0],[1,0,1,0,0],[1,0,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'L':np.array([[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), 'M':np.array([[1,0,0,0,1],[1,1,0,1,1],[1,0,1,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'N':np.array([[1,0,0,0,1],[1,1,0,0,1],[1,0,1,0,1],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'O':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'P':np.array([[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]],dtype=np.uint8), 'Q':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,1,0],[0,1,1,0,1]],dtype=np.uint8), 'R':np.array([[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,0],[1,0,1,0,0],[1,0,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'S':np.array([[0,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[0,0,0,0,1],[1,1,1,1,0]],dtype=np.uint8), 'T':np.array([[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],dtype=np.uint8), 'U':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'V':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,0,1,0],[0,1,0,1,0],[0,0,1,0,0]],dtype=np.uint8), 'W':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,1,0,1],[1,1,0,1,1],[1,1,0,1,1],[1,0,0,0,1]],dtype=np.uint8), 'X':np.array([[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'Y':np.array([[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],dtype=np.uint8), 'Z':np.array([[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), ' ':np.zeros((7,5),dtype=np.uint8) }
TEXT = "CALX WRITES THE MOTION " THRESH = 0.5 RATE = 60
SCALE = 1
FADE = 0.90
JITTER = 2.0
def togray01(img): img = img[..., :3].astype(np.float32) return np.clip(0.2126img[...,0]+0.7152img[...,1]+0.0722*img[...,2], 0, 1)
def edgesfrom_thresh(gray, thr): mask = (gray >= thr).astype(np.uint8) up=np.roll(mask,-1,0); down=np.roll(mask,1,0) left=np.roll(mask,1,1); right=np.roll(mask,-1,1) edge=(mask & ((up!=mask)|(down!=mask)|(left!=mask)|(right!=mask))).astype(np.uint8) return edge
def draw_letter_rgba(canvas, ch, cx, cy, s=2, color=(1,1,1,1)): H,W, = canvas.shape bmp = ALPHA.get(ch, ALPHA[' ']) h7,w5 = bmp.shape x0 = int(cx - (w5s)//2); y0 = int(cy - (h7s)//2) for yy in range(h7): for xx in range(w5): if bmp[yy,xx]: ys=y0+yys; xs=x0+xxs ys2=min(H,ys+s); xs2=min(W,xs+s) if ys>=0 and xs>=0 and ys<H and xs<W: canvas[ys:ys2, xs:xs2, :] = color
def onCook(scriptOp): global prevgray, canvas, char_i
inTOP = scriptOp.inputs[0] if scriptOp.inputs else None if inTOP is None: h, w = 480, 640 if canvas is None or canvas.shape[:2] != (h,w): canvas = np.zeros((h,w,4), dtype=np.float32) scriptOp.copyNumpyArray(canvas); return
arr = inTOP.numpyArray() if arr is None: return H,W = arr.shape[0], arr.shape[1] gray = togray01(arr)
if canvas is None or canvas.shape[0]!=H or canvas.shape[1]!=W: canvas = np.zeros((H,W,4), dtype=np.float32) prevgray = None chari = 0
_canvas *= FADE
edges = edgesfrom_thresh(gray, THRESH) ys, xs = np.nonzero(edges) n = ys.size if n > 0: k = min(RATE, n) idx = rng.choice(n, k, replace=False) if n>k else np.arange(n) L = len(TEXT) for i in idx: y = int(ys[i]); x = int(xs[i]) jx = int(rng.normal(0, JITTER)) jy = int(rng.normal(0, JITTER)) ch = TEXTchari % L].upper() drawletter_rgbacanvas, ch, x + jx, y + jy, s=SCALE, color=(1,1,1,1)) char_i += 1
scriptOp.copyNumpyArray(np.clip(_canvas, 0, 1)) return
Script 2: Fine-edge tracking – precise character generation reacting to edge micro-variations.
import numpy as np rng = np.random.default_rng(123)
_ALPHA = { 'A':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'B':np.array([[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,0,0],[1,0,0,1,0],[1,0,0,1,0],[1,1,1,0,0]],dtype=np.uint8), 'C':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'D':np.array([[1,1,1,0,0],[1,0,0,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,1,0],[1,1,1,0,0]],dtype=np.uint8), 'E':np.array([[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), 'F':np.array([[1,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]],dtype=np.uint8), 'G':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,0],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'H':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'I':np.array([[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[1,1,1,1,1]],dtype=np.uint8), 'J':np.array([[0,1,1,1,1],[0,0,0,1,0],[0,0,0,1,0],[0,0,0,1,0],[1,0,0,1,0],[1,0,0,1,0],[0,1,1,0,0]],dtype=np.uint8), 'K':np.array([[1,0,0,0,1],[1,0,0,1,0],[1,0,1,0,0],[1,1,0,0,0],[1,0,1,0,0],[1,0,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'L':np.array([[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), 'M':np.array([[1,0,0,0,1],[1,1,0,1,1],[1,0,1,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'N':np.array([[1,0,0,0,1],[1,1,0,0,1],[1,0,1,0,1],[1,0,0,1,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1]],dtype=np.uint8), 'O':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'P':np.array([[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,0],[1,0,0,0,0],[1,0,0,0,0],[1,0,0,0,0]],dtype=np.uint8), 'Q':np.array([[0,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,1,0],[0,1,1,0,1]],dtype=np.uint8), 'R':np.array([[1,1,1,1,0],[1,0,0,0,1],[1,0,0,0,1],[1,1,1,1,0],[1,0,1,0,0],[1,0,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'S':np.array([[0,1,1,1,1],[1,0,0,0,0],[1,0,0,0,0],[0,1,1,1,0],[0,0,0,0,1],[0,0,0,0,1],[1,1,1,1,0]],dtype=np.uint8), 'T':np.array([[1,1,1,1,1],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],dtype=np.uint8), 'U':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,1,1,0]],dtype=np.uint8), 'V':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[0,1,0,1,0],[0,1,0,1,0],[0,0,1,0,0]],dtype=np.uint8), 'W':np.array([[1,0,0,0,1],[1,0,0,0,1],[1,0,0,0,1],[1,0,1,0,1],[1,1,0,1,1],[1,1,0,1,1],[1,0,0,0,1]],dtype=np.uint8), 'X':np.array([[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,1,0,1,0],[1,0,0,0,1]],dtype=np.uint8), 'Y':np.array([[1,0,0,0,1],[0,1,0,1,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0],[0,0,1,0,0]],dtype=np.uint8), 'Z':np.array([[1,1,1,1,1],[0,0,0,0,1],[0,0,0,1,0],[0,0,1,0,0],[0,1,0,0,0],[1,0,0,0,0],[1,1,1,1,1]],dtype=np.uint8), }
def maskedges(mask): up=np.roll(mask,-1,0); down=np.roll(mask,1,0) left=np.roll(mask,1,1); right=np.roll(mask,-1,1) edge=(mask & ((up!=mask)|(down!=mask)|(left!=mask)|(right!=mask))).astype(np.uint8) return edge
def drawletter(img,ch,cx,cy,s=1,color=(1,1,1,1)): H,W,C=img.shape bmpALPHA.get(ch,ALPHA['A']) h7,w5=bmp.shape x0=int(cx-(w5s)//1); y0=int(cy-(h7s)//2) for yy in range(h7): for xx in range(w5): if bmp[yy,xx]: ys=y0+yys; xs=x0+xxs ys2=min(H,ys+s); xs2=min(W,xs+s) if ys>=0 and xs>=0 and ys<H and xs<W: img[ys:ys2,xs:xs2,:]=color
def onCook(scriptOp): inTOP=scriptOp.inputs[0] if scriptOp.inputs else None if inTOP is None: h,w=480,640 out=np.zeros((h,w,4),dtype=np.float32)
scriptOp.copyNumpyArray(out); return
arr=inTOP.numpyArray() if arr is None: return gray=0.2126arr[...,0]+0.7152arr[...,1]+0.0722*arr[...,2] mask=(gray>0.5).astype(np.uint8) edgesmaskedges(mask) ys,xs=np.nonzero(edges); n=ys.size
out=np.zeros((arr.shape[0],arr.shape[1],4),dtype=np.float32)
if n>0: K=min(60,n) idx=rng.choice(n,K,replace=False) if n>K else np.arange(n) offsets=np.array([[8,0],[-8,0],[0,8],[0,-8]],dtype=np.int32) letters=listALPHA.keys()) for i in idx: y=int(ys[i]); x=int(xs[i]) for off in offsets: yy=y+off[1]+rng.integers(-2,2) xx=x+off[0]+rng.integers(-2,2) draw_letter(out,rng.choice(letters),xx,yy,s=1,color=(1,1,1,1))
scriptOp.copyNumpyArray(np.clip(out,0,1)) return
Script 3: Dynamic line tracer – connects sampled points frame-by-frame, forming evolving line structures.
import numpy as np rng = np.random.default_rng(20251002)
prevpts = None _canvas = None
THRESH = 0.5 POINTS = 80 FADE = 0.5 JITTER = 1.0
def togray01(img): return np.clip(0.2126img[...,0]+0.7152img[...,1]+0.0722*img[...,2],0,1)
def _edges(gray, thr): mask=(gray>thr).astype(np.uint8) up=np.roll(mask,-1,0); down=np.roll(mask,1,0) left=np.roll(mask,1,1); right=np.roll(mask,-1,1) edge=(mask & ((up!=mask)|(down!=mask)|(left!=mask)|(right!=mask))).astype(np.uint8) return edge
def draw_line(img,x0,y0,x1,y1,color): H,W,=img.shape dx=abs(x1-x0); dy=abs(y1-y0) sx=1 if x0<x1 else -1 sy=1 if y0<y1 else -1 err=dx-dy while True: if 0<=y0<H and 0<=x0<W: img[y0,x0]=color if x0==x1 and y0==y1: break e2=2*err if e2>-dy: err-=dy; x0+=sx if e2< dx: err+=dx; y0+=sy
def onCook(scriptOp): global prevpts, canvas inTOP=scriptOp.inputs[0] if scriptOp.inputs else None if inTOP is None: h,w=1920,1080 if canvas is None or canvas.shape[0]!=h or canvas.shape[1]!=w: canvas=np.zeros((h,w,4),dtype=np.float32) scriptOp.copyNumpyArray(canvas); return
arr=inTOP.numpyArray() if arr is None: return H,W=arr.shape[0],arr.shape[1] graytogray01(arr[...,:3].astype(np.float32))
if canvas is None or canvas.shape[0]!=H or canvas.shape[1]!=W: canvas=np.zeros((H,W,4),dtype=np.float32) prevpts=None
_canvas *= FADE
edges=_edges(gray,THRESH) ys,xs=np.nonzero(edges) n=ys.size if n>0: k=min(POINTS,n) idx=rng.choice(n,k,replace=False) if n>k else np.arange(n) pts=np.stack([xs[idx],ys[idx]],axis=1) pts=pts+ rng.normal(0,JITTER,pts.shape).astype(int)
for i in range(len(pts)-1): x0,y0=pts[i]; x1,y1=pts[i+1] color=(rng.random(), rng.random(), rng.random(), 1.0) drawlinecanvas,x0,y0,x1,y1,color) if prev_pts is not None: for i in range(min(len(pts),lenprevpts))): x0,y0=pts[i]; x1,y1prevpts[i] color=(rng.random(), rng.random(), rng.random(), 1.0) drawlinecanvas,x0,y0,x1,y1,color) prev_pts=pts
else: prevpts=None
scriptOp.copyNumpyArray(np.clip(_canvas,0,1)) return