Guide frames improve centerline estimation of complex postures in WormTracer Authors: Chung-Kuan Chen, Yuichi Iino, Yu Toyoshima Published: 2026 ABSTRACT Precise estimation of body posture is essential for analyzing animal behavior. C. elegans exhibits a variety of complex postures, such as turning and looping, for which centerline extraction is challenging. WormTracer, an algorithm designed to ensure temporal continuity of centerlines, enabled reliable centerline extraction. However, accurate estimation remains difficult without human intervention in animals exhibiting prolonged, complex postures. Here, we present an updated version of WormTracer that accepts user-revised centerlines as guide frames, enabling accurate estimation even during prolonged complex postures. In addition, we provide a Napari plugin, Napari-WormTracer, which allows users to manually revise centerlines estimated by WormTracer. (A) Time-series analysis of a representative worm exhibiting prolonged complex postures. The first panel shows posture classification (simple vs. complex), with guide frames indicated in green. The second panel shows image loss (MSE) for centerlines obtained using the canonical thinning algorithm (gray) and after WormTracer optimization either without (blue) or with (orange) guide frames. (B) Time-series raw images and corresponding binarized mask overlaid with the centerlines estimated without or with guide frame at time point 797. Circle indicates head position. Centerlines obtained without guide frames are shown in blue, whereas those obtained with guide frames are shown in orange. A manually annotated centerline used as a guide frame is shown in green. (C) Interface of Napari-Wormtracer, a Napari-based plugin for revising centerlines exported from WormTracer, is shown. Description Behavioral analysis relies on accurate extraction of body posture, which is essential for uncovering the mechanisms underlying motion control and for quantitatively modeling the movement. However, precise posture estimation remains challenging due to the diversity of postures, frequent occlusion of body parts, and variability in imaging conditions (Mathis et al., 2018; Pereira et al., 2022). In C. elegans research, many studies have been dedicated to estimating the body posture using variety of computational approaches. For example, Tierpsy provides a well-established pipeline to analyze the worm posture using traditional imaging processing techniques (Javer, Currie, et al., 2018; Javer, Ripoll-Sánchez, et al., 2018). Moreover, deep learning models for instance segmentation have improved posture estimation by increasing the accuracy of binary masks (Castro et al., 2025; Deserno & Bozek, 2023). In addition to the mask-based extraction, several methods directly predict the centerlines from raw input images without prior binarization (Alonso & Kirkegaard, 2023; Hebert et al., 2021; Layana Castro et al., 2023; Saha et al., 2025; Weheliye et al., 2025). However, training such deep learning model typically requires large amounts of manually annotated data or generation of synthetic data from limited annotations. To address this limitation, in our previous study we developed WormTracer (Kuze et al., 2026), an algorithm that estimates the centerline by comparing a worm-shaped mask reconstructed from the candidate centerline with the observed worm silhouette, while enforcing temporal continuity and spatial smoothness of the centerlines. First, WormTracer preprocessed the input masks to extract the centerlines using a canonical thinning algorithm. The extracted centerlines were then classified as either “simple” or “complex”. For example, during turning behavior, contact between the head or tail and the body generated looped masks that could not be accurately resolved using the thinning algorithm alone. Consequently, these frames were classified as “complex”. To objectively identify the complex frames based on the estimated centerlines, WormTracer evaluated the pixel mismatch between the original binary body mask and the mask reconstructed from the centerlines. Frames in which the thinning algorithm failed to accurately reconstruct the original mask were classified as complex ( Fig. 1A ). Consecutive frames with the same classification were then grouped into behavioral sequences. Following this preprocessing step, initial centerlines for the simple sequences were derived directly from the thinning method, whereas those for the complex sequences were generated by linearly interpolating centerlines from adjacent simple sequences. These estimates were then optimized via gradient descent to minimize mask pixel mismatch, with a regularization penalty for abrupt spatial and temporal changes. Eventually, the output centerlines were optimized to best fit the input mask while maintaining their spatial and temporal continuity. The entire optimization required only a time-series binary mask, and the centerlines were automatically estimated without human intervention. Despite these advantages, WormTracer has several limitations. When complex postures persist for a long period, relying on adjacent simple frames for initial estimates becomes insufficient. The errors are more likely to occur in highly coiled shapes, where mask-based reconstruction alone may fail to resolve the correct centerline topology. An example dataset shown here exhibited prolonged complex posture from time points 776 to 968 and was analyzed using WormTracer to estimate centerlines ( Fig. 1A, blue). In this case, frames around time point 797 showed increased image loss. Consistently, these frames also displayed incorrect centerline predictions ( Fig. 1B, blue). To address these limitations, we updated WormTracer to incorporate manually specified centerlines (termed guide frames) for optimization. The guide frames serve as anchoring points that are treated as ground truth during optimization and partitions the full sequence into smaller optimization blocks. During optimization, these guide frames correct the topology of the centerlines, allowing the continuity constraints of the WormTracer algorithm to propagate the correct head-tail orientation and bending angles to neighboring frames. As a result, providing a single guide frame at time point 797 ( Fig. 1A and B, green) corrected the centerline topology not only at that frame but also during the complex postures around time point 865 within the same behavioral sequence ( Fig. 1A and B, orange). This result indicates that guide frames can resolve erroneous centerline topology and allow WormTracer to automatically propagate the correction throughout the sequence, substantially reducing the amount of manual intervention required. In conclusion, incorporating guide frames improves overall prediction accuracy and enables WormTracer to recover correct centerlines with minimal manual intervention. The updated version of WormTracer is available at: https://github.com/lycantrope/wormtracer/releases/tag/v21.0.0 In addition to enabling WormTracer to incorporate guide frames for centerline refinement, we developed a Napari plugin (Sofroniew et al., 2026), Napari-WormTracer ( Fig. 1C ; https://github.com/lycantrope/napari-wormtracer ). This tool enables users to easily inspect centerlines generated by WormTracer. It also provides functionality to manually revise centerlines and register these corrections, facilitating the generation of guide frame data for subsequent WormTracer optimization. Furthermore, it can serve as a practical tool to prepare training datasets for other established methods. In summary, guide frames enhance the robustness of WormTracer for complex postures, and Napari-WormTracer provides a practical interface for manual correction, enabling accurate centerline estimation with minimal user intervention. Methods Strains and culture All C. elegans strains were mainly cultured on nematode growth medium (NGM) with Escherichia coli strain OP50 , as described (Brenner, 1974) and maintained at 20°C. For sample movies, bright field images were acquired from adult individuals of TOY21, a strain derived from QD15#4 (Toyoshima et al., 2020; Yang et al., 2026) and was developed for whole-brain calcium imaging. Definition of loss functions for centerline estimation WormTracer defines five loss functions to evaluate the fitness of estimated centerlines to the observed worm mask, which ensures both spatial accuracy and temporal continuity (Kuze et al., 2026). These include image loss, temporal angular continuity loss (continuity loss), spatial angular continuity loss (smoothing loss), length continuity loss (length loss), and centroid loss (center loss). Specifically, image loss is calculated as the mean squared error (MSE) between two masks, the observed worm silhouette and the mask reconstructed from the estimated centerline. Temporal and spatial angular continuity losses are defined as the MSE differences of segment bending angles along the temporal dimension (i.e., between consecutive time points) and the spatial dimension (i.e., along the centerline within a single frame), respectively, constraining abrupt changes in angle. Length continuity loss and centroid loss enforce consistency in segment length and stability of the center of mass by minimizing their variance and displacement, respectively. Implementation of WormTracer with guide frames The major difference from the previous version of WormTracer was the support for incorporating guide frames. Particularly, the newer of WormTracer loaded the correct centerlines from external files. After calculating the image loss as, Im loss,t = MSE(mask model,t − mask real,t ) , the losses in the frames with correct centerlines (guide frames) were replaced by the minimum loss, expressed as Im loss,t_g = min(Im loss,t ), t_g ∈ guide_frames . Subsequently, the long behavioral sequences were split into small optimization blocks at these guide frames, thereby anchoring the topology of neighboring centerlines, such as head-tail orientation, segment length and bending angles. WormTracer was implemented in Python using several libraries for data analysis and image processing, including NumPy (Harris et al., 2020), SciPy (Virtanen et al., 2020), scikit-image (Van Der Walt et al., 2014), and OpenCV (Bradski, 2000). Deep learning components were implemented using PyTorch (Paszke et al., 2019). Visualization was performed using Matplotlib (Hunter, 2007), and the final figure layouts were assembled using Inkscape ( https://inkscape.org/ ). All code and detailed usage instructions are available at https://github.com/lycantrope/wormtracer and https://github.com/lycantrope/napari-wormtracer . In this paper, we used WormTracer v21.0.0 and napari-wormtracer 2026.05.29. Reagents Strain Genotype Source OP50 Escherichia coli CGC TOY21 qjIs11[glr-1p::svnls2::TagBFPsyn, ser-2 (prom2)p::svnls2::TagBFPsyn] V; peIs3042[eat-4p::svnls2::TagRFP675syn,lin-44p::GFP ] X.; Is[H20p::nls3::tdTomato,H20p::nls2::GCaMP6f]#72-2-5 (Yang et al., 2026) Strain Genotype Source OP50 Escherichia coli CGC TOY21 qjIs11[glr-1p::svnls2::TagBFPsyn, ser-2 (prom2)p::svnls2::TagBFPsyn] V; peIs3042[eat-4p::svnls2::TagRFP675syn,lin-44p::GFP ] X.; Is[H20p::nls3::tdTomato,H20p::nls2::GCaMP6f]#72-2-5 (Yang et al., 2026)