Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: haesleinhuepf/napari-process-points-and-surfaces
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 0.5.0
Choose a base ref
...
head repository: haesleinhuepf/napari-process-points-and-surfaces
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: main
Choose a head ref
  • 9 commits
  • 5 files changed
  • 1 contributor

Commits on Apr 12, 2023

  1. Copy the full SHA
    1b046b8 View commit details
  2. Copy the full SHA
    f966fc3 View commit details
  3. Copy the full SHA
    98e22bc View commit details
  4. corrected test result

    haesleinhuepf committed Apr 12, 2023
    Copy the full SHA
    779a6f7 View commit details
  5. Merge pull request #78 from haesleinhuepf/labeled-surfaces

    Labeled surfaces
    haesleinhuepf authored Apr 12, 2023
    Copy the full SHA
    35a192f View commit details

Commits on Apr 22, 2023

  1. Copy the full SHA
    4b61d89 View commit details

Commits on Mar 8, 2024

  1. Update README.md

    haesleinhuepf authored Mar 8, 2024
    Copy the full SHA
    490a2b2 View commit details

Commits on Apr 28, 2024

  1. Copy the full SHA
    d427108 View commit details
  2. Copy the full SHA
    788ec4f View commit details
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -59,11 +59,10 @@ To visualize measurements on the surface, just double-click on the table column

## Installation

You can install `napari-process-points-and-surfaces` via mamba/conda and pip:
You can install `napari-process-points-and-surfaces` via mamba/conda:

```
mamba install vedo vtk libnetcdf=4.7.4 -c conda-forge
pip install napari-process-points-and-surfaces
mamba install vedo=2022.4.1 napari-process-points-and-surfaces -c conda-forge
```

### Troubleshooting: Open3d installation
@@ -82,6 +81,7 @@ There are other napari plugins with similar / overlapping functionality
* [napari-pymeshlab](https://www.napari-hub.org/plugins/napari-pymeshlab)
* [napari-pyclesperanto-assistant](https://www.napari-hub.org/plugins/napari-pyclesperanto-assistant)
* [napari-stress](https://www.napari-hub.org/plugins/napari-stress)
* [surforama](https://github.com/cellcanvas/surforama)

And there is software for doing similar things:
* [meshlab](https://www.meshlab.net/)
19 changes: 16 additions & 3 deletions napari_process_points_and_surfaces/__init__.py
Original file line number Diff line number Diff line change
@@ -263,13 +263,15 @@ def invert_faces(surface: "napari.types.SurfaceData", viewer: "napari.Viewer" =

@register_function(menu="Surfaces > Create surface from all labels (marching cubes, scikit-image, nppas)")
@time_slicer
def all_labels_to_surface(labels: "napari.types.LabelsData", viewer: "napari.Viewer" = None) -> "napari.types.SurfaceData":
def all_labels_to_surface(labels: "napari.types.LabelsData", add_label_id_as_value:bool = False, viewer: "napari.Viewer" = None) -> "napari.types.SurfaceData":
"""
Turn a set of labels into a surface using the marching cubes algorithm
Parameters
----------
labels_data:napari.types.LabelsData
add_label_id_as_value: bool, optional
if True, will give the same label value to the surface vertices it had in the label image
"""
import vedo
from skimage.measure import marching_cubes
@@ -281,15 +283,26 @@ def all_labels_to_surface(labels: "napari.types.LabelsData", viewer: "napari.Vie

# Create a surface for every label
mesh_list = []
for label in np.unique(labels)[:-1]:
all_values = []
for label in np.unique(labels)[1:]:
print("label", label)
verts, faces, normals, values = marching_cubes(labels==label)
if add_label_id_as_value:
all_values = all_values + (np.ones_like(verts[:,0]) * label).tolist()
print("unique labels:", np.unique(all_values))
mesh = vedo.mesh.Mesh((verts, faces))
mesh_list.append(mesh)

# merge the meshes; label is stored in `mesh.pointdata['OriginalMeshID']`
mesh = vedo.merge(mesh_list, flag=True)

return to_napari_surface_data(mesh)
surface = to_napari_surface_data(mesh)
surface = invert_faces(surface)

if add_label_id_as_value:
surface = set_vertex_values(surface, all_values)

return surface
#(mesh.points(), np.asarray(mesh.faces()), mesh.pointdata['OriginalMeshID'])

# alias
2 changes: 2 additions & 0 deletions napari_process_points_and_surfaces/_quantification.py
Original file line number Diff line number Diff line change
@@ -360,6 +360,8 @@ def set_vertex_values(surface: "napari.types.SurfaceData", values) -> "napari.ty
"""
from ._vedo import SurfaceTuple

values = np.asarray(values)

num_vertices = len(surface[0])
num_values = len(values)
if num_vertices != num_values:
2 changes: 2 additions & 0 deletions napari_process_points_and_surfaces/_tests/test_function.py
Original file line number Diff line number Diff line change
@@ -35,6 +35,8 @@ def test_something():
labels = label(nuclei > 20000)

surface = all_labels_to_surface(labels)
surface = all_labels_to_surface(labels, add_label_id_as_value=False)
surface = all_labels_to_surface(labels, add_label_id_as_value=True)
surface = label_to_surface(labels, 3)

surface = largest_label_to_surface(labels)
Original file line number Diff line number Diff line change
@@ -34,7 +34,7 @@ def test_connected_components():
surface = nppas.all_labels_to_surface(image)
connected_components = nppas.connected_component_labeling(surface)

assert len(np.unique(connected_components[2])) == 3
assert len(np.unique(connected_components[2])) == 2

def test_decimate():
import napari_process_points_and_surfaces as nppas