Abstract
Instance segmentation of anatomical structures from medical images can help enhance clinical outcomes such as disease diagnosis, surgical planning accuracy, and treatment efficacy. However, since segmentation masks often lack point-to-point correspondence between patients, instance segmentation masks may not be directly applicable for clinical studies that require measurement of medical parameters defined on an anatomical shape atlas. For such applications, meshes with correspondence between patients are preferred representations of object geometries. The conversion from segmentation masks to meshes can be error-prone due to segmentation artifacts, and therefore, it is desirable to directly obtain mesh representations of object geometries from medical image data, bypassing segmentation masks. In this work, we propose novel attention-based neural networks for geometry reconstruction and error estimation, which offers a direct pathway from medical images to high-quality mesh representations. We introduce an innovative attention-based feature extraction network and incorporate image self-attention and shape self-attention with cross-attention between them to capture consistent features. Based on the extracted features, we develop a geometry reconstruction network that deforms a mesh template to reconstruct the geometry of the object, which automatically ensures mesh correspondence. In addition, we design a shape error estimation network to evaluate the reliability of the output from geometry reconstruction, that is, to estimate the point-to-point error of a reconstructed geometry. We demonstrate our approach for the application of lumbar spine geometry reconstruction and compare our geometry reconstruction network with UNet++, UTNet, Swin UnetTR, SLT-Net, and nnUNet, using the Dice metric. In this application, our geometry reconstruction network has much higher accuracy and artifact-free segmentation results, and our shape error estimation network facilitates quality control for clinical use. The source code is available at https://github.com/linchenq/SPIE2025-GoemReconstruction-with-ShapeErrorNet.
Keywords: lumbar spine, MRI, geometry reconstruction, image segmentation, error estimation, self-attention
1. INTRODUCTION
Instance segmentation of anatomical structures from medical images can help improve clinical outcomes such as disease diagnosis, surgical planning precision, and treatment efficacy.1 For example, accurate segmentation of the lumbar spine can help assess the state of spinal degeneration,2 and automated liver segmentation provides surgeons with an overview of the spatial relationships of the liver organ and its internal structures and reduces the risks of surgical resection,3 and segmentation of cardiac structures can help detect earlier cardiac abnormalities.4 Because of the lack of point-to-point correspondence between pixel-level segmentation masks of different patients, instance segmentation masks may not be applicable for clinical studies that require measurement of medical parameters defined on an anatomical shape atlas. For clinical applications that require stress or hemodynamic analysis,5–7 segmentation masks need to be converted to meshes. Furthermore, if the mesh correspondence is established (i.e., the same number of nodes/points and elements with the same connectivity), then detailed geometry/stress analysis and comparison6,8 can be directly performed at the population level, and virtual clinical trials on virtual patients can be facilitated.9
Currently, deep learning approaches, particularly convolutional neural networks (CNNs) and transformers, have demonstrated superior performance across various medical tasks, including medical image segmentation. Networks such as UNet++,10 UTNet,11 Swin UnetTR,12 SLT-Net,13 nnUNet14 have been proposed for image segmentation on different medical imaging modalities and organs. As illustrated in Fig.1, despite improved accuracy, these segmentation models often generate artifacts such as fragmented, overlapping, and inconsistent regions.15 For applications that need mesh representations of object geometries, the conversion from segmentation masks to meshes can be error-prone because of the common segmentation artifacts. Thus, it is desirable to directly obtain the mesh representation of an object’s geometry from medical image data, bypassing the segmentation masks.
Figure 1.

