WingSegment: A Computer Vision‐Based Hybrid Approach for Insect Wing Image Segmentation and 3D Printing

This article introduces WingSegment, a MATLAB app‐designed tool employing a hybrid approach of computer vision and graph theory for precise insect wing image segmentation. WingSegment detects cells, junctions, Pterostigma, and venation patterns, measuring geometric features and generating Voronoi patterns. The tool utilizes region‐growing, thinning, and Dijkstra's algorithms for boundary detection, junction identification, and vein path extraction. It provides histograms and box plots of geometric features, facilitating comprehensive wing analysis. WingSegment's efficiency is validated through comparisons with established tools and manual measurements, demonstrating accurate results. The tool further enables exporting detected boundaries as FreeCAD macro files for 3D modeling and printing, supporting finite element analysis. Beyond advancing insect wing morphology understanding, WingSegment holds broader implications for diverse planar structures, including leaves and geocells. This tool not only enhances automated geometric analysis and 3D model generation in insect wing studies but also contributes to the broader advancement of analysis, 3D printing, and modeling technologies across various planar structures.


Introduction
The study of insect wings presents a captivating challenge, as their intricate structures hold the key to unraveling the secrets of nature's most skilled aviators. [1]nderstanding the complex morphology of insect wings is not merely an academic pursuit in multiple scientific domains, such as biomechanics, animal behavior, physiology, and ecology, [2][3][4][5][6][7] but an inspiration for innovative technologies in the field of engineering.These include the development of robust load-bearing structures, [8][9][10] bioinspired joints, [11][12][13][14] insect-inspired hinges, [15] bioinspired wing, [16,17] insectinspired composites, [18,19] bioinspired attachment strategies, [20][21][22] and bioinspired grippers. [23]s our understanding of the wing structures deepens, manual analysis methods face challenges in accurately capturing the complex geometric features to characterize wing morphology [24,25] comprehensively.Furthermore, manual analysis of structure complexity requires precise consideration of geometrical parameters and proves time-consuming and prone to errors.To comprehensively explore the multifaceted nature of insect wings, automated methods powered by computer vision offer a promising avenue for precise and efficient analysis.In recent years, several techniques have emerged that facilitate convenient 3D scanning, [26] extraction of geometrical information, [27][28][29][30][31] and automated finite element modeling [29,32,33] of both insect bodies and wings.These advancements aim to enhance the precision, speed, and efficiency of analyzing insect wing morphology.
Network extraction tool (NET), [34] and network extraction from images (NEFI) [35] are tools designed to extract graphs from images of networks found in diverse domains.The kind of graph they extract is a representation of the underlying network structure within the images.They also encompass the aim of extracting networks (e.g., venation patterns) from insect wings.FijiWings [36] is a comprehensive tool that incorporates multiple integrated functions to accurately quantify cell number (trichome count) in the wings of Drosophila.DrawWing [37] is another tool for extracting vein junctions and drawing a fitted diagram of wing outlines and veins.DrawWing is specifically developed to be compatible with the wings of honeybees belonging to the genus Apis.However, the aforementioned tools primarily focus on extracting junction locations or venation network patterns, while there are other tools dedicated to automating the modeling of insect wings.
WingMesh [32] is one such tool previously developed by the authors, which aims explicitly at extracting cell boundaries from images of insect wings.It utilizes Distmesh2D, [38] a mesh generator in MATLAB, to generate a mesh on the insect wing domain.Embedded within WingMesh are methods that facilitate the replication and manipulation of a distinct file format known as Abaqus input file (i.e., INP files), utilized by Abaqus CAE.These methods enable the generation of orphan meshes. [39]rphan meshes lack the necessary user-friendly functionality to change the wing's geometry easily.It should be noted that generating a wing model using WingMesh is considerably slow.WingGram [29] was later developed as a solution to tackle these challenges, incorporating computer vision techniques to accurately detect wing cell boundaries from two-dimensional images.It introduces a novel approach for assigning corrugations to the wing model using a secondary image.Moreover, WingGram has the capability to extract various geometric features from wings, including cell area, length, width, and vein junction locations.Python scripting in Abaqus was utilized within WingGram to transfer wing geometry from an image to a journal file (JNL).This enables users to import wing geometry without relying on generated meshes, allowing them to leverage the advantages of Abaqus faster and more optimal meshing tools compared to the embedded Distmesh2D in WingMesh.
Although the aforementioned tools have been acknowledged for their intended purpose, there is room for improvement further to enhance the analysis and study of insect wings.These enhancements may include extending the detection capabilities beyond venation networks to encompass venation patterns, enhancing robustness and accessibility, and providing additional tools for statistical analysis of insect wings.These improvements would contribute to the advancement of research in this field.Recognizing the limitations of NEFI and NET in detecting curved patterns, along with the species-specific nature of FijiWings [36] and DrawWings, [37] and the fact that WingMesh [32] and WingGram [29] exclusively generate Abaqus-compatible models, which may be inaccessible and costly to students, this study aims to address these shortcomings by introducing WingSegment as a fast, accessible, and reliable solution.WingSegment adopts a hybrid approach that integrates computer vision and graph theory to extract cell boundaries, junction coordinates, and vein path coordinates accurately.The methodology encompasses various techniques, such as region-growing, [40][41][42] Dijkstra path finding, [43][44][45][46] thinning, [47] and line simplification, [48,49] which have been employed in this research.Additionally, we have utilized the FreeCAD macro (FC macro) file format [50,51] to generate automated FC models from insect images, further enhancing the accessibility and flexibility of the software in both modeling and 3D printing of biomimetic wings.
WingSegment additionally produces Voronoi patterns within the wing area by utilizing the centroids of the extracted cells.Voronoi patterns, commonly found in insect wings, hold significant importance in their study. [52]These patterns offer insights into the physical constraints governing the organization of biological tissues, reflecting the crucial role wings play in insect radiation and contributing to their remarkable diversity in shape, size, and color patterns.With their efficient and complete plane tiling, Voronoi patterns serve as convenient models for the intricate structures of insect wings.By examining Voronoi patterns, researchers can gain a valuable understanding of the physical and biological properties of wings, shedding light on insect evolution and adaptation.

