# Does Meshing.isosurface() work only with the exact value of iso in maching\_cube()

**URL:** <https://discourse.julialang.org/t/does-meshing-isosurface-work-only-with-the-exact-value-of-iso-in-maching-cube/64146>\
**Category:** Visualization\
**Tags:** package\
**Created:** [July 6, 2021, 11:19am UTC](https://discourse.julialang.org/t/does-meshing-isosurface-work-only-with-the-exact-value-of-iso-in-maching-cube/64146 "2021-07-06T11:19:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 6, 2021, 11:19am UTC](https://discourse.julialang.org/t/does-meshing-isosurface-work-only-with-the-exact-value-of-iso-in-maching-cube/64146/1 "2021-07-06T11:19:46Z")

</div>

I tried to use the function `isosurface` with `marching_cube`, from `Meshing.jl`.  
I have volumetric data in an array of size(91, 109, 91), with Float64 values in the interval [-3, 3], and I wanted to get the mesh for the isosurface corresponding to iso=1.25 (a brain).

Inspecting the array ([https://drive.google.com/file/d/12eBKRzlnSD8gZJmpV9ahPmFPK9Mcat4B/view?usp=sharing](https://drive.google.com/file/d/12eBKRzlnSD8gZJmpV9ahPmFPK9Mcat4B/view?usp=sharing))

```julia
findall(x->x==1.25, brain_vol)

```

I get:

```julia
CartesianIndex{3}[]

```

Although no array element has exact this value, I was expecting that calling

```julia
verts, triangles = Meshing.isosurface(brain_vol, MarchingCubes(iso=1.25));

```

to get the brain mesh (because other tools work even in this case), but plotting it I get an empty plot.  
Trying with Python skimage marching\_cube

```julia
verts, triangles= skimage.measure.marching_cubes_lewiner(brain_vol, 1.25)

```

I get:

 ![iso-brain](https://global.discourse-cdn.com/julialang/original/3X/f/d/fd0fc08d1a1ad0e55c60424d6e323aeacd403928.png)

I suspect that the algorithm used by skimage selects values at some distance from the transmitted iso-value.

My question:  
Is there a keyword that must be set when calling `Meshing.isosurface()` to ensure that it generate the right mesh?

```julia
Meshing.isosurface(brain_vol, MarchingCubes(iso=1.25));

```

returns non-empty `verts` and `triangles`, but using almost the same code(Plotly JS vs plotly.py) for visualizing meshes, I get an empty plot with PlotlyJS, that works for any other mesh I tested. Here is the code to get the brain mesh:

```julia
using Meshing
using NPZ
brain_vol = npzread("MNI152.npy")
verts, triangles = Meshing.isosurface(brain_vol, MarchingCubes(iso=1.25));
```

---

<div class="post-metadata">

**Author:** ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Post date:** [July 6, 2021, 4:10pm UTC](https://discourse.julialang.org/t/does-meshing-isosurface-work-only-with-the-exact-value-of-iso-in-maching-cube/64146/2 "2021-07-06T16:10:12Z")

</div>

The isosurface will separate voxels with value \>= 1.25 from those below that number. I suspect that the voxels hold integer values.

---

<div class="post-metadata">

**Author:** ![empet](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/empet/32/221303_2.png) [@empet](https://discourse.julialang.org/u/empet)\
**Post date:** [July 7, 2021, 10:34am UTC](https://discourse.julialang.org/t/does-meshing-isosurface-work-only-with-the-exact-value-of-iso-in-maching-cube/64146/3 "2021-07-07T10:34:35Z")

</div>

The isosurface was not drawn because  
triangles had elements from 1 to N, but for PlotlyJS.jl they must start from 0.  
Thse two lines fixed my issue:

```julia
matr_tri = reshape(reinterpret(Int64, triangles), (3, size(triangles,1)));
matr_tri = matr_tri .- 1

```