The comparison between segmentation and geometry reconstruction methods.
In this work, our main contributions are as follows. (1) We propose an innovative attention-based neural network as the backbone for feature extraction, which utilizes image self-attention and shape self-attention as well as cross-attention between image and shape to capture consistent features. (2) Based on the feature extraction network, we design a geometry reconstruction network that deforms a mesh template in the input image, and the deformed mesh is the reconstructed geometry of the object, which automatically ensures the mesh correspondence between different patients. (3) Also based on the feature extraction network, we design a shape error estimation network to estimate the error of a reconstructed geometry on the point level, i.e., evaluating the reliability of the output from the geometry reconstruction network. We demonstrate our approach on the application of lumbar spine geometry reconstruction from mid-sagittal MR images, and compare our geometry reconstruction network with UNet++, UTNet, Swin UnetTR, SLT-Net, and nnUNet, using the Dice metric. In this application, our geometry reconstruction network has much higher accuracy and artifact-free segmentation results, and our shape error estimation network facilitates quality control for clinical use.
2. METHODS
2.1. Architecture
As illustrated in Fig.1, the goal of our application is to reconstruct the lumbar spine geometries from 2D mid-sagittal MR images and then measure the medical parameters and estimate the error of any geometry. For this purpose, we designed a novel attention-based network for geometry reconstruction with error estimation. We developed the shape feature extraction network to capture consistent features from both image and shape input. Then, based on the extracted features, we designed the geometry reconstruction network to deform the input template and get the reconstructed geometry.
The architecture of the shape feature extraction network is depicted in Fig. 2. Our network applies two groups of CNN layers as pixel/region-level feature extractors at two spatial resolutions (512×512 and 128×128). The network utilizes self-attention on non-overlapping patches from the low-resolution CNN feature map, producing a sequence of image features with aggregated global context. Our approach uses a normalized mesh grid for image position embedding, on which each patch is centered on one of the mesh grid points. Then, shape self-attention and cross-attention between images and shapes are performed to cross-examine and fuse information from individual patches of the feature maps and points of the shape.
Figure 2.

The architecture of out feature extraction network.
The input shape (i.e., a template shape) is used to sample the low-resolution CNN feature map, where each point on the shape is assigned with specific image features by bilinear interpolation. This ensures that the shape is represented not only by a set of spatial points but also by their embeddings/features. The cross-attention acts as a bridge between image and shape. Whereas the sampling method can filter irrelevant information during the initialization, this method is confined to its perception field, the area of neighbor pixels. Our network utilizes cross-attention where each shape token (i.e., point with features) serves as a query vector to align itself with the entire image tokens (patches), thereby fostering the long-range dependencies. This approach allows our network to gather proper information from relevant image patches, even if the shape is initially far from the true shape. The final output of the feature extraction network is a shape feature matrix that contains information about the shape and image.
The structure of our geometry reconstruction network is shown in Fig.3. Given the input image and template shape, the output of the feature extraction network is used to predict the displacement vectors at the points of the template shape, and an intermediate shape is obtained after the first deformation. Then, this intermediate shape is further deformed by using the higher-resolution CNN feature. The instance segmentation masks are directly obtained from the reconstructed shape. We note that shape, mesh, and geometry are used interchangeably in this paper.
Figure 3.

The architecture of our geometry reconstruction network that deforms a mesh/shape template.
2.2. Attention with Relative Position Embedding
The attention mechanisms in ViT16 and its successors assume that tokens are located on a regular grid and therefore could not be used in our networks, in which points of a shape may be located at non-integer locations. To enable the new attention modules in our networks, we developed new equations for attention with relative position embedding. Let and represent two matrices containing all input tokens. In our application, and can be the same (i.e., ), representing image or shape tokens, which are used for image or shape self-attention. Also, and can be different: representing image tokens and representing shape tokens, which is used for cross-attention in our application. The attention score matrix can be redefined as:
| (1) |
Here are individual linear projections to generate query and key embeddings that can be replaced by MLPs in the implementation. and are two matrices encoding relative positions between tokens. The function combines the original query and key matrix with the corresponding position matrix into a new query and key matrix using Fourier characteristics.17
To better explain the above Equation (1), we redefine query and key by incorporating sinusoidal functions to effectively extract relative position information. After the calculation, we derive that each entry, , of the attention score matrix, , is proportional to the scalar dot product of query and key vectors :
| (2) |
Here, each entry of the attention score matrix is a function of the relative position vector . More details are shown in our previous work.15 We propose this novel relative position embedding to improve the performance of our geometry reconstruction method compared to absolute position embedding. We will show an ablation study in our future work.
2.3. Shape Error Estimation Network
The structure of the shape error estimation network is shown in Fig.4. It takes an image and an arbitrary shape as the inputs, and estimates the point-level difference between the input shape and the ground truth shape of the object in the image. This predicted error depicts the reliability of each point in the input shape that may be the output of a network for geometry reconstruction. During model training, the input shape is randomly selected from the training dataset and then added with noise, and the MSE loss is used.
Figure 4.