Result
Our method successfully extracts the boundary of the wing outline, individual cells, and the intricate venation pattern.Additionally, it identifies the locations of junctions and generates a 3D-printable wing model.Moreover, our method could measure the wing's geometric properties, including cell area, length, and circularity distributions, which are visualized through heatmaps, boxplots, and histograms.Furthermore, we generate a Voronoi pattern based on the centroids of the segmented wing cells.The results obtained from Apis mellifera (Honeybee, Hymenoptera; forewings) are summarized and visually presented in Figure 1, which showcases several panels.Figure 1a displays the extracted cells, while Figure 1b illustrates the precise locations of the junctions.Figure 1c showcases the intricate venation patterns, with each vein color-coded according to its length, as indicated by the accompanying color bar.
Figure 1d provides insights into the distribution of cell areas, including a distribution plot (d.1), a corresponding histogram (d.2), and a boxplot (d.3).Similarly, panels (e) and (f ) present the distributions of cell lengths and circularity, respectively, with their respective histograms and boxplots.Figure 1g illustrates a physical model of the segmented wing created through 3D printing.The model was generated in FC using the sketch obtained from WingSegment's FC macro export tool.Printing was carried out using a Prusa MK3S printer with a 0.25 mm nozzle and Prusa Jet black polylactic acid (PLA) filament.The file containing the 3D-printable model is provided as Model S1, Supporting Information. [53]Finally, Figure 1h presents the Voronoi pattern generated based on the centroids of the extracted wing cells.

Validation
The validation of WingSegment was conducted to assess the accuracy and reliability of the method in segmenting insect wing images and extracting vital features.Table 1 and 2 present the results obtained during the validation process, demonstrating the performance of WingSegment.Figure 1h illustrates the numbered cells and five randomly selected veins represented by red dashed lines.The result regarding the length of all veins is stored as File S5, Supporting Information. [53]The subsequent analysis focused on comparing results between WingSegment and ImageJ.Table 1 provides the vein-related results, revealing an error rate of only 0.56%.This low error percentage underscores the precision of our method in detecting and measuring the intricate venation patterns present in insect wings.Moving on to cell analysis, Table 2 presents the obtained cell area measurements, circularity, and length from both WingSegment and ImageJ.The results indicate a high accuracy of cell area measurements, with negligible differences observed.The average error in cell circularity and length measurement is 3.70% and 1.59%, respectively.Moreover, manual counting was performed on a complex Crocothemis erythraea (Scarlet dragonfly, Odonata: Anisoptera; forewings) to assess the cell and junction counting functionality of WingSegment.Video S1 and S2, Supporting Information [53] illustrate the manual marking process for cells and junctions using our custom code (Code S1, Supporting Information), respectively.The coordinates of cells' centroids and junctions are stored as File S1-S4, Supporting Information. [53]emarkably, both methods yield the same count for cells (440) and junctions (816), highlighting the exceptional performance of WingSegment in accurately detecting cells and junctions.

