Computer vision-guided rapid and precise automated cranial microsurgeries in mice
Automatizovane kranijalne mikrohirurške intervencije kod miševa vođene kompjuterskom vizijom, brze i precizne
Navabi ZS, Peters R, Gulner B, Cherkkil A, Ko E, Dadashi F, Brien JO, Feldkamp M, Kodandaramaiah SB.
2025 · Science advances · CC BY-NC
Prevod na srpski je mašinski (Claude) i prikazan je radi čitljivosti; original je merodavan.
Abstract A common procedure that allows interfacing with the brain is cranial microsurgery, wherein small to large craniotomies are performed on the overlying skull for insertion of neural interfaces or implantation of optically clear windows for long-term cranial observation. Performing craniotomies requires skill, time, and precision to avoid damaging the brain and dura. Here, we present a computer vision–guided craniotomy robot (CV-Craniobot) that uses machine learning to accurately estimate the dorsal skull anatomy from optical coherence tomography images. Instantaneous information of skull morphology is used by a robotic mill to rapidly and precisely remove the skull from a desired craniotomy location. We show that the CV-Craniobot can perform small (2- to 4-millimeter diameter) craniotomies with near 100% success rates within 2 minutes and large craniotomies encompassing most of the dorsal cortex in less than 10 minutes. Thus, the CV-Craniobot enables rapid and precise craniotomies, reducing surgery time compared to human practitioners and eliminating the need for long training.
A machine vision–guided robot performs automated craniotomies in mice, with performance faster and more precise than humans.
INTRODUCTION Much of neuroscience that uses rodent models such as mice and rats require access to the brain by removing the overlying skull to insert neural probes for recording, optical imaging, and perturbation of neural activity. In recent years, the need to perform simultaneous multi-area recordings has led neuroscientists to increasingly remove large sections of the dorsal skull to allow optical imaging and access to penetrating neural probes for targeting deep brain regions. The advent of ultra-widefield imaging systems such as the two-photon mesoscopes ( 1 ) has prompted research groups to develop surgical approaches to perform very large craniotomies across the dorsal cortex ( 2 – 5 ) and the cerebellar cortex ( 6 ). Once removed, the skull is typically replaced with either curved glass windows ( 2 ) or three-dimensionally (3D) printed polymer skulls that conform to the morphology of the removed skull ( 7 – 12 ). Such approaches have also been adapted for implanting large cranial windows with access ports to insert multiple neural recording devices ( 5 ). While these approaches provide unprecedented capability and flexibility to access and dissect neural function, the challenging craniotomy procedures needed to implant such large cranial windows have precluded widespread adoption. Even more widely adopted cranial window implantation techniques for imaging smaller fields of view ( 13 , 14 ) require practice and have variable learning curves depending on individual surgeons. Thus, standardized automation of skull removal would be a highly useful tool for neuroscience research. An accurate estimate of the skull thickness is necessary for automated bone removal. Various approaches have addressed this issue; some use destructive methods to find the optimal milling depth automatically. These include systems that use change in the electrical impedance sensed by the tip of the driller to specify the type of tissue in contact with the drill tip ( 15 ), systems that use mechanical impedance of the tissue under the driller tip ( 16 ), or drills that use vibration and sound ( 17 ) to detect reaching the brain during milling. However, these approaches are prone to false positives when hitting blood vessels in the bone ( 15 ). Furthermore, they are difficult to implement on intricate rodent skulls ( 16 ). Thus, previous approaches have relied on substantial user inputs during robotic milling and require repeated runs to shave off enough material from the skull surface to break off the bone ( 18 ). To date, there have not been any approaches that do not require human intervention during automated craniotomies. Here, we describe the CV-Craniobot, a computer vision–guided craniotomy robot that combines nondestructive imaging of live mouse skulls with robotic milling to fully automate craniotomies in mice. The CV-Craniobot uses an optical coherence tomography (OCT) scanner to image through the skull. Machine learning models are trained to accurately reconstruct the skull’s dorsal and ventral surface from the OCT images. The machine learning model’s reconstructions of the dorsal and ventral surface of the skull can be used to perform rapid and precise robotic removal of bone, with a near 100% success rate at a fraction of the time taken to perform manual craniotomies. RESULTS CV-Craniobot operation and architecture The operation of the CV-Craniobot is shown in Fig. 1A . First, the user fixes the mouse skull in a custom-made stereotax integrated within the robot; then, it is scanned using an OCT scanner. An OCT system uses low-coherence interferometry to image through the different layers of scattering material ( 19 , 20 ). Here, we use an OCT system with a center wavelength of 1310 nm and a bandwidth of 60 nm. This enables us to image nondestructively through the bone tissue and obtain a near-instantaneous 3D reconstruction of both the dorsal and ventral skull surfaces. To estimate the pixels containing the bone tissue, CV-Craniobot uses a machine learning model (U-Net), which is trained to segment the bone tissue in the B-scans ( X - Z cross sections of the 3D OCT scan). The software then uses the segmented images to identify the top edge and bottom edges of the skull tissue. Using the extracted edges on all B-scans, the skull’s top and bottom 3D boundaries, the dorsal and ventral surfaces of the mouse skull, are reconstructed. Once the surfaces are estimated, this information and the user input milling path guide a robotic drill to automatically perform bone milling using the estimated dorsal or ventral skull surface as a reference. Fig. 1. CV-Craniobot working principle and hardware architecture. ( A ) Workflow: The mouse skull is imaged using an OCT scanner; an machine learning (ML) model estimates the dorsal and ventral skull surfaces from the B-scans of the OCT image; a robotic mill executes automated bone removal along the computed craniotomy path. ( B ) Computer-aided design rendering of the CV-Craniobot hardware. ( C ) Photograph of the CV-Craniobot with core elements highlighted. To execute this operation principle, we established the CV-Craniobot shown in Fig. 1B . The CV-Craniobot consists of three major components: First, a central linear stage on which a custom stereotax is installed. Second, the OCT scanning bay, where the OCT scanner is mounted on an adjustable Z -stage, allows the OCT scanner to focus properly on the mouse skull. Third, the milling bay, which is equipped with an electrical dental drill mounted on a Z -axis linear stage, adjusts the height of the driller with respect to the skull, while the central linear stage controls the lateral position of the driller with respect to the skull. The linear stage transports the mouse affixed to the stereotax between an OCT scanning bay and the craniotomy milling bay. OCT imaging and ML estimation of the skull surface OCT scans are known to be prone to different types of distortions ( 21 – 23 ), which need to be corrected before they can be used for accurately estimating skull morphology. These distortions include nonlinear scanning distortions that can occur in the axial ( Z axes) direction, non-telecentric distortions that cause images to be warped laterally ( XY plane), and optical distortions that cause distortion in the axial direction when imaging through materials with different refractive index. Imaging a flat glass coverslip using the OCT scanner revealed negligible nonlinear axial scanning distortion (fig. S1). We imaged a modeling clay sample imprinted with a mesh pattern with an approximate spacing of 125 μm to determine lateral image warping. Reconstruction of the raw OCT images revealed both tangential and radial distortions in the lateral direction ( XY plane; Fig. 2B , left). Image distortion in both X and Y axes increased in the lateral areas of the OCT’s field of view (FOV), resulting in an average of 13-pixel distortion in the most lateral X -lines and an average of 8-pixel distortion in the Y -lines. We measured the distortion as the root mean square error (RMSE) between the detected lines in each cross section and the reference (undistorted) line corresponding to the detected line (see Materials and Methods). Our image processing software uses the division model for radial distortion and the Brown-Conrady model for tangential distortion to represent and correct for distortions in the XY plane (see Materials and Methods). After correction, images had a measured distortion of around 1 pixel in both directions ( Fig. 2, C and D ). Images of the mesh after distortion correction are shown in Fig. 2B (right). Fig. 2. Rapid and accurate estimation of skull morphology from OCT image scan. ( A ) Steps involved in estimating skull morphology from OCT image scan ( B ) Reconstructed top view image of a modeling clay sample imprinted with mesh pattern before and after non-telecentric distortion correction. ( C ) Root mean square error (RMSE) between each Y -line and the reference line at that position for both raw and corrected scans. ( D ) RMSE between the raw and corrected X -lines. ( E ) U-Net model training [(E), i]. Representative average B-scan image from OCT scan of a mouse skull. [(E), ii] B-scan image with manually annotated dorsal and ventral skull surfaces. [(E), iii] Trained U-Net model estimate of the dorsal and ventral surfaces. ( F ) Tversky loss plot for training and validation. ( G ) Measured refractive index ( n = 8 mice) (see Supplementary Text S1). ( H ) Top: Reconstructed top view of the mouse’s dorsal skull from OCT scan. Bottom: B-scan cross section with estimated dorsal and ventral surfaces by U-Net model and the refractive index-corrected ventral surface. ( I ) A pseudo-color map of the skull thickness of the specimen is shown in (H). ( J ) Comparison between the micro–computed tomography (μCT) scan measurement (left) and the estimated thickness using OCT scans in the same area. Once the images were corrected for non-telecentric distortions, we proceeded to identify the dorsal and ventral skull surfaces from the cross-sectional images acquired from the OCT. The low-coherence infrared light passing through the dorsal skull surface from air creates a clear contrast in the cross-sectional image, whereas the ventral surface boundary with the brain tissue underneath was less discernible ( Fig. 2E i). To accurately reconstruct the two surfaces, we trained a U-Net model ( 24 ), a convolutional neural network model widely used for biomedical image segmentation. We trained the model using 300 B-scans of live mouse skulls, in which the skull bone area was manually annotated ( Fig. 2E ii) (see Materials and Methods for details). Our results demonstrated good generalization to out-of-fold samples, with training and validation accuracies of 0.995 ± 0.001 and 0.994 ± 0.003 ( Fig. 2G ) and intersection over union (IOU) of 0.908 ± 0.021 and 0.886 ± 0.043, respectively (fig. S2). The skull’s dorsal and ventral surfaces were then reconstructed using the top and bottom boundaries of all segmented B-scans using image processing methods ( Fig. 2E iii). An OCT system determines scattering depth by measuring the difference in travel time between light returning from the sample and the reference arm. Because of the slower speed of light in bone compared to air, the light takes longer to return from the ventral surface of the skull, causing the ventral surface to appear deeper in OCT images than its true location ( 25 , 26 ). To correct this, we measured the refractive index of the mouse skull bone tissue across multiple animals and areas of the skull ( Fig. 2F ; see Supplementary Text S1 and fig. S3). The image processing software then corrects the ventral surface estimated by the U-Net model for the refractive index distortion using a nominal refractive index value of 1.6 ( Fig. 2G ). Figure 2I shows a pseudo-color image of the estimated thickness of the skull from the OCT image shown in Fig. 2H . Consistent with previous work ( 26 ), we found that the average skull thickness in the parietal bone region was mostly even, with smooth surfaces defining both the dorsal and ventral skull surfaces, resulting in thickness ranging from 100 to 650 μm ( 7 ). Further, the thickness of the skull increased in the areas immediately surrounding the bone sutures, with the highest thickness measured at the midline suture. The skull thickness images allowed distinguishing the bregma and lambda landmarks as well as the bone sutures. Pseudo-color images of a skull generated first with the OCT scanner, followed by micro–computed tomography (μCT) images, are shown in Fig. 2J , showing agreement in the estimation of skull thickness across these modalities. Image-guided milling using dorsal skull surface as reference To evaluate whether we could use the estimated dorsal surfaces for robotic milling, the CV-Craniobot was used to engrave the University of Minnesota logo on the eggshells with increasing engraving depth ( Fig. 3A and movie S1). Eggshells provided a reference surface mimicking the curved surface of the dorsal skull while providing an optically opaque and rigid surface. The robotic milling provided sufficient machining resolution to visually discriminate differences in milling depth, indicating that the surface reconstructed from the OCT images was accurate and suitable for robotic milling. Post-milling scans of the engraved logos were acquired both with a μCT scanner and the OCT scanner to evaluate the milling depth after the procedure ( Fig. 3, B and C ). Qualitatively, uniform milling depth was observed along the entire length of the milling path. The average depth of milling along the whole milled length was calculated. A clear linear relationship was observed between the milling depth and the commanded depth [coefficient of determination ( R 2 ) = 0.91] ( Fig. 3D ). In general, the milling depth was slightly lesser than the commanded milling depth, possibly due to a combination of system calibration offset and incomplete removal of material along the periphery of the milling tool. Fig. 3. Robotic milling using the estimated dorsal surface as reference. ( A ) Photograph of the surface of an eggshell engraved with the University of Minnesota logo using the CV-Craniobot. Insets 1 and 2 show close-up images of the engravings milled to depths of milling operations with depths of 42 and 168 μm, respectively. ( B ) Surface profiles of the bottom left corner logo were obtained via μCT scanning of the eggshell surface after engraving the logo on it. Inset: Reconstructed μCT scan top view of the 6-pixel (84 μm)–deep logo engraving. The red dashed line indicates the cross section of the surface shown in the plot. ( C ) Pseudo-color plots of the engraving depth. ( D ) Milled trench depth along the milling path for different target milling depths, as measured using the OCT scanner. ( E ) Milled trench depths along the vertical paths for different target milling depths. Inset: Top-view image of the OCT scanner’s FOV after milling. The red circle indicates bregma. The dashed lines show the cross section displayed in (G). ( F ) Milling depths along the horizontal paths for different target milling depths. Inset: Top-view image of the OCT scanner’s FOV after milling. The red circle indicates bregma. The dashed lines show the cross section displayed in (H). ( G ) Coronal section of the mouse skull along the dashed line indicated in (E). ( H ) Coronal cross section of the skull along the dashed line indicated in (F). A, anterior; P, posterior; M, medial; L, lateral; D, dorsal; V, ventral. Next, we performed similar acute experiments on anesthetized mice. The CV-Craniobot scanned and estimated the dorsal skull surface of a mouse, which was then used as a reference to mill trenches of varying depths in the anteroposterior and mediolateral directions ( Fig. 3, E and F ). The CV-Craniobot was programmed to mill 2.2-mm-long lines on the parietal bone 0.8 to 3 mm lateral and 0.2 to 2 mm posterior to bregma ( Fig. 3, E and F ) with depths increasing from 3 pixels (42 μm) to 7 pixels (98 μm) along the axial direction of the OCT scan with respect to the dorsal skull surface. Similar to the milling experiments on eggshells, milling the dorsal skull surface along both the anteroposterior and mediolateral directions resulted in linear tracking of commanded milling depth by milled trench depth. Post-milling scanning of the skull surface revealed clear trenches ( Fig. 3, G and H ). The comparison between the OCT images taken before and after the milling operations clearly indicated the removal of bone along the trenches ( Fig. 3, G and H ). Measuring the depth of the milled trenches and comparing with the commanded depth of milling, we again found that there was a clear linear trend ( Fig. 3, E and F ; R 2 = 0.71 for vertical and R 2 = 0.74 for horizontal lines), with the measured milled depth being ~14 μm (1 pixel) less than the commanded depth of milling. The high variability in the deeper trenches is partly due to the higher curvature of the skull at the edges and the fixed orientation of the driller. This causes one side of the milled trench to be slightly deeper inside the bone, while the other is shallower than the targeted depth. Having established that the estimated dorsal skull surface could be used for robotic milling of eggshells and live anesthetized mice, we next performed experiments to determine whether the estimated ventral surface could be used as a reference for computerized milling. The CV-Craniobot was programmed to mill down to various depths, leaving a programmed skull thickness above the ventral surface. The robot performed circular craniotomies of 2 mm diameter on four mice to quantify the accuracy of this milling operation. The robotic mill was commanded to remove bone, leaving a 70-μm (5 pixels in OCT image coordinates)–thick layer of bone tissue above the ventral skull surface. The craniotomies were performed, centered at ~1.8 mm anterior and ~1.4 mm lateral to bregma ( Fig. 4A ). Cross-sectional OCT images illustrated that we were able to reach the desired depth of milling, with the median thickness of the remaining bone across four craniotomies being 82 μm with interquartile range (IQR) in 71 to 101 μm (6 pixels; IQR, 5 to 7) ( Fig. 4F , left, and fig. S4). We also performed the same procedure ( n = 4 mice) with a target remaining thickness of 98 μm (7 pixels). This time, the craniotomies were performed at different positions with respect to the bregma to sample the robot’s performance in different skull regions. After milling along the programmed path, the OCT-measured resultant thickness had a median value of 106 μm with IQR of 92 to 122 μm (7 pixels; IQR, 6 to 8) ( Fig. 4F , right, and fig. S4). Fig. 4. Robotic milling of mouse skull using estimated ventral surface as reference. ( A ) Reconstructed top view of OCT scan after milling circular trench on a mouse skull. ( B ) Cross-sectional view of the milled skull along the dashed line shown in (A). ( C ) Pseudo-color plot of measured skull thickness after milling of circular trench in (A). ( D ) Reconstructed top view of μCT scan of the same mouse skull shown in (A). ( E ) Cross-sectional view of the milled skull as shown in (D). ( F ) Violin plots of measured thickness of the skull along the milled trench path with target remaining thickness of 70 μm (left plot) and 98 μm (right plot), n = 4 mice. Red lines indicate targeted milling depth. ( G ) Reconstructed top view of OCT scan after milling over a circular area to thin the tissue down to 98 μm. ( H ) Pseudo-color plot of the skull thickness measured via OCT scanning in the milled skull area shown in (G). ( I ) Reconstructed top view of μCT scan of the same mouse shown in (G). ( J ) Cross-sectional view of the milled skull as shown in (G). ( K ) Pseudo-color plot of the skull thickness measured via μCT scanning in the milled skull area shown in (G). ( L ) Violin plots of the measured thickness of the skull in the milled circular area with target remaining thickness of 70 μm (left plot) and 98 μm (right plot), n = 4 mice. Red lines indicate targeted milling depth. A, anterior; P, posterior; M, medial; L, lateral; D, dorsal; V, ventral. Red circles in [(A) and (D)] indicate bregma. The OCT measurements were cross-validated using μCT scanning of the same samples, with μCT providing a higher signal-to-noise ratio and slightly better resolution (11 μm both in lateral and axial directions). The μCT scan revealed rectangular profile trenches created by the flat end mill along the craniotomy ( Fig. 4, D and E ), with the median thickness of bone remaining across four craniotomies performed being 68 μm with IQR of 55 to 99 μm when milling was commanded to leave bone of thickness 70 μm. The remaining thickness had a median of 88 μm and IQR of 70 to 102 μm when milling was commanded to leave the bone of thickness 98 μm. Showing that the ventral surface estimations were adequate to enable removal of the skull bone to the desired thickness. We next performed robotic skull thinning procedures (eight procedures, n = 4 mice) where the skull within a 2-mm-diameter circular area centered at either ~1.3 mm posterior and ~2 mm lateral to bregma or ~1.8 mm anterior and ~1.4 mm lateral to bregma. The CV-Craniobot was set to uniformly remove bone, leaving 70 μm for half of the procedures and 98-μm-thick bone above the ventral skull surface for the rest of the procedures. Such skull thinning operations are typically performed in experiments that are particularly susceptible to potential neuroimmune responses to skull removal ( 27 , 28 ). Both post-milling OCT and μCT scans reveal robust tracking to the desired milling depth across the entire area targeted for thinning ( Fig. 4, G to L , and fig. S5). The median thickness of the bone above the ventral surface was measured to be 61 μm (IQR, 45 to 75 μm) when the robot was commanded to leave the bone thickness of 70 and 96 μm (IQR, 82 to 110 μm) when milling was commanded to leave 98 μm. Measurements of the same skulls made using the μCT revealed a median thickness of 45 μm (IQR, 34 to 57 μm) for the 70-μm target and a median of 68.1 μm (IQR, 57 to 79 μm) for the target thickness of 98 μm ( Fig. 4, K and L ). We observed a slight decrease in the measured thickness in the μCT scans compared to the measurements taken with the OCT immediately after the procedure. Possibly, this is due to the dehydration of the soft bone tissue or the trabecula. These experiments confirmed that the information provided by nondestructive OCT imaging can be reliably used to accurately and precisely remove bone to a specific thickness in a robotic fashion. Computer vision–guided robotic milling for rapid and precise craniotomies We next sought to determine the maximum thickness of the bone from the ventral surface that can remain intact for a craniotomy to be successfully completed. Ideally, bone removal can be performed down to the ventral skull surface for complete bone removal. However, this operation might result in inadvertent contact with the underlying brain and dura due to potential errors in the model estimate. Experienced manual craniotomy surgeons typically aim to mill down to the soft part of the bone tissue, the trabecula, where the bone is loose enough to be fractured and removed. CV-Craniobot was programmed to perform 2-mm-diameter circular craniotomies at the parietal bone (centered at ~1.3 mm posterior and ~2 mm lateral to bregma) and frontal bone (centered at ~1.8 mm anterior and ~1.4 mm lateral to bregma). The milling depth was adjusted to leave the bone thickness varying from 28 to 84 μm above the dorsal surface ( Fig. 5A ). Fig. 5. Automated craniotomies using CV-Craniobot. ( A ) Left: Top view of reconstructed OCT image of the surgery area, with path of circular craniotomy highlighted. Right: Photograph of the same location shown on the left taken after automated removal of the bone island. ( B ) The success rate of complete bone removal at different thicknesses of bone remaining on top of the ventral surface by the CV-Craniobot. ( C ) Top view of computationally stitched reconstructed images from four OCT scans. The image from each scan is coded with a different color. ( D ) Sagittal cross section of the stitched scans along the vertical dashed line shown in (C). ( E ) Coronal cross section of the stitched scans along the horizontal dashed line shown in (C). ( F ) Alignment error during stitching between each two neighboring scans. ( G ) An example image of a mouse implanted with a multi-planar faceted cranial window covering the whole dorsal cortex was taken 21 days after robotic surgery using the CV-Craniobot. ( H ) Representative images of brain slices stained for Iba-1 and 4′,6-diamidino-2-phenylindole (DAPI) of the brain directly underneath the craniotomy and control samples. Scale bar, 200 μm. ( I ) Average microglia cell counts in a 700 μm–by–900 μm area under the milled skull area for the test samples and similar areas for the control samples. n.s., not significant. ( J ) Average time to complete craniotomy using the CV-Craniobot and comparison with human surgeons. Small craniotomies (SC): n = 5 procedures using the robot and n = 5 manual procedures performed by two experimenters. Large craniotomies (LC): n = 5 procedures using CV-Craniobot and n = 7 manual procedures performed by three experimenters. It was observed that, on the parietal bone, programming the CV-Craniobot to leave 28 and 42 μm (2 and 3 pixels in OCT image coordinates) of bone remaining intact over the dorsal skull surface resulted in a 100% success rate in complete bone island removal after a single round of milling ( Fig. 5B ) ( n = 10 craniotomies attempted). The success rate of bone removal dropped to 50% ( n = 10 craniotomies attempted) when leaving 56 μm of the bone thickness ( n = 10 craniotomies attempted) and 0% when the CV-Craniobot was programmed for the remaining thickness of 70 and 84 μm ( n = 10 craniotomies attempted for each target thickness). Similarly, when performing craniotomies in the frontal bone, we found that programming the CV-Craniobot to leave 28 μm (2 pixels in PCT image coordinates) of bone remaining intact over the dorsal skull surface resulted in an 83% success rate in the complete bone island removal ( Fig. 5B , n = 10 craniotomies attempted). The success rate of bone removal dropped to 75% ( n = 10 craniotomies attempted) and 0% when ( n = 10 craniotomies attempted) when the CV-Craniobot performed the craniotomy, leaving 42 and 56 μm of bone remaining above the dorsal skull surface. Similar to parietal bone craniotomies, no craniotomies with a target remaining thickness of 70 and 84 μm resulted in a successful bone removal after a round of milling ( n = 10 for each target depth). Compared to craniotomies performed over the parietal bone, the success rates at each milling depth were lower, possibly due to inaccurate estimation of the dorsal skull surface by the U-Net model or high variation in the refractive index of the bone. Note that the U-Net model training and the refractive index estimation were done mainly on parietal bone. Nevertheless, these results demonstrate the feasibility of single-shot rapid craniotomies, resulting in complete bone removal using the CV-Craniobot. The size of the craniotomy that could be performed after scanning a single region of interest was limited by a 5 mm–by–5 mm lateral FOV of the OCT imaging system. One of the advantages of automating craniotomies is the ability to perform very large craniotomies covering much of the dorsal skull surface ( 3 , 5 , 8 , 9 , 11 , 18 , 29 , 30 ). To perform such large craniotomies, the robot scanned the mouse skull surface across four overlapping FOVs, and the dorsal and ventral surfaces of the skull in each scan were estimated using the U-Net model. Then, the surfaces were computationally stitched together (see Materials and Methods) to create composite dorsal and ventral surfaces of the whole dorsal skull ( Fig. 5C ). The stitching algorithm successfully aligned surfaces from the four scans. Neighboring surfaces were mostly aligned perfectly, generating a complete 3D representation of the dorsal and ventral surfaces of the mouse dorsal skull ( Fig. 5, D and E ). Limited misalignment between the neighboring scans was observed, which is within the limits of the imaging system resolution ( Fig. 5F ). As a demonstration, we used the CV-Craniobot to perform a large craniotomy, removing over 52 mm 2 of the skull surface over the dorsal cortex, encompassing an area over the primary and secondary motor, the somatosensory, association retrosplenial, and visual cortices across both hemispheres to implant a multi-planar faceted cranial window ( Fig. 5G ) ( 30 ). To assess the safety of the CV-Craniobot for automated craniotomies, we evaluated whether the craniotomy resulted in an acute inflammatory response to the brain due to inadvertent contact of the milling tool with the soft brain tissue. The CV-Craniobot was used to perform 2-mm-diameter craniotomies over the cerebral cortex with the target remaining thickness of 48 μm (centered at 2.6 mm medial to midline, 1.8 mm anterior to bregma). All procedures resulted in successful bone detachment. The brain was covered with a gauze pad soaked in sterile saline (0.9% sodium chloride), and the animal was maintained under anesthesia for 60 min, following which animals were transcardially perfused and brain dissected for histological analysis. We stained the fixed brain slices for ionized calcium-binding adaptor molecule 1 (Iba-1), a marker for activated microglial cells ( Fig. 5H ). A 700 μm–by–900 μm area of the brain directly underneath the craniotomy had 38 ± 13 cells. The same area in the corresponding contralateral side had 34 ± 13 cells. There was no significant difference in the average number of Iba-1–positive cells among the two groups ( Fig. 5I ) ( n = 20 samples, from under the surgerized areas and 16 control samples ( P = 0.31, two-sample t test). Thus, controlled bone removal using the CV-Craniobot results in no significant acute inflammatory response in the underlying brain tissue. We further assessed the performance of the CV-Craniobot by comparing the speed of craniotomy procedures enabled by the CV-Craniobot to multiple manual surgeries performed in our laboratory. In contrast to manual craniotomy procedures, the CV-Craniobot needs to perform the OCT scan, followed by U-Net estimation of the dorsal and ventral skull surfaces. Scanning each FOV took 44 s on average, while the U-Net surface estimation and milling path planning took ~2 min for each FOV. The CV-Craniobot is programmed to mill the bone at a maximum feed rate of 6 mm/min. Thus, the CV-Craniobot can consistently perform 2-mm-diameter circular craniotomies in 2 min compared to the average of 8 min taken by human surgeons ( Fig. 5J , n = 6 procedures completed by two surgeons), a 75% reduction in time. Surgeons included both experts (>50 craniotomy procedures) and novices. The CV-Craniobot also performed large craniotomies across the dorsal cortex ( Fig. 5I ) in 5 min, an 85% increase in speed as compared to the average time taken during manual surgeries (34 min SD: 23 min, n = 3 surgeons, seven procedures). These results highlight the capabilities of the CV-Craniobot to perform precise and rapid craniotomy procedures in mice. DISCUSSION We demonstrated that the CV-Craniobot could perform repeatable, precise, safe, and fast craniotomies on the dorsal mouse skull. Comparing milling durations, the CV-Craniobot achieved small craniotomies twice as fast as the previous version and was four times faster than other automated craniotomy systems in performing small circular craniotomies ( 15 , 18 , 31 ). Minimizing the milling duration not only enhances the throughput of the procedure but also potentially increases the animal’s survival chance by reducing the duration of disturbance in the brain environment ( 32 , 33 ). Using OCT scanning to estimate skull thickness along the milling path eliminates the need for user intervention in specifying the milling depth, making the robot’s performance less prone to human errors. Computer vision has previously been used to automate delicate neuroscience experiments such as image-guided patch clamping ( 34 – 36 ) and microinjection ( 37 – 39 ). Integration of machine learning models for object recognition has further extended these efforts both by increasing the accuracy and specificity of object detection ( 40 , 41 ) in a wide range of imaging conditions and providing variability in the types of objects and anatomical features that can be detected and manipulated robotically. Here, we harness deep learning methods to precisely and rapidly estimate skull morphology from OCT images to automate craniotomies in rodents. In the future, our approach for rapid 3D morphology detection using machine learning on nondestructive imaging for surgical operations could be harnessed in clinical settings for automating delicate microsurgical procedures. The CV-Craniobot enables a unique preparation method of reducing skull thickness to a set value. As an advancement over skull thinning preparations demonstrated in the past ( 18 , 28 ), this approach allows the skull tobe thinned to a “uniform” thickness. This can improve imaging quality through the thinned window while minimizing disturbance in the brain environment. OCT scans provide valuable information beyond estimating the skull’s dorsal and ventral surfaces. The speckle variance in OCT images can map microvasculatures in the imaged tissue ( 42 , 43 ). This can potentially be used to study the brain, optimize the device implantation process, or enhance craniotomy path planning. CV-Craniobot was designed with modular bays, each dedicated to performing specific tasks. This design allows for the easy integration of new functionalities by adding additional bays. For example, an electrode insertion bay could be incorporated to enable precise microelectrode insertion, with control over the insertion angle based on OCT scans of brain tissue. Similarly, bays for assisted implantation procedures, ranging from implant placement to using additive manufacturing methods to 3D printed neural interfaces on the animal ( 44 ), can also be envisioned. Thus, the CV-Craniobot is a fully open-source system that can be established in other laboratories using the resources provided in the online data and code repositories associated with this manuscript. In principle, the CV-Craniobot can be applied to perform surgeries in rats; however, there are some caveats. Rat skulls are much thicker than mouse skulls, and accurate reconstruction of the skull morphology will depend on the depth to which the OCD scanner can image through the rat skull. The skull thickness must be estimated, which requires determining the refractive index of the skull tissue for OCT image correction. Additionally, if the appearance of the skulls under OCT differs significantly, then training a new model for image segmentation may be necessary. The 3D skull reconstruction performed by the CV-Craniobot was not as accurate as μCT scans due to the U-Net underestimation of skull thickness in some thicker areas like the central sinus and frontal bone. Other factors include variability in the refractive index of skull tissue and limitations in the model used to correct optical distortions, particularly in extreme lateral regions of the scan ( 21 , 22 ). The accuracy of surface estimation can be enhanced by improving the trained model and deploying more sophisticated scan distortion correction techniques. Despite these inaccuracies, the experiments demonstrated that the current estimations were accurate enough to provide a functional assessment of each surface’s depth. While the cost of the OCT system may limit its accessibility for individual labs, it could be acquired as core facility equipment shared among multiple groups. In the future, the OCT imager could be replaced with less expensive solutions such as laser profilometry coupled with model estimation based on age sex and strain of the animals for noninvasive skull thickness estimation. MATERIALS AND METHODS CV-Craniobot hardware construction and design The CV-Craniobot hardware comprises of four linear actuators: two compact, motorized translation stages with a travel range of 50 mm (MTS-50 Z8, Thorlabs Inc.) for moving the dental driller and the OCT scanner along the Z axis; a 300-mm range stepper motor linear translation stage (LTS300C, Thorlabs Inc.) for moving the custom-made stereotax between the OCT stage and the milling stage and adjusting the X-position of the sample; and a DC-servo motor linear translation stage with a range of 30 mm (M30X, Thorlabs Inc.) for moving the stereotax in the Y direction. The custom-made aluminum stereotax, designed similarly to the Craniobot ( 29 ), is mounted on the X and Y linear stages, which are assembled orthogonally using a custom-designed connector made from 3/8-inch (0.9525-cm)–thick machined 6061 aluminum sheets. The Z -actuators are mounted on 20-inch (50.8-cm) construction rails (50 mm by 75 mm, XE5075L20, Thorlabs Inc.) using custom-made aluminum connectors. The OCT scanner and the USB digital microscope are mounted on the Z -actuator using a custom-designed, 3D printed holder. The milling procedure uses an electric dental drill (RAMPOWERDIGITAL45, RAM Products, Inc.) mounted on the Z -stage with another custom-designed, 3D printed holder. OCT scanner The CV-Craniobot uses a commercial spectral domain OCT scanner with a center wavelength of 1310 nm and a bandwidth of 60 nm (OQ Stratascope 1.0, Lumedica Inc.) for OCT scanning of the mouse skull during surgeries and is equipped with a custom objective with a fixed working distance of 1 inch (2.54 cm). The system uses the native software package (Lumedica OQ LabScope, Lumedica Inc.) to manage the scanning process, perform primary calculations on the raw signals, and generate cross-sectional B-scans. Software communication and control The CV-Craniobot control software was developed in LabVIEW (National Instruments Inc.). The motorized stages were connected to the control computer via USB serial communication, linking the computer to each linear stage’s controller. The linear stage controllers used a built-in PID (proportional, integral, derivative) algorithm to execute position commands and communicated with LabVIEW through .NET controls provided by their native software (Kinesis, Thorlabs Inc.) (see fig. S6 for the communication diagram). The CV-Craniobot controller software communicated with the OCT scanner’s native software through a virtual serial port (virtual serial port driver, version 11, Electronic Team Inc., 2023). Multiple scripts for calculating the milling path based on the OCT scans of the sample were written in MATLAB (MATLAB, MathWorks), which were called and executed through the LabVIEW interface for MATLAB. The Graphic User Interface (GUI) also provides options for the users to re-perform a craniotomy along the same path in the case of unsuccessful bone removal. The external graphic user interface is illustrated in fig. S7. The control software and the computer-aided design files for constructing the custom-built hardware components are available for download at https://doi.org/10.5281/zenodo.14596992 . CV-Craniobot calibration To perform automated milling based on the OCT scans of the sample, it is necessary to determine the relationship between the coordinates of each 3D point in the OCT scans and the position of each motorized stage. After the OCT scan distortion removal process, we found the transformation operator using normalized direct linear transformation ( 45 ). To correlate the 3D position of the driller’s tip ( X -stage, Y -stage, and driller’s Z -stage positions) with the 3D space of the OCT image, nine holes were automatically drilled in modeling clay using the dental driller, with its position controlled and recorded by the linear stages. The drilled sample was then transferred to the OCT stage and imaged by the OCT scanner. After normalizing the points’ coordinates, the relationship between the recorded drilling position for each hole and the position of the center of the drilled hole on the OCT scan was extracted by finding the affine transformation matrix (calibration matrix) relating these two spaces. To ensure a robust solution and increase accuracy, we designed the pilot points so that no three points were collinear and no four were coplanar ( 30 ). The resulting calibration matrix and the position of the robot stages during OCT imaging were then saved for further use. Processing of the OCT scans and all related calculations to find the calibration matrix was performed using custom MATLAB scripts with the MATLAB Image Processing Toolbox. We embedded all MATLAB scripts, along with the custom-built GUI, in a LabVIEW VI designed specifically for the calibration procedure. The script also contained a module to annotate the edges of the OCT’s “top-view” FOV in the live images from the USB microscope (MS100 portable USB microscope, Teslong Technology) mounted along with the OCT scanner. The annotated area in the live video from the USB camera was used to ease the sample adjustment process under the OCT scanner before automated craniotomy. Non-telecentric distortion correction We corrected OCT scans for non-telecentric scanning distortions before being used for the dorsal and ventral surface estimation by the U-Net model using a custom MATLAB script. The script modeled the fan distortion, i.e., non-telecentric scanning distortions, by radial and tangential distortions in Z cross sections of the OCT scan. To find the distortion parameters in the resultant XY image, we imaged the imprint of a piece of woven wire 120 mesh on modeling clay using the OCT scanner at different distances from the scanner with increments of 75 μm. For each batch of B-scans (one volume scan), the XY image was generated as the Z cross section of the scan at Z equal to the mean clay surface Z value. The resultant XY images for each B-scan batch are shown in Fig. 2B . The custom script detected the edges of the mesh’s imprints using MATLAB image processing toolbox function (edge) used the “Canny” method, labeled, and stored as separate image components using MATLAB’s function (bwlabel). Each detected edge represented a straight line that was deformed because of the image distortions. Radial distortion correction We used the division model ( 46 ) of radial distortion to formulate and correct for radial distortion in the XY image. The division model can express high distortion in low order, sufficient for commonly seen distortions in cameras ( 47 – 49 ). Hence, we used the model’s first order to express the image’s distortion. Specifically, the method by Wang et al. ( 49 ) was used, where each line was fitted on a circle, and the radial distortion parameters were found as the solution to a system of linear equations relating the parametric equation representing a straight line after distortion and the equation representing the distorted lines fitted on a circle. The circle fit to each deformed line was found using a custom MATLAB script developed previously ( 50 ), which uses the direct least-squares fitting method to find the best-fit circle. We solved the system of linear equations for all lines using a custom MATLAB script and extracted the radial distortion parameters (distortion center and first-order radial distortion coefficient) for the XY image. The same procedure was repeated for all OCT volumes, and, for each Z , the radial distortion parameters were calculated. We calculated the resultant radial distortion parameters as the mean of these values across different Z cross sections. The extracted parameters were then used to recalculate the position of each point in the 3D scan. Tangential distortion correction The Brown-Conrady model, which represents both tangential and radial distortion, was used to correct for tangential distortion in the XY image for each Z value ( 51 ). After correcting the image for radial distortion, we used the first-order tangential portion of the Brown-Conrady model to model the distortion in the image. Tangential distortion parameters were calculated by first reconstructing the undistorted lines as lines parallel to either of the two perpendicular lines crossing the center of radial distortion in the same position as the current distorted lines. Then, we reconstructed the parametric equations for each line using Brown’s model. We compared the parametric equations to the distorted lines detected in the image, and the distortion parameters were extracted. We chose the average of the tangential distortion parameters over different Z values as the final tangential distortion parameter. After reconstructing the corrected scan, the empty pixels were filled by interpolation using a custom function (ndnanfilter) written in MATLAB ( 52 ). To assess the success of the image correction algorithm in reducing telecentric distortion in the XY plane of the OCT scans, we calculated the RMSE of each point on an X- or Y -line in the distorted image. The error for each point on a line was defined as the distance between that point and the corresponding point on the reference line (undistorted form of the line). The error was calculated for all XY images from Z = 72 to 337 pixels (the usable range for imaging through the mouse skull). We applied the same procedure to the corrected image, and the RMSE was calculated for each detected line. The entire process was performed using a custom MATLAB script. OCT top-view image generation A custom MATLAB function was reconstructed the top-view image of the scanner’s FOV and enabled the user to choose the position of the milling path on the animal skull. The function reads the OCT scan from the hard drive and corrects the telecentric distortions in the scan. It reconstructs the top-view image by summing the intensities for all Z values for each X and Y , replicating what a 2D camera would do to generate a top-view image of the sample. The function further refines the image using MATLAB’s built-in image processing toolbox function (“localcontrast”) to adjust the image’s contrast, setting the maximum and minimum intensity range of the image within 3 SDs from the mean intensity value. U-Net model training We used a U-Net model to perform semantic segmentation of each B-scan, which was then post-processed to extract the dorsal and ventral boundaries. The model was trained for 100 epochs using the Adam optimizer ( 53 ) with a learning rate of 4 × 10 −4 . For our loss function, we used the region-based Tversky loss ( 54 , 55 ), finding that it produced more structurally coherent predictions, especially around borders, compared to distribution-based criteria such as binary cross entropy. We implemented training augmentations to improve the model’s generalization to novel samples that included a random horizontal and vertical flip ( P = 0.5), as well as a random vertical translation ( P = 0.5). Model performance was quantified using the pixel-wise accuracy and IOU metrics on out-of-fold samples within a K -fold cross-validation scheme ( k = 5). The model was trained on 300 annotated live mouse skull B-scans. Four scans from the same FOV were averaged into a single high-quality scan for each FOV to enhance the quality of the manual annotations. These high-quality scans were then selectively annotated in the corresponding B-scans. For the training, the annotated areas were overlaid onto the raw image from one scan. A custom MATLAB script was used to prepare the training set. Dorsal and ventral surface reconstruction A compiled custom MATLAB script was used to estimate the positions of the dorsal and ventral surfaces. As explained above, the script first reads the OCT stack and corrects it for distortions. Then, it smooths the scan in the Y direction using a 3D median filter (a built-in MATLAB function) with a window size of 15 pixels in the Y direction. Next, the script uses the trained U-Net model to infer the pixels containing the mouse skull in each B-scan. The dorsal surface is calculated as the largest gradient in the Z direction in the resulting binary cross-sectional image from the U-Net model (from 0/no skull to 1/skull), and the ventral surface is found as the lowest gradient in the Z direction (from 1/skull to 0/no skull). The calculated dorsal and ventral boundaries of the skull in each B-scan are then accumulated to generate 3D surfaces of the dorsal and ventral areas of the skull. We further smoothed the surfaces using a 2D median filter with a window of 5 pixels in the X direction and 10 pixels in the Y direction. Last, the script adjusts the orientation of the surfaces for ease of calculation in the subsequent steps and saves the generated surfaces along with the top-view image of the OCT FOV as a .mat file on the hard drive. The script is compiled into an executable file using MATLAB Compiler to facilitate the use of the trained model by LabVIEW VI and reduce the complexity of system configuration for future system replication. Optical distortion (refractive index) correction To correct the OCT images for optical distortion, every surface imaged through a material other than air should be corrected for depth. This is accomplished by dividing the thickness of the medium by its refractive index ( 21 ). Hence, we calculated the corrected depth of the ventral surface as follows Corrected ventral surface depth = Dorsal surface depth − ( Dorsal surface depth − Virtual ventral surface depth ) refractive index After estimating the dorsal and ventral surfaces of the mouse skull using the U-Net model, the depth of the ventral surface at each point was corrected using the above equation with a custom MATLAB script. Milling path computation The CV-Craniobot user provided the non-axial ( X and Y ) positions of the milling pilot points with respect to the center of the craniotomy to the system in millimeters in a text file format following the control software prompt. The milling depth for each pilot point was then automatically calculated through a custom MATLAB script embedded in the CV-Craniobot’s control VI in LabVIEW as follows: After completing the OCT scanning, the script generated a top view of the sample from the OCT scans. The user was prompted to annotate the center of the milling axis and a point on the negative Y axis on the top-view image. The input pilot points were then rotated, centered on the basis of the input path center and orientation, and scaled to match the OCT magnification (each millimeter is ~111 pixels in the OCT transverse direction). The resulting milling path was overlaid on the OCT top-view image for the user’s confirmation. To ensure that the milling pilot points were sufficiently close to capture the sample height changes along the milling path, a custom MATLAB function linearly interpolated between the original pilot points to keep their distance below 100 μm. The interpolated points were then added to the original set of milling pilot points. The robot software then calculated the milling depth using different methods depending on the input milling mode (constant remaining thickness milling or constant trench depth milling). For each pilot point, the depth was determined by first referencing the depth of the reference surface at that point. For constant trench depth procedures, the reference surface was the dorsal surface, while, for the “constant remaining thickness” mode, it was the skull’s ventral surface. The software then prompted the user to input the desired milling depth or remaining thickness (based on the milling mode). The depth of the milling path was calculated as an offset from the reference surface (positive offset for constant remaining thickness and negative for “constant trench depth”). In the final step, the software transforms the 3D coordinates of the milling pilot points from OCT 3D space to the linear stage’s coordinate space using the calibration matrix and the relative position of the sample during OCT scanning with respect to the calibration sample during the calibration process P stage = P OCT * A + ( V imaging − V calibration ) where P stage is the milling pilot points in the stage’s axis, P OCT are the pilot points coordinates in the OCT space, A is the calibration matrix, V imaging is the position vector of the stereotax and the ( X and Y ) and the OCT scanner ( Z ) during the sample’s scanning process and V calibration is the position vector of the stereotax while imaging during the calibration process. The system saved the generated milling pilot points as a text file on the hard drive and passed to the software controller to perform milling. Surgical procedures All animal experiments in this study were conducted under approved protocols by the University of Minnesota Institutional Animal Care and Use Committee (approval number 2411-42563A). We used mice from three strains (Ai162/Cux2-cre, Ai162, and Thy1-Gcamp6f) of both sexes and ages ranging from 10 to 56 weeks. Before surgery, the mice were anesthetized with 1 to 5% isoflurane (Piramal Critical Care Inc., Bethlehem, PA) and were administered buprenorphine (Par Pharmaceutical, Chestnut Ridge, NY) at 1 mg/kg and meloxicam (Dechra Veterinary Products, Overland Park, KS) at 1 to 2 mg/kg. Buprenorphine was replaced by slow-releasing buprenorphine (Buprenorphine SR LAB, Zoopharm, Windsor, CO) at 1 mg/kg, and meloxicam was replaced by dexamethasone at 2 mg/kg for survival surgeries. The mouse scalp was shaved and cleaned, and the animal was transferred to the CV-Craniobot’s stereotax, which maintained anesthesia with a continuous supply of isoflurane in oxygen. We sterilized the scalp area using standard aseptic techniques, and the scalp and manually removed fascia with autoclaved surgical instruments. The mouse skull was dried with autoclaved cotton swabs. At the initiation of the robotic craniotomy procedure, CV-Craniobot transferred the mouse to the OCT imaging bay for scanning. After scanning and path planning, the mouse was automatically transferred to the milling bay, where a craniotomy was performed. During milling, the skull was constantly irrigated with sterile saline to remove bone dust and prevent tissue damage from the heat generated during milling. The system performed an additional OCT scan for assessment purposes at the end of the craniotomy procedure. The animal was euthanized after removal from the stereotax after acute surgical procedures. During the survival surgery, the surgeon fixed a sterilized cranial implant on the skull with dental cement (S380, C&B Metabond, Parkell Inc.) after bone removal. Once the surgery was done, the mouse was transferred to a clean, heated cage for monitoring until full recovery. The animal’s state was monitored for up to 3 days post-procedure. Automated craniotomy using the CV-Craniobot The user first head fixed the mice on the custom stereotax and removed the scalp. Then, CV-Craniobot control software guided the user through multiple steps via user prompts for inputs. The user could choose the milling mode, i.e., using the dorsal skull surface as a reference or ventral skull surface as a reference, and specify the craniotomy’s size, shape, and location. User-initiated inputs guided the affixed mouse first to the OCT scanner bay, where the head of the mouse was adjusted via visualization using the targeting camera (MS100 portable USB microscope, Teslong Technology) to ensure that the area of the desired craniotomy was within the OCT imaging FOV. The user adjusted the height of the OCT scanner with respect to the skull using the live B-scans in OCT’s native control software. The CV-Craniobot next scanned the skull using the OCT scanner and generated a top view of the reconstructed OCT scan image. Next, the user specified the orientation and location of the milling path by annotating the top view image, after which the CV-Craniobot computed the required milling path (fig. S7). In the next step, the CV-Craniobot moved the stereotax to the milling bay to perform a robotic craniotomy. The milling procedure was carried out using an electric dental drill operating at a speed of 20,000 to 30,000 rpm, equipped with a miniature square-end mill with a diameter of 200 μm (Harvey Tool Inc., 13908). A complete automated circular craniotomy procedure is illustrated in movie S2. Constant trench depth milling on a live mouse skull A 20-week-old male Thy1-Gcamp6f mouse was used to perform multiple constant-depth craniotomies. Using the CV-Craniobot, we milled five horizontal lines perpendicular to the central suture orientation on the left hemisphere of the mouse skull. Each line had a different trench depth, ranging from 42 to 98 μm. Similarly, five vertical lines with varying trench depths were milled on the right hemisphere of the mouse skull. After each craniotomy, the mouse was automatically transferred back to the OCT stage for scanning. These scans were later used to assess the milling depth in each procedure. Constant remaining thickness milling and skull thinning procedure Five mice (four females and one male), aged 10 to 15 weeks and from various strains (Ai162 and Ai163/Cux2-cre), underwent two circular craniotomies and two circular skull thinning preparations with different target remaining thicknesses. The position of each craniotomy varied between mice to assess the CV-Craniobot’s performance in different areas of the skull. CV-Craniobot scanned the milled area automatically at the end of each craniotomy procedure for performance assessment. We euthanized the animals after the experiment, extracted their skulls, and preserved in 4% paraformaldehyde (PFA). The skull thinning procedure involved constant remaining thickness milling along a specific milling path designed to cover the entire area of interest. Using a custom MATLAB script, we generated the milling path and calculated a raster milling path for any drown convex shape where the distance between each milling pass could be adjusted for different end mills. The distance between each pass was set to 80 μm for the experiments reported here. Milling procedure assessment using the OCT scanner To assess the performance of the CV-Craniobot, the robot returned the sample to the initial scanning position ( V imaging ) after the milling procedure and performed an OCT scan. The software calculated the dorsal surface of the sample after milling by finding the maximum gradient in the Z direction for each X and Y . U-Net was not used to find the surfaces after milling because of its inferior performance compared to the gradient method in finding the depth of the milled trenches. In some cases, we detected a global offset between the dorsal surfaces before and after milling in non-milled areas. This offset was partly due to the minor differences between the U-Net and gradient thresholding methods in identifying the dorsal surface pixels. This height difference (dorsal offset) was calculated as the mode of the differences between the two dorsal surfaces. We measured the difference between the two dorsal surfaces (before and after milling) along the milling path for constant-depth drilling, which was reported as the final milling depth after being corrected for dorsal offset. For constant thickness craniotomies, we used the distance between the milled dorsal surface and the ventral surface (corrected for dorsal offset) before milling along the milling path as the remaining thickness measure. The whole process was performed using a custom MATLAB script. To assess the linear relationship between the targeted milling depth and the resultant milled depth, the measured thicknesses along the path against the target depth were fitted for all thicknesses using robust (“bisquare”) linear regression using a built-in function (“fitlm”) of statistics and machine learning toolbox in MATLAB, and the coefficient of determination was also extracted as a property of the output model. μCT scanning and processing To cross-validate the OCT measurement, we scanned the samples shortly after the OCT scan with a μCT scanner (H225 X-teck XT, Nikon PA, USA). The scans were taken with a resolution of 11 μm on all axes, and the FOV of the scans contained the entire mouse skull. To prepare the samples for μCT, we euthanized each mouse and extracted and mounted their skull on a Teflon pedestal compatible with the μCT’s scanning stage. The sample was fixed on a mount compatible with the μCT scanner using epoxy glue (DP100 Plus Epoxy Adhesive-3M) and was scanned with the same setting as our previous studies ( 55 ). The x-ray images of the sample were then saved as a volume graphics file (.vgi) and subsequently saved as .tiff files using VGSTUDIO MAX 3.0 (Volume Graphics GmbH, Heidelberg, Germany). We then analyzed the scans using a custom MATLAB script. The script smoothed the scans using a 3D median filter with a window size of 3 pixels in all axes, followed by segmentation using MATLAB image processing toolbox function (“imbinarize”). The robot software then used the segmented binary image to find the dorsal and ventral surfaces by finding the first and last pixel equal to one in the Z direction for all X ’s and Y ’s. OCT-μCT scan comparison The acquired OCT and μCT scans have different resolutions and fields of view. To compare the measured skull thickness through these different scanning systems, we extracted the dorsal and ventral surfaces of the sample using the methods explained above for each scanning modality. Then, the μCT scan was transformed using an affine transformation matrix to have the same orientation and magnification as the OCT scan. After the transformation, we calculated the thickness of the mouse skull for each modality by subtracting the depth of the dorsal surface from the ventral surface. We calculated the affine transformation matrix for transforming the μCT scan using a custom script that finds the solution for the matrix M as a solution to the linear equation P = Q * M . P is the position of visible skull landmarks in the OCT scan, and Q is the position of the same landmarks in the μCT scan. The user manually annotated the landmarks in both scans. Bone removal success rate experiment To assess the success rate of bone removal at different remaining thicknesses of the mouse skull under the milling path, we performed multiple circular craniotomies with a diameter of 2 mm and varying target remaining thicknesses (28 to 84 μm) on eight mice, aged 17 to 21 weeks. The group included two males and six females from various strains (Ai162/Cux2-cre, Ai162, and Thy1-GCamp6f). Each mouse underwent three to eight craniotomies, totaling 10 for each target thickness. After automated milling, the experimenter tested the bone disk to verify whether it was removable and recorded the result. Histology We performed a histology study on a subset of mice ( n = 5 mice, aged 7 to 23 weeks), comprising two males and three females from various strains (Ai162/Cux2-cre, Ai162, and Thy1-GCamp6f). On each mouse, we used CV-Craniobot to perform a circular craniotomy with a diameter of 2 mm, and a predefined remaining thickness of 28 μm was milled on the left hemisphere of each mouse skull. After milling, we confirmed that the bone island could be removed. The animals were kept anesthetized on the CV-Craniobot’s stereotax for 1 hour after the milling procedure to allow for a potential neuroimmune response due to tissue damage during the milling process. We recovered the mice from the robot and transcardially perfused them using methodologies that we have previously used ( 56 ). The dissected brains were sliced and stained using the same procedure as established previously ( 18 ). Using a custom MATLAB script, we counted the number of microglial cells in an area of 700 μm by 900 μm under the milling path. Four tissue samples were used from each mouse to count immune cells under the milling path. We identified microglial cells by the co-occurrence of Iba-1 and 4′,6-diamidino-2-phenylindole staining in the same area. The contralateral hemisphere of the same mouse brain was used as the control sample to count the baseline number of microglial cells in the tissue. Image stitching To perform larger craniotomies using the CV-Craniobot, a larger area needs to be scanned by the OCT scanner. To extend the OCT scanner’s FOV, after the user positions the sample to fit in the target area (target position), the CV-Craniobot moves the sample to four different predefined positions with respect to the target position and performs OCT scanning. These scans collectively cover the entire area of interest. The CV-Craniobot software analyzes each scan separately to infer the dorsal and ventral surfaces. The software stitches the resulting surfaces together using the known relationship between the position of X -, Y -, and OCT Z -stages and the center of the image in the OCT scan (a calibration matrix), and the position at which each scan was performed with respect to the target position to predict the position of each surface in the larger OCT space. The Z value of the surfaces in overlapping regions is estimated as the average height of the overlapping surfaces. Acknowledgments We thank B. Van Heel and A. Fok for help with μCT imaging experiments. The μCT scanning was performed at the Minnesota Dental Research Center for Biomaterials and Biomechanics. We thank C. Forster at the Center for Translational Science Institute (CTSI) for help with histology experiments. The CTSI is supported by the National Center for Advancing Translational Sciences of the National Institutes of Health, award numbers UM1TR004405 and UL1TR002494. We also thank J. Hope for fruitful discussions on using OCT imaging for this project. Funding: This work was supported by grant R01NS11128 awarded by the National Institute for Neurological Disease and Stroke (NINDS) and grant RF1NS113287 awarded by the National Institutes of Health (NIH) BRAIN Initiative to S.B.K. Author contributions: Conceptualization: Z.S.N., B.G., and S.B.K. Methodology: Z.S.N., R.P., and S.B.K. Software: Z.S.N., R.P., B.G., and J.O.B. Data curation: Z.S.N, R.P., and S.B.K. Formal analysis: Z.S.N., R.P., and S.B.K. Investigation: Z.S.N., A.C., F.D., M.F., and S.B.K. Visualization: Z.S.N., R.P., and S.B.K. Validation: Z.S.N., A.C., E.K., and F.D. Writing—original draft: Z.S.N., R.P., and S.B.K. Writing—review and editing: Z.S.N., R.P., A.C., E.K., F.D., M.F., and S.B.K. Project administration: Z.S.N. and S.B.K. Supervision: Z.S.N. and S.B.K. Funding acquisition and resources: S.B.K. Competing interests: S.B.K. is a cofounder of Objective Biotechnology Inc. The other authors declare that they have no competing interests. Data and materials availability: The CV-Craniobot control software is available for download here: https://doi.org/10.5281/zenodo.14596992 . All other data needed to evaluate the conclusions in the paper are present in the paper and/or the Supplementary Materials. Supplementary Materials The PDF file includes: Supplementary Text S1 Figs. S1 to S7 Legends for movies S1 and S2 References Other Supplementary Material for this manuscript includes the following: Movies S1 and S2 REFERENCES AND NOTES 1. Yu C.-H., Yu Y., Adsit L. M., Chang J. T., Barchini J., Moberly A. H., Benisty H., Kim J., Young B. K., Heng K., Farinella D. M., Leikvoll A., Pavan R., Vistein R., Nanfito B. R., Hildebrand D. G. C., Otero-Coronel S., Vaziri A., Goldberg J. L., Ricci A. J., Fitzpatrick D., Cardin J. A., Higley M. J., Smith G. B., Kara P., Nielsen K. J., Smith I. T., Smith S. L., The Cousa objective: A long-working distance air objective for multiphoton imaging in vivo. Nat. Methods 21, 132–141 (2024). 2. Kim T. H., Zhang Y., Lecoq J., Jung J. C., Li J., Zeng H., Niell C. M., Schnitzer M. J., Long-term optical access to an estimated one million neurons in the live mouse cortex. Cell Rep. 17, 3385–3394 (2016). 3. Ren C., Komiyama T., Wide-field calcium imaging of cortex-wide activity in awake, head-fixed mice. STAR Protocols 2, 100973 (2021). 4. Hope J., Beckerle T. M., Cheng P.-H., Viavattine Z., Feldkamp M., Fausner S. M. L., Saxena K., Ko E., Hryb I., Carter R. E., Ebner T. J., Kodandaramaiah S. B., Brain-wide neural recordings in mice navigating physical spaces enabled by robotic neural recording headstages. Nat. Methods 21, 2171–2181 (2024). 5. Bennett C., Ouellette B., Ramirez T. K., Cahoon A., Cabasco H., Browning Y., Lakunina A., Lynch G. F., McBride E. G., Belski H., Gillis R., Grasso C., Howard R., Johnson T., Loeffler H., Smith H., Sullivan D., Williford A., Caldejon S., Durand S., Gale S., Guthrie A., Ha V., Han W., Hardcastle B., Mochizuki C., Sridhar A., Suarez L., Swapp J., Wilkes J., Siegle J. H., Farrell C., Groblewski P. A., Olsen S. R., SHIELD: Skull-shaped hemispheric implants enabling large-scale electrophysiology datasets in the mouse brain. Neuron 112, 2869–2885.e8 (2024). 6. M. L. Streng, R. E. Carter, B. W. Kottke, K. Togneri, E. Wasserman, V. Rajendran, S. B. Kodandaramaiah, E. Krook-Magnuson, T. J. Ebner, Mesoscale Ca 2+ imaging reveals networks of Purkinje cell dendritic and somatic modulation, with divergent roles of activity versus correlation during behavior. bioRxiv 561090 [Preprint] (2023). https://doi.org/10.1101/2023.10.05.561090. 7. Ghanbari L., Carter R. E., Rynes M. L., Dominguez J., Chen G., Naik A., Hu J., Sagar M. A. K., Haltom L., Mossazghi N., Gray M. M., West S. L., Eliceiri K. W., Ebner T. J., Kodandaramaiah S. B., Cortex-wide neural interfacing via transparent polymer skulls. Nat. Commun. 10, 1500 (2019). 8. Donaldson P. D., Navabi Z. S., Carter R. E., Fausner S. M. L., Ghanbari L., Ebner T. J., Swisher S. L., Kodandaramaiah S. B., Polymer skulls with integrated transparent electrode arrays for cortex-wide opto-electrophysiological recordings. Adv. Healthc. Mater. 11, e2200626 (2022). 9. Hu J., Hossain R. F., Navabi Z. S., Tillery A., Laroque M., Donaldson P. D., Swisher S. L., Kodandaramaiah S. B., Fully desktop fabricated flexible graphene electrocorticography (ECoG) arrays. J. Neural Eng. 20, 016019 (2023). 10. Rynes M. L., Surinach D. A., Linn S., Laroque M., Rajendran V., Dominguez J., Hadjistamoulou O., Navabi Z. S., Ghanbari L., Johnson G. W., Nazari M., Mohajerani M. H., Kodandaramaiah S. B., Miniaturized head-mounted microscope for whole-cortex mesoscale imaging in freely behaving mice. Nat. Methods 18, 417–425 (2021). 11. Edelman B. J., Siegenthaler D., Wanken P., Jenkins B., Schmid B., Ressle A., Gogolla N., Frank T., Macé E., The COMBO window: A chronic cranial implant for multiscale circuit interrogation in mice. PLOS Biol. 22, e3002664 (2024). 12. Vickers E. D., McCormick D. A., Pan-cortical 2-photon mesoscopic imaging and neurobehavioral alignment in awake, behaving mice. eLife 13, RP94167 (2024). 13. Roome C. J., Kuhn B., Chronic cranial window with access port for repeated cellular manipulations, drug application, and electrophysiology. Front. Cell. Neurosci. 8, 379 (2014). 14. Holtmaat A., Bonhoeffer T., Chow D. K., Chuckowree J., De Paola V., Hofer S. B., Hübener M., Keck T., Knott G., Lee W.-C. A., Mostany R., Mrsic-Flogel T. D., Nedivi E., Portera-Cailliau C., Svoboda K., Trachtenberg J. T., Wilbrecht L., Long-term, high-resolution imaging in the mouse neocortex through a chronic cranial window. Nat. Protoc. 4, 1128–1144 (2009). 15. Pak N., Siegle J. H., Kinney J. P., Denman D. J., Blanche T. J., Boyden E. S., Closed-loop, ultraprecise, automated craniotomies. J. Neurophysiol. 113, 3943–3953 (2015). 16. Osa T., Abawi C. F., Sugita N., Chikuda H., Sugita S., Tanaka T., Oshima H., Moro T., Tanaka S., Mitsuishi M., Hand-held bone cutting tool with autonomous penetration detection for spinal surgery. IEEE/ASME Trans. Mechatron. 20, 3018–3027 (2015). 17. Seibold M., Maurer S., Hoch A., Zingg P., Farshad M., Navab N., Fürnstahl P., Real-time acoustic sensing and artificial intelligence for error prevention in orthopedic surgery. Sci. Rep. 11, 3993 (2021). 18. Ghanbari L., Rynes M. L., Hu J., Schulman D. S., Johnson G. W., Laroque M., Shull G. M., Kodandaramaiah S. B., Craniobot: A computer numerical controlled robot for cranial microsurgeries. Sci. Rep. 9, 1023 (2019). 19. Huang D., Swanson E. A., Lin C. P., Schuman J. S., Stinson W. G., Chang W., Hee M. R., Flotte T., Gregory K., Puliafito C. A., Optical Coherence Tomography. Science 254, 1178–1181 (2015). 20. J. G. Fujimoto, W. Drexler, “Introduction to OCT” in Optical Coherence Tomography: Technology and Applications , W. Drexler, J. G. Fujimoto, Eds. (Springer International Publishing, 2015), pp. 3–64. https://doi.org/ 10.1007/978-3-319-06419-2_1. 21. Westphal V., Rollins A. M., Radhakrishnan S., Izatt J. A., Correction of geometric and refractive image distortions in optical coherence tomography applying Fermat’s principle. Opt. Express 10, 397–404 (2002). 22. Ortiz S., Siedlecki D., Grulkowski I., Remon L., Pascual D., Wojtkowski M., Marcos S., Optical distortion correction in optical coherence tomography for quantitative ocular anterior segment by three-dimensional imaging. Opt. Express 18, 2782–2796 (2010). 23. Díaz J. D., Stritzel J., Rahlves M., Majdani O., Reithmeier E., Ortmaier T., Roth B., One step geometrical calibration method for optical coherence tomography. J. Opt. 18, 015301 (2015). 24. O. Ronneberger, P. Fischer, T. Brox, “U-Net: Convolutional Networks for Biomedical Image Segmentation” in Medical Image Computing and Computer-Assisted Intervention – MICCAI 2015 , N. Navab, J. Hornegger, W. M. Wells, A. F. Frangi, Eds. (Springer International Publishing, 2015), pp. 234–241. 25. Stritzel J., Rahlves M., Roth B., Refractive-index measurement and inverse correction using optical coherence tomography. Opt. Lett. OL 40, 5558–5561 (2015). 26. Turani Z., Fatemizadeh E., Xu Q., Daveluy S., Mehregan D., Avanaki M. R. N., Refractive index correction in optical coherence tomography images of multilayer tissues. J. Biomed. Opt. 23, 070501 (2018). 27. Silasi G., Xiao D., Vanni M. P., Chen A. C. N., Murphy T. H., Intact skull chronic windows for mesoscopic wide-field imaging in awake mice. J. Neurosci. Methods 267, 141–149 (2016). 28. Drew P. J., Shih A. Y., Driscoll J. D., Knutsen P. M., Blinder P., Davalos D., Akassoglou K., Tsai P. S., Kleinfeld D., Chronic optical access through a polished and reinforced thinned skull. Nat. Methods 7, 981–984 (2010). 29. Rynes M. L., Ghanbari L., Schulman D. S., Linn S., Laroque M., Dominguez J., Navabi Z. S., Sherman P., Kodandaramaiah S. B., Assembly and operation of an open-source, computer numerical controlled (CNC) robot for performing cranial microsurgical procedures. Nat. Protoc. 15, 1992–2023 (2020). 30. A. Cherkkil, J. Hu, I. Oladepo, S. Fausner, D. Surinach, R. Peters, K. Saxena, R. Horstmeyer, S. B. Kodandaramaiah, “Micro-camera Arrays for Ultra-widefield, Multi-site Cellular Resolution Calcium Imaging Across the Dorsal Cortex of Behaving Mice” in Optica Biophotonics Congress: Biomedical Optics 2024 (Optica Publishing Group, 2024), p. BM3C.6. https://opg-optica-org.ezp3.lib.umn.edu/abstract.cfm?uri=BRAIN-2024-BM3C.6 . 31. Ramrath L., Vogt S., Jensen W., Hofmann U. G., Schweikard A., Computer- and robot-assisted stereotaxy for high-precision small animal brain exploration. Biomed. Tech. (Berl) 54, 8–13 (2009). 32. Cheng H., Clymer J. W., Po-Han Chen B., Sadeghirad B., Ferko N. C., Cameron C. G., Hinoul P., Prolonged operative duration is associated with complications: A systematic review and meta-analysis. J. Surg. Res. 229, 134–144 (2018). 33. McHayle A., Pertsch N. J., Toms S. A., Weil R. J., Operative duration and early outcomes in patients having a supratentorial craniotomy for brain tumor: A propensity matched analysis. J. Clin. Neurosci. 92, 207–214 (2021). 34. Wu Q., Kolb I., Callahan B. M., Su Z., Stoy W., Kodandaramaiah S. B., Neve R., Zeng H., Boyden E. S., Forest C. R., Chubykin A. A., Integration of autopatching with automated pipette and cell detection in vitro. J. Neurophysiol. 116, 1564–1578 (2016). 35. Suk H.-J., van Welie I., Kodandaramaiah S. B., Allen B., Forest C. R., Boyden E. S., Closed-loop real-time imaging enables fully automated cell-targeted patch-clamp neural recording in vivo. Neuron 96, 244–245 (2017). 36. Annecchino L. A., Morris A. R., Copeland C. S., Agabi O. E., Chadderton P., Schultz S. R., Robotic automation of in vivo two-photon targeted whole-cell patch-clamp electrophysiology. Neuron 95, 1048–1055.e3 (2017). 37. Shull G., Haffner C., Huttner W. B., Kodandaramaiah S. B., Taverna E., Robotic platform for microinjection into single cells in brain tissue. EMBO Rep. 20, e47880 (2019). 38. G. Shull, C. Haffner, W. B. Huttner, E. Taverna, S. B. Kodandaramaiah, Image-guided robotic cell microinjection: An automated high-throughput technique for the precise delivery of fluorescently-labeled polysaccharides into single neuronal cells in organotypic brain slice cultures, JoVE Wordpress Development; www.jove.com/20989 . 39. Alegria A. D., Joshi A. S., Mendana J. B., Khosla K., Smith K. T., Auch B., Donovan M., Bischof J., Gohl D. M., Kodandaramaiah S. B., High-throughput genetic manipulation of multicellular organisms using a machine-vision guided embryonic microinjection robot. Genetics 226, iyae025 (2024). 40. Koos K., Oláh G., Balassa T., Mihut N., Rózsa M., Ozsvár A., Tasnadi E., Barzó P., Faragó N., Puskás L., Molnár G., Molnár J., Tamás G., Horvath P., Automatic deep learning-driven label-free image-guided patch clamp system. Nat. Commun. 12, 936 (2021). 41. Yip M. C., Gonzalez M. M., Valenta C. R., Rowan M. J. M., Forest C. R., Deep learning-based real-time detection of neurons in brain slices for in vitro physiology. Sci. Rep. 11, 6065 (2021). 42. Mariampillai A., Leung M. K. K., Jarvi M., Standish B. A., Lee K., Wilson B. C., Vitkin A., Yang V. X. D., Optimized speckle variance OCT imaging of microvasculature. Opt. Lett. 35, 1257–1259 (2010). 43. Wijesinghe R. E., Kahatapitiya N. S., Lee C., Han S., Kim S., Saleah S. A., Seong D., Silva B. N., Wijenayake U., Ravichandran N. K., Jeon M., Kim J., Growing trend to adopt speckle variance optical coherence tomography for biological tissue assessments in pre-clinical applications. Micromachines 15, 564 (2024). 44. Zhu Z., Guo S.-Z., Hirdler T., Eide C., Fan X., Tolar J., McAlpine M. C., 3D Printed functional and biological materials on moving freeform surfaces. Adv. Mater. 30, e1707495 (2018). 45. Hartley R. I., In defense of the eight-point algorithm. IEEE Trans. Pattern Anal. Mach. Intell. 19, 580–593 (1997). 46. A. W. Fitzgibbon, “Simultaneous linear estimation of multiple view geometry and lens distortion” in Proceedings of the 2001 IEEE Computer Society Conference on Computer Vision and Pattern Recognition. CVPR 2001 (IEEE, 2001), vol. 1, p. I–I. 47. J. P. Barreto, K. Daniilidis, “Fundamental matrix for cameras with radial distortion” in Tenth IEEE International Conference on Computer Vision (ICCV’05) Volume 1 (IEEE, 2005), vol. 1, pp. 625–632 Vol. 1. 48. M. Lopez, R. Mari, P. Gargallo, Y. Kuang, J. Gonzalez-Jimenez, G. Haro, “Deep single image camera calibration with radial distortion” in 2019 IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR) (IEEE, 2019), pp. 11809–11817. 49. Wang A., Qiu T., Shao L., A simple method of radial distortion correction with centre of distortion estimation. J. Math Imaging. Vis. 35, 165–172 (2009). 50. Pratt V., Direct least-squares fitting of algebraic surfaces. SIGGRAPH Comput. Graph. 21, 145–152 (1987). 51. Brown D. C., Close-Range Camera Calibration. Photogramm. Eng. 37, 855–866 (1971). 52. C. A. V. Aguilera, ndnanfilter.m, MATLAB Central File Exchange; www.mathworks.com/matlabcentral/fileexchange/20417-ndnanfilter-m . 53. D. P. Kingma, J. Ba, Adam: A method for stochastic optimization. arXiv:1412.6980 (2017). 54. S. S. M. Salehi, D. Erdogmus, A. Gholipour, Tversky loss function for image segmentation using 3D fully convolutional deep networks. arXiv:1706.05721 (2017). 55. S. Jadon, “A survey of loss functions for semantic segmentation” in 2020 IEEE Conference on Computational Intelligence in Bioinformatics and Computational Biology (CIBCB) (IEEE, 2020), pp. 1–7. 56. Kodandaramaiah S. B., Franzesi G. T., Chow B. Y., Boyden E. S., Forest C. R., Automated whole-cell patch-clamp electrophysiology of neurons in vivo. Nat. Methods 9, 585–587 (2012). 57. Khan R., Gul B., Khan S., Nisar H., Ahmad I., Refractive index of biological tissues: Review, measurement techniques, and applications. Photodiagnosis Photodyn. Ther. 33, 102192 (2021). Associated Data Supplementary Materials Supplementary Text S1 Figs. S1 to S7 Legends for movies S1 and S2 References Movies S1 and S2
