# Segmentation with higher resolution

**URL:** https://discourse.slicer.org/t/segmentation-with-higher-resolution/7495
**Category:** Development
**Tags:** segmentation
**Created:** [July 10, 2019, 1:42pm UTC](https://discourse.slicer.org/t/segmentation-with-higher-resolution/7495 "2019-07-10T13:42:45Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![David\_M](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_m/32/3727_2.png) [@David\_M](https://discourse.slicer.org/u/David_M)
#### Post date: [July 10, 2019, 1:42pm UTC](https://discourse.slicer.org/t/segmentation-with-higher-resolution/7495/1 "2019-07-10T13:42:45Z")

</div>

Hi everyone,

I would like to make a segmentation of the eye, with a resolution of 0.1 mm.  
For this purpose, I would like to start my segmentation from building spheres from python code.

I tried to start from this code

```python
import SampleData
# Load master volume
sampleDataLogic = SampleData.SampleDataLogic()
masterVolumeNode = sampleDataLogic.downloadMRBrainTumor1()
# Create segmentation
segmentationNode = slicer.vtkMRMLSegmentationNode()
slicer.mrmlScene.AddNode(segmentationNode)
segmentationNode.CreateDefaultDisplayNodes() # only needed for display
segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode(masterVolumeNode)
# Create segment sclera
eye = vtk.vtkSphereSource()
eye.SetCenter(30, 68, -31)
eye.SetRadius(12)
eye.Update()
segmentationNode.AddSegmentFromClosedSurfaceRepresentation(eye.GetOutput(), "1_Sclera", [1.0,1.0,0.0])

```

That works, but with a resolution of nearly 1mm.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/3/b334c05fbcff9846a8249f70626e308e78d68681.png)

Then I tried to crop the volume, increasing the resolution (scaling), with success, following [this](https://discourse.slicer.org/t/segmentation-resolution/1394/5) instructions. However, now I don’t know how to link the sphere code to the segmentation with this higher resolution.

Unfortunately, I am not good at programming with python, I tried to find help with the vtk library and tutorials, without success.  
Thanks in advance for your help

---

<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: [July 25, 2019, 4:59am UTC](https://discourse.slicer.org/t/segmentation-with-higher-resolution/7495/2 "2019-07-25T04:59:13Z")

</div>

You did it all right, the only point that was missed that you used the input image resolution as segmentation resolution. The simplest would be to crop&resample the input volume _before_ running your script.

You could [create a new volume](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Create_a_new_volume) with 0.1mm spacing and use that as input of `segmentationNode.SetReferenceImageGeometryParameterFromVolumeNode` to avoid additional step of manual cropping&resampling, but without cropping you would get quite large segmentation volumes (2000-3000 voxels along each axis if you have an image of the entire head) and you may run out of memory and/or segmentation may become slow.

---

<div class="post-metadata">

### Author: ![David\_M](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/david_m/32/3727_2.png) [@David\_M](https://discourse.slicer.org/u/David_M)
#### Post date: [July 25, 2019, 6:50am UTC](https://discourse.slicer.org/t/segmentation-with-higher-resolution/7495/3 "2019-07-25T06:50:08Z")

</div>

It worked 🙂 thanks a lot!