Discussion
This study suggests a new hybrid method called WingSegment to segment insect wing images.The methodology employed in WingSegment combines region-growing and thinning algorithms for detecting cells and junctions, along with path-finding techniques for extracting venation patterns.This hybrid approach ensures efficient and accurate analysis of complex wing structures.It is important to emphasize that integrating the  1 and 2 aforementioned algorithms is crucial in this case, and considerable effort is required when employing these algorithms separately for the same task.In WingSegment, the embedded method extracts the locations of junctions by utilizing the thinning algorithm and the conditions introduced in the methodology.The pathfinding method then determines the path between the extracted junctions from the previous step.Additionally, the skeletonized image enables the algorithm to identify the available networks between junctions and uncover the true path, even if it is curved.This capability is not present in currently available tools like NET and NEFI.Performance evaluation was conducted on honeybee and Crocothemis erythraea (Scarlet dragonfly, Odonata: Anisoptera; hindwing) to assess the effectiveness of WingSegment (Figure 2).In addition, additional figures corresponding to the geometric features of a damselfly, a locust wing, and a Scarlet dragonfly forewing are presented in Figure S5-S8, Supporting Information. [53]This comprehensive evaluation allowed a thorough assessment of the software's performance across different insect species.
The results obtained from WingSegment demonstrate its effectiveness, as evidenced by the successful extraction of wing features with minimal errors in vein detection and cell measurement.The WingSegment validation involved comparing the results with those obtained from established tools such as ImageJ and manual measurements.The results obtained from WingSegment were in agreement with these reference methods, confirming the accuracy and reliability of our approach.It is important to note that both WingSegment and ImageJ employ image binarization as a preprocessing step.In WingSegment, we set the threshold value to 0.54, which provides optimal alignment with ImageJ results.Altering this threshold value would impact the outcome.

WingSegment versus WingGram
WingSegment, while visually resembling its counterpart WingGram, [29] incorporates notable distinctions and numerous enhancements.Both tools employ a similar approach to extract cell boundaries, but WingSegment addresses minor bugs from WingGram, resulting in enhanced reliability and speed.Figure 2a illustrates the extracted cells from a dragonfly wing, represented in blue color.While both WingGram and WingSegment provide measurements for cell area, length, and count, WingGram includes an additional feature that measures cell width by dividing the area by the length of cells.However, this approach was found to be imprecise and has been omitted from WingSegment.Instead, WingSegment incorporates cell circularity measurement, providing valuable information about cell shape. [27,28]   In this table, the units of area and length are px 2 and px, respectively.
circularity.This type of figure enables the examination of the relationship between cell size and its spatial positioning.The histogram in Panel 2 provides valuable information on how cells are distributed across different categories of area, length, and circularity.This allows for investigating the predominant size or shape of the cells within the population.Lastly, the boxplot in Panel 3 presents important statistical details such as the minimum, maximum, upper quartile, lower quartile, and median values of cell area, length, and circularity.These visualizations collectively provide insights into the characteristics and distribution of cells within the wing sample.Furthermore, WingSegment offers additional features not present in WingGram.It provides distance measurements of cells centroids from the wing margins, allowing for a more comprehensive analysis of the wing structure.Additionally, WingSegment includes automatic detection of the Pterostigma, a specialized region within the wing.In terms of junctions, both tools are capable of locating and quantifying junctions.However, WingSegment surpasses WingGram by identifying the ends of unblocked veins as junctions, which provides a more accurate representation of the wing's connectivity.Notably, both WingGram and WingSegment can detect cell centroids on insect wings.However, WingSegment stands out with its built-in feature for generating a Voronoi pattern based on the extracted centroids.Figure 2b illustrates the Voronoi pattern generated by WingSegment on a dragonfly wing.This Voronoi pattern is a significant aspect of WingSegment, as it offers insights into the arrangement and distribution of cells on the wing surface. [27,54])

