# Export Brainstorm seeg coordinates to 3D Slicer

**URL:** <https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986>\
**Category:** Support\
**Tags:** segmentation, brain, segmentations, segment-editor\
**Created:** [January 7, 2025, 2:26pm UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986 "2025-01-07T14:26:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephanejean](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephanejean/32/79038_2.png) [@stephanejean](https://discourse.slicer.org/u/stephanejean)\
**Post date:** [January 7, 2025, 2:26pm UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/1 "2025-01-07T14:26:28Z")

</div>

Hello, I have been using 3D slicer for a while now, I would like to export SEEG contact location generate to brainstorm into 3D slicer and convert each contacts into a segment sphere using the xyz coordinates. Is it possible?

I have tried by changing the xyz naming convention into RAS, and then importing the contacts as points using the markups pluggin and it worked, however i can’t transfrom each point into a segment. The markup to model pliggin can only change the points in a connecting curve of tube shape. I want it to remain as location segmented points. Thanks

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 7, 2025, 2:53pm UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/2 "2025-01-07T14:53:34Z")

</div>

Probably the easiest is to describe this using a short Python code snippet. You can generate the code snippet with any AI assistant, you don’t need to know programming or much about Slicer.

For example, I got a working code with giving the following prompts to the free [Microsoft Copilot](https://copilot.microsoft.com):

> write a Python code snippet that converts a markup fiducial list to a segmentation so that at each markup control point position a small sphere shape segment is added

It almost gave correct result, but it hallucinated a non-existent function, so I tried to make correct itself just by copying the error message that I saw in the Python console in Slicer.

> I got the error: AttributeError: ‘vtkSlicerSegmentationsModuleLogicPython.vtkSlicerS’ object has no attribute ‘CreateLabelmapVolumeFromModel’

> I got the error: AttributeError: module ‘slicer.util’ has no attribute ‘createLabelVolumeFromModel’

> I got the error: AttributeError: ‘vtkSegmentationCorePython.vtkSegmentation’ object has no attribute ‘AddSegmentFromClosedSurfaceRepresentation’

> I got the error: AttributeError: module ‘slicer.util’ has no attribute ‘updateSegmentFromModelPolyData’

It still did not find the correct converter function, so at this point I decided that I will point it to the Slicer script repository.

> Use examples on this page: [Script repository — 3D Slicer documentation](https://slicer.readthedocs.io/en/latest/developer_guide/script_repository.html)

It still did not get it right, so I pinpointed the relevant section.

> Use the code snippet in the section “Create segmentation from a model node”

This finally generated working code! It was not perfect in that it created an empty segment for each point, so I asked it to correct itself.

> It created an extra empty segment for each point. Please update the code so that it does not generate those extra empty segments.

Now this generated code that worked perfectly:

```python
import slicer
import vtk

# Create a segmentation node
segmentation_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLSegmentationNode")
segmentation = segmentation_node.GetSegmentation()

# Get the markup fiducial node
markup_node = slicer.util.getNode('F')
n_control_points = markup_node.GetNumberOfFiducials()

# Define sphere parameters
sphere_radius = 5.0 # Adjust the radius as needed
sphere_resolution = 50

# Create a model node for the sphere
sphere_model_node = slicer.mrmlScene.AddNewNodeByClass("vtkMRMLModelNode")
sphere_model_node.SetName("SphereModel")

for i in range(n_control_points):
    # Get the control point position
    position = [0.0, 0.0, 0.0]
    markup_node.GetNthFiducialPosition(i, position)
    
    # Create the sphere
    sphere = vtk.vtkSphereSource()
    sphere.SetCenter(position)
    sphere.SetRadius(sphere_radius)
    sphere.SetThetaResolution(sphere_resolution)
    sphere.SetPhiResolution(sphere_resolution)
    sphere.Update()
    
    # Update the model node with the sphere polydata
    sphere_model_node.SetAndObservePolyData(sphere.GetOutput())
    
    # Add model to segmentation as a new segment
    slicer.modules.segmentations.logic().ImportModelToSegmentationNode(sphere_model_node, segmentation_node)
    
# Remove temporary model node
slicer.mrmlScene.RemoveNode(sphere_model_node)

# Ensure the segmentation displays correctly
segmentation_node.CreateClosedSurfaceRepresentation()

```

While having to copy-paste error messages was slightly annoying and ultimately I gave some hints to the chatbot, the whole thing did not take more than 5 minutes and the generated code works and the code quality is not bad at all. And the nice thing is that if you want to do something more or different then you can just keep asking the chatbot to further modify the code.

---

<div class="post-metadata">

**Author:** ![stephanejean](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephanejean/32/79038_2.png) [@stephanejean](https://discourse.slicer.org/u/stephanejean)\
**Post date:** [January 8, 2025, 1:18am UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/3 "2025-01-08T01:18:26Z")

</div>

I would like to thank you for the quick and informative answer. I am going to try it and let you know. Thanks again

---

<div class="post-metadata">

**Author:** ![stephanejean](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephanejean/32/79038_2.png) [@stephanejean](https://discourse.slicer.org/u/stephanejean)\
**Post date:** [January 8, 2025, 3:54am UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/5 "2025-01-08T03:54:17Z")

</div>

After using my own data and your advice I found this code worked perfectly

---

<div class="post-metadata">

**Author:** ![stephanejean](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephanejean/32/79038_2.png) [@stephanejean](https://discourse.slicer.org/u/stephanejean)\
**Post date:** [January 8, 2025, 3:54am UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/6 "2025-01-08T03:54:27Z")

</div>

import slicer  
import vtk  
import math

# Volume of the sphere

sphere\_volume = 30 # mm³

# Calculate the radius

sphere\_radius = (3 \* sphere\_volume / (4 \* math.pi)) \*\* (1/3)

# Create a segmentation node

segmentation\_node = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLSegmentationNode”)  
segmentation = segmentation\_node.GetSegmentation()

# List of provided positions

positions = [  
(35.49447, 35.492788, -5.868997),  
(38.983289, 35.725376, -6.024056),  
]

# Create spheres and add to segmentation

for i, position in enumerate(positions):  
# Create a sphere model node  
sphere\_model\_node = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLModelNode”)  
sphere\_model\_node.SetName(f"Sphere\_{i}")

```
# Create the sphere
sphere = vtk.vtkSphereSource()
sphere.SetCenter(position)
sphere.SetRadius(sphere_radius)
sphere.SetThetaResolution(50)
sphere.SetPhiResolution(50)
sphere.Update()

# Update the model node with the sphere polydata
sphere_model_node.SetAndObservePolyData(sphere.GetOutput())

# Add model to segmentation as a new segment
slicer.modules.segmentations.logic().ImportModelToSegmentationNode(sphere_model_node, segmentation_node)

```

# Remove temporary model nodes

for i in range(len(positions)):  
node = slicer.mrmlScene.GetFirstNodeByClass(“vtkMRMLModelNode”)  
slicer.mrmlScene.RemoveNode(node)

# Ensure the segmentation displays correctly

segmentation\_node.CreateClosedSurfaceRepresentation()

---

<div class="post-metadata">

**Author:** ![stephanejean](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephanejean/32/79038_2.png) [@stephanejean](https://discourse.slicer.org/u/stephanejean)\
**Post date:** [January 8, 2025, 3:57am UTC](https://discourse.slicer.org/t/export-brainstorm-seeg-coordinates-to-3d-slicer/40986/7 "2025-01-08T03:57:11Z")

</div>

the only issue is that the processing time is extremely long, even the saving of the 3d slicer scene is long.  
Windows 11, 12th Gen Intel(R) Core™ i9-12900 2.40 GHz  
RAM 128 GB  
3D slicer version 5.2.2