The architecture of our proposed network for shape error estimation.
3. EXPERIMENTS
3.1. Evaluation of the Geometry Reconstruction Network
In our experiment, we used the public dataset SSMSpine,15 which has 7000 images for training, 250 images for validation, and 2500 images for testing. To facilitate the comparison with image segmentation models, we converted each output mesh of our geometry reconstruction network into a segmentation mask and calculated the Dice Score. We used Pytorch 2.0.018 for model implementation. The training process for each model was completed within 24 hours on a single NVIDIA RTX A6000.
We conduct qualitative and quantitative evaluations on the accuracy and quality of the predicted segmentation of six vertebrae and five intervertebral discs. We utilize Dice Score (a.k.a. Dice Similarity Coefficient, DSC, ranging from 0 to 1, the higher the better) to measure the spatial overlap of predicted and ground-truth segmentation masks numerically.
Tab.1 and Fig.5 show the performance of our network and the other five well-known models. Our proposed model demonstrates superior performance in all the listed spinal areas.
Table 1.
Dice Score Coefficient percentage score (%) comparison between our model and baselines. ”L1” ”L5” represent vertebrae bodies, ”D1” ”D5” represent disks, and “S1” denotes the first sacral vertebra. Red color highlights the best score among the methods.
| Network | Ours | nnUNet | SLT-Net | Swin UnetTR | UTNet | UNet++ |
|---|---|---|---|---|---|---|
| L1 | 97.8±1.0 | 95.1±4.0 | 91.9±11.2 | 93.1±8.4 | 82.7±28.3 | 65.1±40.8 |
| L2 | 97.9±0.9 | 97.1±1.7 | 96.7±2.4 | 96.3±3.3 | 80.8±31.0 | 69.5±36.4 |
| L3 | 96.9±2.4 | 94.7±10.3 | 93.9±12.7 | 93.3±14.5 | 84.1±27.0 | 70.0±31.7 |
| L4 | 97.2±1.1 | 95.2±6.4 | 92.5±18.4 | 95.3±5.1 | 85.7±27.9 | 66.9±37.2 |
| L5 | 97.5±1.0 | 94.9±6.0 | 94.6±8.9 | 94.7±4.9 | 91.1±16.2 | 81.4±28.0 |
| S1 | 96.8±1.7 | 93.8±5.9 | 92.4±8.0 | 93.1±5.5 | 91.3±9.0 | 90.5±13.2 |
| D1 | 96.3±1.7 | 94.0±3.2 | 92.7±7.2 | 93.1±5.4 | 76.8±31.0 | 64.6±40.3 |
| D2 | 96.2±2.4 | 95.0±3.5 | 93.8±4.9 | 94.2±4.2 | 80.6±28.2 | 72.0±31.8 |
| D3 | 95.1±3.2 | 92.9±7.8 | 89.9±18.7 | 92.0±9.2 | 83.9±27.0 | 63.1±38.2 |
| D4 | 95.0±2.4 | 91.2±9.5 | 90.4±11.8 | 90.4±6.8 | 85.4±20.6 | 72.9±31.2 |
| D5 | 96.0±1.9 | 92.4±6.4 | 91.1±11.4 | 91.3±6.2 | 90.7±11.8 | 87.2±20.3 |
| Average | 96.6±1.2 | 94.2±6.6 | 92.7±9.1 | 93.3±5.0 | 84.8±19.8 | 73.0±23.3 |
Figure 5.

Examples of semantic segmentation using different methods, Objects (vertebra or disc) are shown in different colors as indicated by the right-side colormap: (a) an input image (b) ground truth (c) our network (d) UNet++ (e) UTNet (f) Swin UnetTR (g) SLT-Net (h) nnUNet
3.2. Evaluation of the Shape Error Estimation Network
We used the shape error estimation network to estimate the output errors of the geometry reconstruction network on the test set of the SSMSpine dataset. We computed different correlation coefficients between the estimated errors and the true errors. The Pearson correlation coefficient is 0.9254, and the Spearman’s rank correlation coefficient is 0.8989, which shows that our shape error estimation network has high performance on error estimation.
3.3. Medical Parameter Measurement and Quality Control
All of the current machine learning (ML) models for segmentation and geometry reconstruction, including our models, are purely data-driven and therefore have no guarantee in output accuracy. Thus, the output shape from an ML model has to be checked by a human operator for clinical use. To reduce human negligence, those shapes with larger (estimated) errors will be checked first when the operator is vigilant, and those with smaller (estimated) errors will be checked later when the operator possibly becomes fatigued. Motivated by this, we conducted the experiment on the test set of the SSMSpine dataset to show how the shape error estimation network can facilitate quality control for medical parameter measurement.
In our experiment, we focused on the diameters and heights of the vertebrae and the disks of the lumbar spine. As illustrated in Fig.6, the vertebrae are measured by diameters and heights, including UVD, LVD, MVD, AVH, PVH, and MVH, while disks are measured by height only, including ADH, MDH, and PDH.
Figure 6.