WingSegment versus WingMesh
WingMesh is another software developed for mesh generation on insect wing geometries. [32]It was created by integrating image processing with Distmesh2D, [38] a well-known mesh generator in MATLAB.In WingMesh, the wing's geometry is extracted using image analysis, and Distmesh2D is then employed to generate a mesh on the extracted geometry.The output mesh in WingMesh is based on INP files compatible with Abaqus CAE.While WingMesh represents an advancement in automated mesh generation for insect wing geometries, it is noteworthy that it generates orphan meshes in Abaqus.Consequently, manipulating the geometry on the finite element (FE) models generated by WingMesh is impossible.Moreover, WingMesh was slow, particularly demonstrating reduced functionality on wings with complex geometries, such as dragonfly wings.Table 3 provides a side-by-side comparison illustrating the key differences between WingGram, WingMesh, and WingSegment.

Venation Pattern Recognition
One distinguishing feature of WingSegment, which was not incorporated in WingGram, is its ability to extract the network pattern of insect wings and accurately determine the paths between junctions.While tools like NEFI [35] and NET [34] excel in extracting network patterns from various structures such as leaves and spider webs, WingSegment offers a unique advantage in capturing the intricate details of wing venation.NEFI and NET primarily focus on network extraction, representing connections between junctions with straight lines, which is suitable for their intended purposes as network analysis tools.However, WingSegment goes beyond network extraction by precisely capturing the curved paths between junctions, allowing for a more comprehensive representation of the intricate venation pattern and providing valuable insights into the wing's structural characteristics.It is important to highlight the specific focus and strengths of NEFI and NET in network analysis while emphasizing that WingSegment complements these tools by offering a specialized feature for path extraction.Figure 2a demonstrates the successful extraction of the intricate venation pattern from a complex dragonfly wing represented by red color.Notably, when dealing with a dragonfly wing featuring a Pterostigma, Figure 2a.2 showcases the effectiveness of the distance transform in detecting veins around the Pterostigma.In contrast, Figure 2a.3 illustrates the detection of a vein within the Pterostigma when this option is not utilized.This function enhances vein detection and leads to more accurate junction detection.Furthermore, Figure 2c provides insight into the distribution of veins based on their length.
Additionally, this article presents two approaches for detecting venation patterns: Sequential vein detection (SVD) (Video S5, Supporting Information) and parallel vein detection (PVD) (Video S4, Supporting Information). [53]While PVD offers faster processing due to its parallel nature, it is essential to note that accurately extracting venation patterns is a highly delicate process.Initially, we developed SVD and subsequently enhanced its speed.Following that, we developed PVD.Our observations revealed that while both methods generally detect all veins within the wing, there are instances where one of the methods may miss some veins.Consequently, we incorporated both methods into WingSegment to ensure comprehensive vein detection.

FreeCAD Macro Export: Seamless Transfer of the Wing Geometry to FreeCAD
In terms of finite element modeling (FEM), WingGram surpasses WingSegment with its array of tools for modeling insect wings.WingGram offers functionalities such as marking discontinuities to exclude specific areas from the model and an innovative tool for corrugation assignment.Furthermore, WingGram can export the final model as an Abaqus JNL file.In contrast, WingSegment generates a FreeCAD macro file from extracted cell boundaries, allowing for the import of a wing cell sketch into FreeCAD.However, it is essential to consider that Abaqus is not open access, limiting accessibility for many users.In contrast, the FC macro exporting tool in WingSegment, although lacking corrugation assignment capabilities, generates a file compatible with FreeCAD-an open-source and accessible FEM software package.This aspect enhances the usability and practicality of WingSegment, particularly for users without access to specialized software like Abaqus.Furthermore, this seamless integration empowers users to easily create FE or 3D printable models within the FreeCAD environment.The practical utility of WingSegment is exemplified in Figure 2e, showcasing a successful application of 3D printing.More examples of dragonfly, damselfly, and locust 3D printed wings with complex geometries are also available in Figure S4, Supporting Information. [53]he physical wing was produced using a Prusa MK3S 3D printer, employing a 0.25 mm nozzle size.Prusament PLA Jet black filament was used to fabricate the wing in Figure 2e, and Prusament PLA Galaxy Silver was used in producing wings in Figure S4, Supporting Information.The nozzle temperature was set at a constant value of 225 °C, while the bed temperature was maintained at 65 °C.To ensure precise replication of all features, the wing model was scaled %4.5 times its original size, resulting in a 3D-printed wing that accurately represents the morphology of the original insect wing.The 3D printable model of the wing is stored as Model S2, Supporting Information. [53]t is essential to highlight that, like WingGram, WingSegment extracts all points along the boundaries of cells, which can lead to many unnecessary points.These plenty of points significantly increase the volume of the macro file, consequently increasing the runtime during the importing process in FreeCAD.Therefore, it is crucial to recognize the importance of employing line simplification techniques before generating the macro file.This is exemplified in Figure 2d, where the density of points before and after line simplification is showcased in Figure 2d.1,d.2, respectively.

