# Grow from seeds function produces wrong data

**URL:** <https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329>\
**Category:** Support\
**Tags:** segmentation\
**Created:** [June 30, 2023, 7:17pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329 "2023-06-30T19:17:13Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [June 30, 2023, 7:17pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/1 "2023-06-30T19:17:13Z")

</div>

This image shows the segmentations I have drawn.

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

However, after I grow from seeds, it gives me something completely wrong. What am I doing wrong here?

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

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [July 1, 2023, 3:01pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/2 "2023-07-01T15:01:58Z")

</div>

Are you trying to segment the lungs with 3D Slicer´s grow from seeds effect?  
[This YouTube video](https://www.youtube.com/watch?v=9iiOBmaP8bA) may help.

However, this is a time-consuming process. Alternatively, you could use modules from the Chest Imaging Platform, LungCTAnalyzer, or the TotalSegmentator extension for that purpose.

---

<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 1, 2023, 4:55pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/3 "2023-07-01T16:55:46Z")

</div>

The segmentation looks correct for these inputs. It seems that you did not add seeds into regions that you are _not_ interested in, therefore your other segments leaked into the unclaimed area. You can fix that by adding an “other” segment and use it to draw scribbles in all areas that you want to be ignored. Once the segmentation is completed, you can delete this segment. For segmenting textureless structures (that are typical in phantoms like yours and sometimes appear in clinical images in regions filled with fluid or air) you may want to increase `Seed locality` value a little bit (0.1-0.5 may be enough) to reduce leaking.

Since your phantom looks completely noise-free (is it an _in silico_ phantom - a computationally generated image?), probably the simplest is to segment it using `Threshold` effect.

---

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [July 5, 2023, 3:19pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/4 "2023-07-05T15:19:29Z")

</div>

I am trying to use the totalSegmentator extension, but I get reproduceable data that is, for lack of a better word, wonky.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/0/902d27d29f2ea00b354bbf5c342132f6637339cd.png)

Can you help me out with this? Thanks

---

<div class="post-metadata">

**Author:** ![rbumm](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/rbumm/32/9404_2.png) [@rbumm](https://discourse.slicer.org/u/rbumm)\
**Post date:** [July 6, 2023, 5:50am UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/5 "2023-07-06T05:50:24Z")

</div>

We can probably help but need the dataset somehow. What is it exactly do you need to segment?

---

<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 6, 2023, 2:01pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/6 "2023-07-06T14:01:47Z")

</div>

The dataset looks so unrealistic that I’m not surprised that most tools fails to deal with it. There is no natural texture or noise in the image. There are gaps (e.g., below the skin). It is not even clear what imaging modelity it is supposed to be (looks more like an MRI, but what kind?). The orientation is incorrect (rotated by 90 degrees in axial view, sagittal/coronal are mixed up). Probably the physical size is off, too (you can check by making some measurements in Markups module).

Is it some _in silico_ phantom? What software have you created it with? What is your overall goal?

---

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [July 6, 2023, 4:13pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/7 "2023-07-06T16:13:18Z")

</div>

Okay, I’ll describe my project here.

This model is taken from the virtual family project. This one is duke. My goal is to take the model from sim4life and make it into a CAD model (.stl, .step, etc.).

How I went about this was extracting the sim4life data into matlab as sigma, rho, and epsilon variables. In Matlab, I converted it into a matrix and nii file. (I also corrected the orientation of the model by transposing and flipping the matrix). With the nii file, I took it into 3d slicer to try to segment it and export as a CAD viewable file. I believe it is an MRI scan.

---

<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 6, 2023, 4:30pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/8 "2023-07-06T16:30:28Z")

</div>

The simplest way to create meshes from such data set is to save it as a labelmap image (each value of the matrix is an integer value that specifies what segment that voxel belongs to). You can then load the image file as a segmentation (by choosing “Segmentation” in “Add data” window) and click “Show 3D” to generate meshes.

If you are interested in free, open solutions, you can use Slicer (and various automatic segmentation tools, such as TotalSegmentator extension) for creating patient models and FEBio for biomechanical simulation (or revive the Slicer-based [Bender](https://www.kitware.com/bender-2-0/) project for posing patient models).

---

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [July 6, 2023, 4:34pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/9 "2023-07-06T16:34:47Z")

</div>

Thanks for you help!

How would I go about creating this labelmap image? Is it a process that I do in matlab? Is there a website documenting this process?

---

<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 6, 2023, 4:42pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/10 "2023-07-06T16:42:55Z")

</div>

Yes, you do it in Matlab. All you need to do is to use an integer value type.

---

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [July 6, 2023, 4:46pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/11 "2023-07-06T16:46:54Z")

</div>

Ok, so I take the original image matrix and change its type to integer? Wouldn’t this truncate many values and break the image?

---

<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 6, 2023, 5:30pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/12 "2023-07-06T17:30:56Z")

</div>

Make sure voxels corresponding to a segment all have the same value. Truncation is no problem, as long as voxel of different structures don’t get assigned to the same value.

---

<div class="post-metadata">

**Author:** ![LavaBunny](https://avatars.discourse-cdn.com/v4/letter/l/8797f3/32.png) [@LavaBunny](https://discourse.slicer.org/u/LavaBunny)\
**Post date:** [July 6, 2023, 6:22pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/13 "2023-07-06T18:22:03Z")

</div>

It worked well, thank you very much. However, the skin layer seems to be inconsistent. Sometimes muscle shows through or bones. Is this a model issue or can this be fixed in software?

---

<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 6, 2023, 6:39pm UTC](https://discourse.slicer.org/t/grow-from-seeds-function-produces-wrong-data/30329/14 "2023-07-06T18:39:19Z")

</div>

The “skin” barely exists, it looks like some disconnected single-voxel boundary that is just thrown on top of the other structures. Maybe you can try to hide all the other segments, in masking settings allow overlap (to prevent the “skin” from overwriting internal structures), then make the skin boundary thicker using Margin effect, and then fill what is inside the skin, using Islands effect.
