Mask Optimization for High-Precision Extraction of Geometric Features in Microscopic Scenes Authors: Tianbo Kang, Jianpeng Zhang, Xin Zhao, Mingzhu Sun, Yunwang Zhang Published: 2026 ABSTRACT Regular geometric targets under microscopic scenes, such as microspheres, micropores, and microtubes, are characterized by small scales, low contrast, and degraded boundaries. Masks generated by general segmentation methods often fail to directly support high-precision geometric parameter measurement. This paper proposes a mask optimization method for the high-precision extraction of regular geometric features in microscopic scenes. We establish a mask optimization framework that integrates initial mask generation with geometric consistency refinement. Mask initialization is first performed through segmentation and adaptive super-resolution (SR) under low annotation constraints. Subsequently, an iterative optimization strategy that fuses multi-dimensional pixel features with regular geometric priors is designed. By incorporating geometric features extracted from the current mask while maintaining stable pixel-level observations, the mask is progressively corrected until convergence to generate target masks with continuous boundaries that satisfy stringent geometric constraints. Our experimental results on a sphere–tube assembly dataset demonstrate that the proposed method achieves lower geometric errors on successfully fitted samples and significantly improves the fitting success rate. Ablation studies further confirm the critical roles of dynamic SR and iterative mask optimization in enhancing overall precision and stability. These findings suggest that for microscopic regular geometric measurement tasks, integrating geometric-consistency constraints into mask optimization effectively improves both the accuracy and robustness of geometric feature extraction. 1. Introduction Microscale assembly and precision manufacturing demand high-accuracy positioning and attitude measurement of microscale components. For regular geometric targets, such as microspheres, micropores, and microtubes, the geometric parameters (e.g., center position, radius or aperture, and central axis direction) serve as critical inputs for closed-loop control and quality assessment [1]. However, microscopic imaging is often degraded by the extremely small scales of the targets, low contrast, noise and blur, partial occlusion, or broken edges. Under such limited-data and complex imaging conditions, reliably extracting high-precision geometric features remains a challenging visual measurement problem. Object detection or keypoint/parameter regression methods are often misaligned with the goals of high-precision geometric measurement. Mainstream detectors, such as the YOLO series, Faster R-CNN, and RetinaNet [2,3,4], are typically optimized for class prediction and bounding box localization, and they only provide coarse-grained geometric descriptions. They cannot impose precise constraints on object boundaries and fine shape details, and they are particularly prone to localization fluctuations and scale instability on tiny objects, which further affects the accuracy of subsequent geometric parameter estimation [5]. Traditional keypoint detection or direct regression of geometric parameters (e.g., circle center and radius) still fails to achieve global modeling of complete object boundaries. Such methods are sensitive to local observation deviations under noise, occlusion, and edge missing conditions, leading to limited model generalization and stability [6]. For regular geometric targets, traditional approaches typically extract discrete boundary points using edge detection operators and subsequently derive geometric parameters based on these points [7,8,9]. While this workflow yields accurate estimations under ideal imaging conditions, its fundamental limitation resides in its heavy dependency on clear and continuous edge responses, rendering it sensitive to threshold configurations, noise levels, and contrast variations. In microscopic scenes, factors such as boundary blurring, fragmented edges, and spurious edges introduce significant outliers among the discrete boundary points. Consequently, these outliers lead to instability in parameter estimation, elevated error margins, and even complete fitting failure [10,11]. Furthermore, traditional edge detection extracts only isolated local features and fails to generate holistic, continuous masks. This lack of global modeling capability for complex backgrounds and local defects makes it challenging to achieve a balance between robustness and high precision within a single framework. In contrast, pixel-level segmentation directly generates complete and continuous masks, forming dense and global boundary constraints at the contour level. This approach addresses the core limitations of the two aforementioned categories of methods, enabling subsequent geometric fitting to fully leverage the target’s global structural information. Consequently, it mitigates the interference of noise from discrete boundary points on fitting results, thereby enhancing the precision of parameter estimation [12,13]. Therefore, in microscopic measurement tasks for regular geometries, the strategy of fitting based on segmentation results possesses inherent advantages. Specifically, boundary errors introduced during segmentation are explicitly quantified and iteratively corrected at the mask level, while the subsequent fitting stage further incorporates global geometric constraints, significantly improving the stability and interpretability of the estimation [14]. However, the existing segmentation methods struggle to balance some core requirements for microscopic scenes, such as low annotation cost, strong cross-scene adaptability, and high-precision boundary representation. Traditional methods based on thresholding, edge detection, and morphological operations are sensitive to illumination fluctuations, low contrast, and noise, thereby lacking robustness under the complex degradations typical of microscopic imaging [15]. Learning-based methods are further classified into Generic Image Segmentation (GIS) and Promptable Image Segmentation (PIS) according to their inference-stage input paradigms and task objectives [16]. GIS models (e.g., U-Net, Mask R-CNN, and DeepLab [17,18,19]) rely on large-scale pixel-level annotated data for full supervision training, which is economically infeasible for rapidly changing industrial microscopic scenes [20]. In contrast, due to the pre-training on large-scale public datasets, the PIS method completes the segmentation only via corresponding prompts, which fully matches the engineering requirements of low annotation and high portability in industrial scenarios. Based on the prompt type, PIS can be subdivided into three categories. Interactive segmentation (e.g., the SAM series [21,22,23]) relies on manual tips, such as point and box, unable to meet the automated deployment of microscopic scenarios. Referring segmentation using language prompts leads to a lack of the fine-grained adaptability required for industrial micro targets. Few-shot segmentation requires targeted fine-tuning or domain adaptation, which has insufficient accuracy in cross-scene generalization [24,25]. Context-learning segmentation, serving as vision generalists (exemplified by the original Painter and SegGPT methods proposed in 2023 [26,27]), performs end-to-end inference using context prompt pairs of reference images with masks and query images, without additional training or fine-tuning. Requiring only minimal reference masks, this paradigm precisely fits the engineering deployment needs of microscopic measurement while offering superior cross-scenario adaptability. Therefore, this study adopts the context-learning approach as the core of the segmentation module, which provides a solid foundation for initial mask generation of microscopic targets under low-annotation constraints. Although the targets can be segmented in the microscopic scenario, the scale of the targets changes significantly. For tiny objects with extremely low pixel occupancy, native models lack sufficient boundary representation capability, leading to issues such as boundary blurring, localization fluctuations, and incomplete contours. These defects are exponentially amplified during subsequent geometric fitting, directly degrading measurement accuracy. Current research often introduces super-resolution (SR) to enhance image details and improve segmentation accuracy. In the microscopic field, SR has been proven effective in improving boundary gradients and detail separability [28], but the existing methods face clear limitations. Global SR methods [29,30] upscale the entire image indiscriminately, introducing unnecessary computational overhead and potential background artifacts. Conversely, target-focused SR typically employs predefined, fixed enlargement factors [31], failing to dynamically adjust the strategy based on the actual target scale, thus struggling to balance computational efficiency with boundary enhancement gains. To this end, building upon context-learning segmentation, this paper introduces an adaptive SR strategy based on target scale estimation. This approach provides a reliable, boundary-enhanced initialization for subsequent mask optimization. Even with boundary enhancement via adaptive SR, a fundamental mismatch persists between pre-trained segmentation foundation models and high-precision geometric measurement tasks. These models are primarily optimized for cross-domain generalization [32,33] rather than the boundary precision and shape-consistency constraints required for metrology. Consequently, the output masks still frequently exhibit defects such as edge shifts, local omissions, holes and noise. These defects are visually subtle and do not impair overall target integrity during segmentation. However, even small boundary deviations are greatly amplified in geometric fitting, resulting in an error explosion. This is the core challenge of microscopic high-precision geometric measurement, and also the key problem to be solved in this paper. To address this, we propose a mask-optimization method tailored for microscopic regular-geometry measurement. First, initial masks are obtained via segmentation and adaptive SR. Subsequently, an iterative optimization strategy that fuses multi-dimensional pixel features (intensity, gradient, edges, etc.) with regular geometric priors is designed to complete missing regions, remove noise, and enhance boundary consistency. The refined masks satisfy stringent geometric consistency requirements, providing a reliable foundation for subsequent geometric fitting and high-precision parameter estimation. This strategy effectively bridges the gap between general segmentation outputs and the rigorous demands of high-precision geometric detection, maintaining exceptional robustness under challenging conditions such as uneven illumination, partial occlusion, fragmented boundaries, and blurring. To evaluate the efficacy of the proposed framework, a dedicated sphere–tube assembly dataset was curated for extensive experimental validation. The main contributions of this paper include the following:1.A two-stage mask optimization framework for high-precision measurement of microscopic regular-geometry targets is proposed. We establish a complete pipeline comprising adaptive SR enhanced initial mask generation and geometry prior-driven iterative mask optimization. This framework addresses the fundamental issue wherein masks output by general segmentation models cannot directly support high-precision geometric measurement, providing a high-robustness solution for microscopic metrology under low annotation cost.2.An iterative mask optimization method is proposed by fusing multi-dimensional pixel features (e.g., intensity, gradient, and edges) with regular geometric priors, which rectifies boundary defects in the initial masks through explicit geometric constraints, substantially enhancing the precision and stability of geometric parameter estimation.3.A dedicated dataset for microscopic regular geometries in sphere–tube assembly scenes is curated, covering a variety of typical microscopic degradation scenes. Through comparative and ablation experiments, the effectiveness, robustness, and engineering viability of the proposed mask optimization framework and its core modules were comprehensively validated. 1.A two-stage mask optimization framework for high-precision measurement of microscopic regular-geometry targets is proposed. We establish a complete pipeline comprising adaptive SR enhanced initial mask generation and geometry prior-driven iterative mask optimization. This framework addresses the fundamental issue wherein masks output by general segmentation models cannot directly support high-precision geometric measurement, providing a high-robustness solution for microscopic metrology under low annotation cost. A two-stage mask optimization framework for high-precision measurement of microscopic regular-geometry targets is proposed. We establish a complete pipeline comprising adaptive SR enhanced initial mask generation and geometry prior-driven iterative mask optimization. This framework addresses the fundamental issue wherein masks output by general segmentation models cannot directly support high-precision geometric measurement, providing a high-robustness solution for microscopic metrology under low annotation cost. 2.An iterative mask optimization method is proposed by fusing multi-dimensional pixel features (e.g., intensity, gradient, and edges) with regular geometric priors, which rectifies boundary defects in the initial masks through explicit geometric constraints, substantially enhancing the precision and stability of geometric parameter estimation. An iterative mask optimization method is proposed by fusing multi-dimensional pixel features (e.g., intensity, gradient, and edges) with regular geometric priors, which rectifies boundary defects in the initial masks through explicit geometric constraints, substantially enhancing the precision and stability of geometric parameter estimation. 3.A dedicated dataset for microscopic regular geometries in sphere–tube assembly scenes is curated, covering a variety of typical microscopic degradation scenes. Through comparative and ablation experiments, the effectiveness, robustness, and engineering viability of the proposed mask optimization framework and its core modules were comprehensively validated. A dedicated dataset for microscopic regular geometries in sphere–tube assembly scenes is curated, covering a variety of typical microscopic degradation scenes. Through comparative and ablation experiments, the effectiveness, robustness, and engineering viability of the proposed mask optimization framework and its core modules were comprehensively validated. 2. Methods Aiming at the high-precision measurement requirements for regular geometric targets in microscopic scenes, this paper proposes a two-stage mask generation and optimization framework. The framework is designed to generate high-quality target masks that stably support subsequent geometric fitting. The process is divided into two progressive core stages: Stage I involves initial mask generation based on segmentation, combined with adaptive SR based on target scale to enhance boundary representation for small targets. Stage II fuses multi-dimensional pixel features with regular geometric priors. It iteratively optimizes the masks while enforcing geometric-consistency constraints, ultimately outputting refined masks for high-precision geometric parameter estimation. 2.1. Stage I: Initial Mask Generation Based on SegGPT and Adaptive Super-Resolution Stage I aims to obtain a reliable initial mask under few annotation constraints. By employing target-scale adaptive SR, it enhances the boundary quality of small-scale targets, providing a stable initialization for the subsequent geometry-driven optimization. The complete workflow of Stage I, as shown in Figure 1, consists of three steps: (1) initial segmentation based on context learning; (2) target scale estimation and SR factor decision; and (3) refined mask generation after target-scale adaptive SR enhancement. 2.1.1. Segmentation Based on Context Learning To reduce pixel-level annotation reliance and improve transferability across regular geometric targets, we utilize the model SegGPT [27] for segmentation. Specifically, for each target class, a reference pair (ILR,MLR) is constructed, where ILR∈RH×W×3 is the reference image and MLR is the corresponding reference mask, which explicitly represents the target’s shape prior (e.g., spherical, elongated tubular, or dual-contour pore). During the inference stage, the reference pair and the target image It are concatenated according to 1:1, resized to the model’s required input scale (e.g., 448×448), and divided into patches with positional encoding. Global context features are extracted through a multi-layer pre-trained Transformer encoder [34]. To reduce complexity and enhance boundary response, multi-scale features are fused via a lightweight convolutional network in the decoding stage, generating a binary coarse mask:(1)M0^∈{0,1}H×W, Binarization and lightweight morphological opening are applied to suppress isolated noise, ensuring the mask provides robust coverage of the target in local regions. 2.1.2. Scale Estimation and Adaptive SR Factor Decision Target sizes vary greatly in microscopic scenes, and details depend heavily on resolution. Small-target segmentation thus often has unsmooth boundaries, missing parts, or noise. We estimate the target scale based on the initial mask M0^ and adaptively select an SR magnification factor to balance computational cost and detail enhancement. The Region of Interest (ROI) is derived from the minimum bounding box of M0^, expanded by δ pixels to mitigate boundary truncation errors. The ROI scale index S is calculated as:(2)S=w×hW×H, where W×H is the original image size and w×h is the ROI size. A scale ratio k=S/S* is defined by comparing S with a predefined target scale S*, which determines the SR factor r∈1,2,4,…. When k is low, a higher SR factor is applied to enhance boundaries and fine structures; otherwise, a lower factor (or no SR) is used to avoid redundant computation and the introduction of artifacts. This adaptive strategy effectively compensates for size differences between the input image and the target resolution at different ratios, ensuring consistent boundary representation quality for targets of different scales. 2.1.3. SR Enhancement and Refined Mask Generation After determining r, SR reconstruction based on the Local Implicit Image Function (LIIF) is performed on the ROI to obtain the enhanced image IR. Unlike fixed-kernel or fixed-ratio methods, LIIF learns a continuous implicit representation, mapping discrete low-resolution images to color/intensity functions in a continuous coordinate domain. This allows for arbitrary magnification (e.g., 2× to 12×), producing smoother grayscale transitions at edges. After obtaining IR, the same strategy is applied to IR to generate the refined mask M0. Due to the enhanced boundary gradients and improved local texture discriminability provided by SR, M0 typically outperforms M0^ in contour continuity and detail completeness, making it more suitable for subsequent geometry-constrained optimization. 2.2. Stage II: Iterative Mask Optimization with Multi-Dimensional Features and Geometric Priors Building upon M0, Stage II models mask optimization as a closed-loop iterative process. By progressively introducing regular geometric priors, the initial segmentation is subjected to stable and controllable consistency refinement. Unlike one-step post-processing, this stage treats the mask as a state variable that is dynamically adjusted until it converges to a result satisfying geometric constraints. The workflow is illustrated in Figure 2 and detailed in Algorithm 1. The pixel-level feature extractor Φ(I) is a fixed heuristic function with no learnable parameters. It generates a 3-channel feature map Fpixel∈RH×W×3 from the original input image:(3)Fpixel=Inorm,∇I,Eadap, where Inorm is the normalized grayscale image scaled to [0, 1], ∇I is the gradient magnitude map, and Eadap is the binary edge map. All channels share the same spatial dimension as I and remain constant throughout the optimization process to provide stable local observations. The geometric feature extractor ϕ(Mt) generates a dense single-channel Signed Distance Field (SDF) map Gt∈RH×W from the current mask Mt. In each iteration, we first extract all foreground pixel coordinates P={(xi,yi)|Mt(xi,yi)=1} and fit the target parametric geometric model Θ from P using least squares. For circular targets (microspheres, micropores), Θ=(xc,yc,r) representing center coordinates and radius; for linear targets (microtube axes), Θ=(a,b,c) representing the line equation ax+by+c=0. Then, we compute the SDF map via pixel-wise broadcasting:(4)Gt(x,y)=d((x,y),Θ), where d(·) is the signed distance from pixel (x,y) to the ideal geometric boundary defined by Θ, with negative values indicating pixels inside the target and positive values indicating pixels outside. Algorithm 1 Mask optimization based on multi-dimensional features and geometric priorsRequire: 1.Original image ILR∈RH×W×3 2.Initial mask M0 (from Stage I) 3.Maximum iterations Tmax 4.Convergence threshold εEnsure: Optimized final mask M* 1:Extract pixel-level features (intensity, gradient, edges) from ILR: 2: Fpixel=Φ(I) 3:Initialize state variables: 4: Set iteration counter t←0, initial mask state Mt←M0. 5:while t