Robustness of WingSegment
WingSegment demonstrates exceptional versatility in segmenting wings with both simple and complex geometries.This capability is exemplified through the segmentation of a straightforward honeybee wing (Figure 1) and the intricate hind wing of a Scarlet dragonfly (Figure 2).Furthermore, to validate the robustness of cell and junction extraction, we utilized a Scarlet dragonfly forewing, showcasing the software's performance (Figure S1, Supporting Information). [53]We have also presented additional 3D printed models of wings with a high number of cells and geometric complexity in Figure S4, Supporting Information. [53]These wings are from the damselfly, locust, and Scarlet dragonfly forewings.
In practice, WingSegment adeptly handles various wing complexities but is more sensitive to image quality.While very high-resolution images may impact runtime, excessively lowresolution images can affect software performance.In our assessments, images with a resolution of 300 dpi were found optimal.
It is important to note that WingSegment excels when the wing image is clear.The software successfully extracts features, but the user must ensure that the image quality meets certain criteria.Images with thin veins, faded details, or noise may not yield optimal results.WingSegment distinguishes between black and white pixels, which is crucial in cell and vein detection tasks.However, this feature has limitations; for instance, black pixels are considered veins in the region-growing method.Therefore, WingSegment is particularly well-suited for wings with transparent membranes and dark veins.Challenges arise when dealing with transparent veins, necessitating user intervention to enhance image contrast.
It's worth mentioning that WingSegment may not be suitable for wings with dark colors or black spots due to its pixel differentiation method.Nonetheless, any wing image can be preprocessed to meet the software's requirements.To address these limitations, we are actively developing filters and incorporating deep learning and machine learning methodologies to enhance software flexibility, minimizing the need for manual editing or pre-processing.Our ongoing efforts include integrating venation sections and corrugations into final 3D models generated with WingSegment.

Applications of WingSegment
WingSegment may play a pivotal role in advancing the study of insect wings by offering automated solutions, significantly reducing the effort required for analyzing mass samples.The software's ability to rely solely on wing images without additional specialized information enhances its accessibility and applicability.WingSegment may contribute substantially to understanding the asymmetry of insect wings, extracting various geometric features from images. [55]Moreover, it will facilitate the design and development of bio-inspired and biomimetic wings by generating intricate 3D models. [16,56]The tool also may aid in studying the functional morphology of wing venation patterns, cells, and junctions through automated extraction of these elements from wing images.[59][60] Notably, WingSegment's versatility extends beyond insect wings, as it can extract features from 2D images of other cellular structures such as leaves, skins, and foam-like formations [61] like that illustrated in Figure 3. Additionally, as depicted in Figure 3b,c, it can contribute to the investigation of soil and the development of clay cracks. [62]This broadens its impact on diverse fields, including developing and designing cellular thin films, geocells, and modeling and analyzing leaves and plant species determination. [63]We envision WingSegment as an invaluable tool in entomology and the comprehensive study of various planar biological structures.WingSegment showcases advancements in designing and developing 3D modeling and printing of wings and exhibits their potential applicability to a wide array of planar structures.This can contribute to advancing 3D printing technologies. [64]

