> For the complete documentation index, see [llms.txt](https://docs.scenery.graphics/sciview/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.scenery.graphics/sciview/complex-data/segmentations.md).

# 3D Segmentations

We will explore this demo using IntelliJ, partially because the benefit of auto-complete is quite signficant for these more complex tasks. The latest version of this demo can be found [here](https://github.com/scenerygraphics/sciview/blob/master/src/main/java/sc/iview/commands/demo/advanced/ShowSegmentationDemo.java)

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2F2dbd38d83bf0021455a807c67df0defa4d35d369.png?generation=1606666360142580\&alt=media)

This demo begins with a demo image. The details of how this image is generated aren't important, but it creates a tuneable number of spheres in random positions within a `(100,100,100)` image (aka RandomAccessibleInterval).

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2Fef8f2615b2e2a0c7b96b3433b4b8976ac2270c73.png?generation=1606666362130895\&alt=media)

We then display this image as a volume in sciview

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2F22e4c69c09160b1462d747fa531ce14dbd336551.png?generation=1606666364059558\&alt=media)

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2Fef5652ac33d9d63f22d9bd14de5bceaf3ad33dcf.png?generation=1606666366240943\&alt=media)

Now comes a key step, we perform what is called a "Connected Components Analysis" (aka CCA), which assigns all connected pixels to a specific label. Each of these labels represents a segmentation.

Note: one nuance of this is that if 2 of our randomly generated spheres overlap, they will be treated as being connected.

An alternative would have been to use the pixel values of the image to create each `LabelRegion`. However, in practice that is not a luxury that an image analyst has.

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2F2eba621c20890fb2ac1dfe506efd3b0db175ea11.png?generation=1606666361091319\&alt=media)

The next thing to do is to create meshes for each segmentation label that we have created. We do this by looping over all `LabelRegion`s that we've created and computing a mesh.

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2F0a536952d4ad90b38aa6a15781d3c74355827e7c.png?generation=1606666365241522\&alt=media)

![](https://1840025532-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LqBCy3SBefXis0YnrcI%2Fsync%2Fc1a3303ffbd7c28095397aa92e445c3925e90338.png?generation=1606666363243270\&alt=media)
