# 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)

![](/files/-MNJll2G4YwvBY6IwJY_)

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).

![](/files/-MNJll2HrhleNgFs4poh)

We then display this image as a volume in sciview

![](/files/-MNJll2I8MGpk_msGX9M)

![](/files/-MNJll2J7uGOMQB-pnMS)

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.

![](/files/-MNJll2K56GGVa52bhsz)

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.

![](/files/-MNJll2Lg92QaqsucYAP)

![](/files/-MNJll2MzCkYf9Ns-Tvs)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.scenery.graphics/sciview/complex-data/segmentations.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