Conclusion
In conclusion, this article introduces WingSegment, a novel computer vision-based hybrid method for insect wing segmentation, venation extraction, and FreeCAD modeling.By leveraging the advantages of computer vision, graph theory, and image analysis, WingSegment offers a powerful solution for studying and analyzing complex insect wings.The proposed method demonstrates remarkable accuracy in extracting cell boundaries, precisely detecting venations, and capturing junctions.Additionally, WingSegment provides various geometric statistical features, such as cell area, length, and circularity.Moreover, the integration of a user-friendly graphical user interface (GUI) and the generation of FreeCAD macro files enhance the accessibility and usability of the software.
The experimental results, showcasing the application of WingSegment on a honeybee wing, highlight the successful extraction of cells and veins and the subsequent creation of a detailed 3D model.Validation using ImageJ software further confirms the reliability and effectiveness of WingSegment.Furthermore, WingSegment and the previously developed tools, WingGram and WingMesh, are comparatively discussed (Table 3).While WingSegment surpasses WingGram in venation pattern extraction and circularity measurement, WingGram retains its own advantages for FE modeling of insect wings.Notably, the accessibility and affordability of WingSegment, which employs FreeCAD as a platform, make it an attractive option for students and researchers.Our development simplifies the study of insect wings and opens avenues for future developments.With its versatility, the presented software is exemplified by exploring a more complex dragonfly wing, further demonstrating the method's robustness-intricate insect wing structures, empowering researchers and students with valuable study tools.