Definitions of the medical parameters on an anatomical shape atlas. Corner vertices (, and ), laying at the intersections between a vertebra and disc, are identified as landmarks. Midpoints (, and ) on edges are also identified. For vertebrae, we introduce three main parameters, including upper, lower and middle vertebra diameters (UVD, LVD, MVD). Additionally, we measure the height of anterior, posterior and middle vertebra (AVH, PVH, MVH) to comprehensively depict the vertebra in cause of its abrasion. Similar to vertebrae, we introduce three main parameters including anterior, posterior and middle disc heights (ADH, PHD, MDH) to measure disc dimensions.
Tab. 2 shows the relative error of various medical parameters of patients in the test set.
Table 2.
The relative error’s comparison of different metrics at various levels. UVD, LVD, MVD, AVH, PVH, MVH, ADH, PDH, and MDH are represented across different levels.
| UVD | LVD | MVD | AVH | PVH | MVH | ADH | PDH | MDH | |
|---|---|---|---|---|---|---|---|---|---|
| 100 | 1.75 | 2.23 | 2.44 | 2.10 | 2.24 | 2.06 | 4.48 | 7.23 | 4.73 |
| 80 | 1.54 | 2.04 | 2.20 | 1.90 | 2.06 | 1.73 | 3.91 | 6.57 | 4.21 |
| 60 | 1.49 | 1.95 | 2.02 | 1.80 | 1.98 | 1.59 | 3.68 | 6.42 | 4.05 |
| 40 | 1.47 | 1.87 | 1.89 | 1.70 | 1.95 | 1.46 | 3.41 | 6.45 | 3.94 |
| 20 | 1.45 | 1.77 | 1.76 | 1.56 | 1.89 | 1.33 | 3.10 | 6.43 | 3.67 |
The reconstructed shapes in the test set are ranked by the errors predicted by the shape error estimation network. These medical parameters can be evaluated using of the shapes with the lowest (estimated) errors. Here we take as 20, 40, 60, 80, and 100. To enhance clarity, we have converted the relative error to the percentage error (%) in Table 2. It is evident that the relative error of the medical parameters decreases when samples with higher (estimated) errors are filtered out.
4. CONCLUSION
In this work, we propose an innovative neural network architecture for geometry reconstruction from medical images, which utilizes image self-attention and shape self-attention as well as cross-attention between image and shape, to capture consistent features. In addition, we propose a shape error estimation network, sharing the same feature extraction network with the geometry reconstruction network. The experiment on the SSMSpine dataset of lumbar spine MR images demonstrates that our geometry reconstruction network has higher accuracy and is free of artifacts, and our shape error estimation network facilitates quality control for clinical use. Our approach could be extended to the geometry reconstruction of other human organs, which is our ongoing work.
ACKNOWLEDGMENT
This work was supported in part by the NIH grant R01HL158829.
Footnotes
SOURCE CODE
The source code of this study is publicly available at this GitHub repository: https://github.com/linchenq/SPIE2025-GoemReconstruction-with-ShapeErrorNet.
REFERENCES
- [1].Litjens G, Kooi T, Bejnordi BE, Setio AAA, Ciompi F, Ghafoorian M, Van Der Laak JA, Van Ginneken B, and Sánchez CI, “A survey on deep learning in medical image analysis,” Medical image analysis 42, 60–88 (2017). [DOI] [PubMed] [Google Scholar]
- [2].Pfirrmann CW, Metzdorf A, Zanetti M, Hodler J, and Boos N, “Magnetic resonance classification of lumbar intervertebral disc degeneration,” spine 26(17), 1873–1878 (2001). [DOI] [PubMed] [Google Scholar]
- [3].Alirr OI and Rahni AAA, “Survey on liver tumour resection planning system: steps, techniques, and parameters,” Journal of Digital Imaging 33(2), 304–323 (2020). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [4].Bruns S, Wolterink JM, van den Boogert TP, Runge JH, Bouma BJ, Henriques JP, Baan J, Viergever MA, Planken RN, and Išgum I, “Deep learning-based whole-heart segmentation in 4d contrast-enhanced cardiac ct,” Computers in biology and medicine 142, 105191 (2022). [DOI] [PubMed] [Google Scholar]
- [5].Gu W, Zhu Q, Gao X, and Brown MD, “Simulation of the progression of intervertebral disc degeneration due to decreased nutritional supply,” Spine 39(24), E1411–E1417 (2014). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [6].Liang L, Liu M, Martin C, Elefteriades JA, and Sun W, “A machine learning approach to investigate the relationship between shape features and numerically predicted risk of ascending aortic aneurysm,” Biomechanics and modeling in mechanobiology 16, 1519–1533 (2017). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [7].Hoeijmakers M, Waechter-Stehle I, Weese J, and Van de Vosse F, “Combining statistical shape modeling, cfd, and meta-modeling to approximate the patient-specific pressure-drop across the aortic valve in real-time,” International journal for numerical methods in biomedical engineering 36(10), e3387 (2020). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [8].Campbell J and Petrella A, “Automated finite element modeling of the lumbar spine: using a statistical shape model to generate a virtual population of models,” Journal of biomechanics 49(13), 2593–2599 (2016). [DOI] [PubMed] [Google Scholar]
- [9].Craig M, Gevertz JL, Kareva I, and Wilkie KP, “A practical guide for the generation of model-based virtual clinical trials,” Frontiers in Systems Biology 3, 1174647 (2023). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [10].Zhou Z, Rahman Siddiquee MM, Tajbakhsh N, and Liang J, “Unet++: A nested u-net architecture for medical image segmentation,” in [Deep Learning in Medical Image Analysis and Multimodal Learning for Clinical Decision Support: 4th International Workshop, DLMIA 2018, and 8th International Workshop, ML-CDS 2018, Held in Conjunction with MICCAI 2018, Granada, Spain, September 20, 2018, Proceedings 4], 3–11, Springer; (2018). [DOI] [PMC free article] [PubMed] [Google Scholar]
- [11].Gao Y, Zhou M, and Metaxas DN, “Utnet: a hybrid transformer architecture for medical image segmentation,” in [Medical Image Computing and Computer Assisted Intervention–MICCAI 2021: 24th International Conference, Strasbourg, France, September 27–October 1, 2021, Proceedings, Part III 24], 61–71, Springer; (2021). [Google Scholar]
- [12].Hatamizadeh A, Nath V, Tang Y, Yang D, Roth HR, and Xu D, “Swin unetr: Swin transformers for semantic segmentation of brain tumors in mri images,” in [International MICCAI brainlesion workshop], 272–284, Springer; (2021). [Google Scholar]
- [13].Feng K, Ren L, Wang G, Wang H, and Li Y, “Slt-net: A codec network for skin lesion segmentation,” Computers in Biology and Medicine 148, 105942 (2022). [DOI] [PubMed] [Google Scholar]
- [14].Isensee F, Jaeger PF, Kohl SA, Petersen J, and Maier-Hein KH, “nnu-net: a self-configuring method for deep learning-based biomedical image segmentation,” Nature methods 18(2), 203–211 (2021). [DOI] [PubMed] [Google Scholar]
- [15].Chen J, Qian L, Ma L, Urakov T, Gu W, and Liang L, “Evaluation of deep neural network models for instance segmentation of lumbar spine mri,” bioRxiv, 2024–04 (2024). [DOI] [PubMed] [Google Scholar]
- [16].Dosovitskiy A, “An image is worth 16×16 words: Transformers for image recognition at scale,” arXiv preprint arXiv:2010.11929 (2020). [Google Scholar]
- [17].Tancik M, Srinivasan P, Mildenhall B, Fridovich-Keil S, Raghavan N, Singhal U, Ramamoorthi R, Barron J, and Ng R, “Fourier features let networks learn high frequency functions in low dimensional domains,” Advances in neural information processing systems 33, 7537–7547 (2020). [Google Scholar]
- [18].Paszke A, Gross S, Massa F, Lerer A, Bradbury J, Chanan G, Killeen T, Lin Z, Gimelshein N, Antiga L, et al. , “Pytorch: An imperative style, high-performance deep learning library,” Advances in neural information processing systems 32 (2019). [Google Scholar]
