Skip to main content

Creates 3d meshes from microscopy experimental data

Project description

Documentation Status tests PyPI - Python Version PyPI DOI

Nanomesh banner


Nanomesh is a Python workflow tool for generating meshes from 2D and 3D image data. It has an easy-to-use API that can help process and segment image data, generate quality meshes (triangle / tetrahedra), and write the data to many mesh formats. Nanomesh also contains tools to inspect the meshes, visualize them, and generate cell quality metrics.

  • Easy-to-use Python API
  • Segment and mesh 2D or 3D image data
  • Mesh visualization
  • Calculate and plot cell metrics
  • Export to many mesh formats


Try nanomesh in your browser!

Generate a 2D mesh Calculate mesh metrics
Generate a 2D mesh Calculate mesh metrics

Show me an example!

This example shows the workflow for generating a mesh from segmented data, and demonstrates a few of the features of Nanomesh. It uses a synthetic binary image with several rounded blob-like objects generated by skimage.

>>> from import binary_blobs
>>> from nanomesh import Image
>>> blobs = binary_blobs(length=100, volume_fraction=0.25, seed=2102)
>>> plane = Image(blobs)
>>> print(plane)
Plane(shape=(100, 100), range=(False,True), dtype=bool)

Image is essentially a container for a numpy array with some methods for image segmentation and visualization.

<AxesSubplot:xlabel='x', ylabel='y'>

Generating a mesh from image data is simple in Nanomesh using Plane.generate_mesh(). The options opts are passed to the triangulation function (nanomesh.triangulate). In this example, we use q30 to generate a quality mesh with minimum angles of 30°, and a50 to limit the triangle size to 50 pixels.

The returned mesh is a MeshContainer that contains the generated triangles and line segments.

>>> mesh = plane.generate_mesh(opts='q30a10')
>>> mesh
  Number of points: 932
  Number of cells:
    triangle: 1754
    line: 2685
  Point data: physical
  Cell data: physical
  Field data: feature, background

In the next cell, we plot the triangles.

>>> mesh.plot('triangle')
<AxesSubplot:title={'center':'triangle mesh'}>

With the metrics submodule, Nanomesh can also calculate cell quality metrics and show them as a colored triangle or histogram plot.

>>> from nanomesh import metrics
>>> triangle_mesh = mesh.get('triangle')
>>> metrics.histogram(triangle_mesh, metric='radius_ratio')
<AxesSubplot:title={'center':'Histogram of radius ratio'}, xlabel='Radius ratio', ylabel='frequency'>

Nanomesh uses meshio to write data to most meshing formats.

>>> mesh.write('mesh.vtk')
Warning: VTK requires 3D points, but 2D points given. Appending 0 third component.

That's it! There is a lot more that Nanomesh can do, check out the examples for an overview.


One of the goals for Nanomesh is that it is easy to install. This means that all dependencies are available from PyPi.

If you use conda, it is advised to create a new environment:

conda create -n nanomesh python=3.9
conda activate nanomesh

Install nanomesh:

pip install nanomesh

For the full installation instructions, see the installation guidelines.


Nanomesh does not have any hard version constraints. For development, it is still useful to have a consistent environment. Therefore, Nanomesh uses a constraints file (constraints.txt) which pins the version requirements.

The constraints are automatically updated and tested every month. Note that in case you run into issues, you may also try to install Nanomesh with constraints file.

Install nanomesh using the development dependencies:

pip install -e .[develop] -c constraints.txt

Running the tests using pytest:


Linting and checks are done using pre-commit:


Building the docs:

make html --directory docs

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nanomesh-0.9.0.tar.gz (8.0 MB view hashes)

Uploaded source

Built Distribution

nanomesh-0.9.0-py3-none-any.whl (7.0 MB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page