Experimental Section
This study proposes a hybrid approach, WingSegment, for segmenting insect wings by integrating various algorithms in image analysis and graph theory.The algorithm is accompanied by a user-friendly graphical interface designed in MATLAB App-designer.WingSegment can detect cells, junctions, and vein paths in the insect wing by taking an image of the wing as input.A region-growing algorithm is incorporated into WingSegment to detect the boundary of cells and the wing.The thinning algorithm in image processing is utilized to locate the junctions.A combination of Dijkstra's and thinning algorithms is employed to detect the venation patterns in the wing.In addition, a distance transform function is incorporated to identify the presence of the Pterostigma in the wing.Lastly, a line simplification method compresses the detected cells and venation patterns.
Image Preparation: A high-quality image is required since we intend to present this method to segment the insect wing image in detail.A camera, scanner, or microscope can be used for taking images.Figure 4a is a sample image of a honeybee taken by a high-resolution scanner (Epson Perfection V850 Pro).Since the method turns the image into a binary image with only black and white pixels with a thresholding of 0.54, the user should ensure that all veins and membranes remain apparent after binarising the image.Figure 4b represents an example of an appropriate image for use in WingSegment.Code S2, Supporting Information, [53] is designed for importing the image and performing the binarization process.
]65] Figure 4d provides an exaggerated pixel view of the domain in Figure 4c and illustrates how the method finds a region from a starting point.Five sets are defined to describe the method, including visited white pixels, unvisited white pixels, visited black pixels, unvisited black pixels, and current pixels.The algorithm involves five steps, starting with marking all white pixels as unvisited.Then, a random initial white pixel within a cell is selected as the current pixel, marked as visited and removed from the unvisited white pixels set.Then, all neighbors' unvisited pixels around the current pixels are checked.If they are white, they are marked as visited white pixels, replaced with the current pixel, and removed from the unvisited white pixels.If they are black pixels, they are marked as visited black pixels and removed from the unvisited black pixels.The algorithm continues while the unvisited white pixels set is not empty, and when it becomes empty, the boundary of that domain is extracted.Video S3, Supporting Information, illustrates this procedure on a honeybee wing.In ref. [53], Code S3, Supporting Information, depicts the function for implementing the region-growing method.
Cell Domain Extraction: Generating Voronoi Pattern: Incorporating a method for extracting the cell boundaries into WingSegment facilitates the calculation of cell centroids.This has been integrated into the WingSegment algorithm, allowing for generating a Voronoi pattern by   1), WingSegment determines the circularity of each cell.The circularity ranges between 0 and 1, where 1 indicates the highest level of circularity, representing how closely a shape resembles a perfect circle. [66]The circularity is quantified using Equation (1).
where, the area represents the measured area of the shape, and the perimeter represents the measured perimeter of the shape.In ref. [53], Code S4, Supporting Information, represents the function responsible for quantifying all geometric features through the utilization of the region-growing method.
Cell Domain Extraction: Generating FC Macro File of Detected Boundaries: In FreeCAD, a powerful 3D modeling software, the term "FC macro" refers to a macro script written in the FreeCAD scripting language. [50,51]FreeCAD is an open-source parametric 3D modeling software that allows users to create and modify 3D designs using a graphical interface.However, it also provides a scripting interface allowing users to automate tasks and create custom Python tools.FC macro in FreeCAD is a Python script specifically written to extend the functionality of FreeCAD.Users can create their macros to perform repetitive tasks, automate design processes, or add new features to the software.These macros can be executed within the FreeCAD environment, providing additional functionality beyond what is available through the graphical interface alone.
In addition to automatically detecting cells from the insect wing image, WingSegment incorporates a valuable tool that allows users to export the detected boundaries in an FC macro file format.This feature enables easy transfer of the wing geometry, specifically the boundaries of the detected cells, into FreeCAD.By exporting the boundaries as an FC macro file, users can conveniently import the wing geometry into FreeCAD and perform various operations such as extrusion, generating finite element (FE) models, or creating 3D printable models.This functionality enhances the usability of WingSegment, providing users with a seamless pathway to further analyze and utilize the detected cell boundaries in their design and simulation processes.In ref. [53], Code S8, Supporting Information, corresponds to the code developed for generating the FCMacro file.Video S7, Supporting Information, shows how the FC Macro files generated by WingSegment can be imported in FreeCAD. [53]unction Detection: In insect wings, a junction refers to a point where two or more wing veins meet or intersect.The method for detecting wing junctions involves a series of steps.First, the width of all veins is reduced to one pixel using the Zhang-Suen thinning algorithm. [47]This process is called skeletonization, commonly used in image processing to reduce an object to its core components.In this case, skeletonization is used to reduce the width of the veins to a single pixel, making it easier to detect intersections. [29,35,37]The skeletonized image is shown in Figure 4f, consisting of a network of thin lines representing the veins in the wing.To detect the junctions, the skeletonized image is examined for black pixels that are surrounded by three or four black pixels (Figure 4g), as shown in the conditions illustrated in Figure 4i.1-i.18.These conditions take into account the position of the black pixels relative to their neighbors, and ensure that they meet specific geometric criteria. [29,35]Any black pixel that meets these conditions is considered a junction.The junctions are then marked and identified in the image, as shown in Figure 4h.By locating the junctions in this way, it is possible to accurately map the venation patterns in the wing and obtain a detailed understanding of its structure.Code S5, Supporting Information, represents the function developed for detecting junctions in the Supporting Information. [53]ein Path Extraction: We use path-finding, also known as the pathing method, to extract venation patterns here.This technique involves using a computer program to draw the most direct path between two points and is a more useful version of solving mazes.Path-finding methods rely heavily on Dijkstra's algorithm, [67] which is used to find the shortest possible route on a graph with weights assigned to its edges.We have adapted this algorithm to find every path between the junctions in a wing using the following approaches.
Vein Path Extraction: Sequential Vein Detection (SVD): This approach involves defining three sets: initial, ending, and front pixels.Each pixel in a set has a so-called parent-child relationship, where the parent indicates the origin of the child from the previous iteration.To initiate the process, one of the identified junctions is designated as the initial pixel, serving as the starting pixel for a generation (Figure 4l, Pixel 1).The initial pixel designates the surrounding pixels as front pixels.Since all veins in the skeletonized image are represented as white pixels, the method transfers these white pixels from the front set to the set of detected pixels.The initial pixel is considered the parent of all pixels detected afterward.Subsequently, the initial pixels are replaced by newly detected pixels, and the same procedure is repeated for each newly generated initial pixel.This process continues until a new junction is among the front pixels, indicating the detection of a vein's ending pixel.In such cases, the pixel that detects the junction and its parent begin to trace its way back to the starting pixel of its generation, with each parent returning to its own parent.This iterative process continues until they reach the initial pixel, resulting in the respective detection of all pixels associated with that vein.This procedure is then repeated for each junction, one at a time, until all veins are detected.Figure 4l visually illustrates this entire process.Furthermore, Video S5, Supporting Information, demonstrates the detection of veins on honeybee wings using the SVD method.The code designed for implementing this method is provided and explained in detail under Code S7, Supporting Information. [53]ein Path Extraction: PVD: The parallel method considers all junctions simultaneously as initial pixels and begins finding paths concurrently.Consequently, as depicted in Figure 4k, the front pixels converge at the center of the connecting vein where two junctions are connected.Video S4, Supporting Information, showcases the application of the PVD method for detecting veins on honeybee wings.The code created for this approach is presented and described under Code S6, Supporting Information. [53]terostigma Detection: The Pterostigma is a feature commonly found in the wings of certain insect orders including Odonata, [1,68,69] Hymenoptera, [70] Orthoptera, [71] and Hemiptera.[72] However, the size, shape, and coloration of Pterostigma can vary among different species.Image processing operations are applied to detect the Pterostigma in the wing.1) Distance transform. [73] The first step invoes calculating the distance transform of the wing image.The distance transform assigns a value to each pixel in the image, representing its distance to the nearest object.The Pterostigma, being a concentrated region within the wing, causes the distance transform to assign the highest value at its central location.2) Normalization.The resulting distance transform image is then normalized in a range of 0-1 using the max-min normalization method.This normalization step ensures that the maximum distance has a value of 1, facilitating subsequent thresholding.3) Thresholding.We have observed that a threshold of 0.7 applies to the normalized distance transform image. Pixes with values above this threshold are set to 1, while those below or equal to the threshold are set to 0. This thresholding operation helped isolate regions in the image that are likely to contain the Pterostigma.4) Overlaying.image is added to the image to the detected Pterostigma visually.This overlaying helped the location of the Pterostigma by visually merging the threshold regions with the original wing image.
Following these steps, the code successfully detects and localizes Pterostigma in the wing image.
Line Simplification: Ramer-Douglas-Peucker algorithm, also known as the Douglas-Peucker algorithm and end-point fit algorithm, simplifies a curve composed of line segments. [48,49]Its purpose is to

