Skip to main content

Documentation Status tests PyPI - Python Version PyPI DOI

Nanomesh banner

Nanomesh

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

Documentation: https://nanomesh.readthedocs.io/en/latest/

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 skimage.data 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.

>>> plane.show()
<AxesSubplot:xlabel='x', ylabel='y'>
drawing

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
<MeshContainer>
  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'}>
drawing

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'>
drawing

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.

Installation

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.

Development

Check out our Contributing Guidelines to get started with development.

Metadata

Release files for nanomesh 0.9.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nanomesh 0.9.1
File Size Uploaded
nanomesh-0.9.1.tar.gz 8.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for nanomesh 0.9.1
File Interpreter ABI Platform
nanomesh-0.9.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 MB

Release files / nanomesh-0.9.1.tar.gz

Download URL nanomesh-0.9.1.tar.gz
Size 8.0 MB
Tags Source
SHA-256 checksum
How to use checksums
b22c7f0bcc819d8819634d1fd03e63ead5329f1642dc05e33a5a10b0fae41a65
BLAKE2b-256 checksum
How to use checksums
3c4670b038885c4ff565c556861fde21a3be886945b29805f58575ef731527ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / nanomesh-0.9.1-py3-none-any.whl

Download URL nanomesh-0.9.1-py3-none-any.whl
Size 7.0 MB
Tags Python 3
SHA-256 checksum
How to use checksums
f5465db869560f522f27d369c24b5e3e8cca3ba204253ef46c0258d4a13eeeb1
BLAKE2b-256 checksum
How to use checksums
46febc11c048b78602912a97dcdb1ad3edde97b2e38e338b228cca832c1ede85
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

0.9.1 This release

2 release files

0.9.0

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page