Figure 1 .
Figure 1.Visualization of the results obtained using WingSegment on an Apis mellifera (Honeybee, Hymenoptera; forewings).a) Identified cells, b) detected junctions, c) distribution of vein lengths, d-f ) distribution of cell areas, lengths, and circularity.Each Figure panel consists of three subpanels: Panel 1 displays the heatmap, Panel 2 shows the corresponding histogram, and Panel 3 presents the boxplot.g) The 3D-printed physical wing model from the 3D model was generated using WingSegment.h) Labeled cells and veins corresponding with the results ofTable 1 and 2 i) Generated Voronoi pattern.
Figure 2f-h depicts the distribution of cell area, length, and circularity using various visual formats, including heatmap (Panel 1), histogram (Panel 2), and boxplot (Panel 3).Panel 1 provides an overview of the distribution of cells and offers insights into their location based on area, length, or

Figure 2 .
Figure 2. Evaluation of WingSegment performance on a Crocothemis erythraea (Scarlet dragonfly, Odonata: Anisoptera; hindwings).a) Extraction of cells, junctions, and venation patterns.Panels 2 and 3 demonstrate the impact of using and not using the distance transform function in Pterostigma detection, respectively.b) Generated Voronoi pattern based on extracted cell centroids.c) Visualization of vein length distribution.Panel 1 displays the heatmap, and panel 2 presents the histogram.d) Illustration of line simplification technique.Panels 1 and 2 depict point density before and after applying the line simplification method.e) Three-dimensional printed dragonfly wing.f-h) Analysis of cell area, length, and circularity, respectively.Panels 1, 2, and 3 show the heatmap, histogram, and boxplot.

Figure 3 .
Figure 3. Illustration of WingSegment performance beyond insect wings.a) Leaf vein pattern.b,c) Soil crack pattern.

Figure 4 .
Figure 4. Illustration of the implemented methodology in WingSegment.a) Image of a honeybee wing, b) binary representation of the wing image,c) visualization of a single cell, d) exaggerated pixel view of a single cell, e) representation of a pixel and its surrounding pixels, f ) Skeletonized image of the wing, g) criteria for identifying junction locations, h) detected junctions, i.1-i.18)pixel-level depiction of the formula shown in panel, g,j) complemented skeletonized image, k) sequential vein detection (SVD) method representation, l) Parallel vein detection (PVD) method representation, m) detected veins in the wing.

Table 1 .
Comparison of measured vein lengths using WingSegment and ImageJ, along with the computed average error.

Table 2 .
Comparison of measured cell area, circularity, and length using WingSegment and ImageJ, alongside the computed error.