pyhaze


Namepyhaze JSON
Version 0.1.3 PyPI version JSON
download
home_pagehttps://github.com/dfsp-spirit/pyhaze
SummaryFast smoothing of per-vertex data on triangular meshes.
upload_time2022-12-10 20:49:59
maintainer
docs_urlNone
authorTim Schaefer
requires_python
licenseMIT License Copyright (c) 2018 Tim Schäfer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords mesh triangular-mesh smoothing overlay per-vertex data mesh descriptor haze neuroimaging mri brain
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyhaze
Fast smoothing of per-vertex data on triangular meshes for Python.

[![PyPI version](https://badge.fury.io/py/pyhaze.svg)](https://badge.fury.io/py/pyhaze)
[![Anaconda-Server Badge](https://anaconda.org/dfspspirit/pyhaze/badges/version.svg)](https://anaconda.org/dfspspirit/pyhaze)


## About

This package package performs smoothing of per-vertex data on [triangular meshes](https://en.wikipedia.org/wiki/Triangle_mesh). Such smoothing is typically used to reduce high-frequency noise and improve signal-to-noise ration (SNR). The algorithm for iterative nearest-neighbor smoothing is trivial, but involves nested tight loops, which are very slow in Python, so this package calls into C++ via [pybind11](https://github.com/pybind/pybind11) to achieve high performance.

![Figure 1, Showing a brain mesh with an overlay, before and after smoothing.](./web/pyhaze.png?raw=true "Per-vertex data on a brain mesh before (left) and after (right) smoothing.")

**Fig.1**: *Noisy per-vertex data on a brain mesh (left), and the same data after smoothing (right). White represents NA values.*

This is a Python implementation of the [haze package for R](https://github.com/dfsp-spirit/haze). The haze website offers a more detailed explanation of the motivation and use cases.


## Installation

Via pip:

```shell
pip install pyhaze
```

Alternatively, if you want to use `conda`:

```shell
conda install -c dfspspirit pyhaze
```

## Usage

### Example 1: Smooth data on a mesh given as a vertex index list

Here is a simple example using the `pyhaze.smooth_pvd` function.

```python
import pyhaze
import numpy as np

vertices, faces = pyhaze.construct_cube()

pvd_data = np.arange(len(vertices), dtype=float)
smoothed_data = pyhaze.smooth_pvd(vertices, faces, pvd_data.tolist(), num_iter=5)
```

A note on the mesh representation used, so you can replace the `vertices` and `faces` with your own triangular mesh:

* `vertices` is a list of lists of `float`, with dimension `N, 3` for `N` vertices. So the outer list has length `N`. The 3 columns (length of all inner lists) are the x,y,z coordinates for each vertex.
* `faces` is a list of lists of `int`, with dimension `M, 3` for `M` faces. So the outer list has length `M`. The 3 columns (length of all inner lists) are the 3 vertices (given as indices into `vertices`) making up the respective triangular face.


### Example 2: Smooth data on a mesh given as an adjacency list

For very large meshes, it pays off to pre-compute the adjacency list of the mesh with a fast method, such as with the `igl` Python package, which provides Python bindings for libigl, and use the `pyhaze.smooth_pvd_adj` function.

```python
import pyhaze
import numpy as np
import igl

vertices, faces = pyhaze.construct_cube()

pvd_data = np.arange(len(vertices), dtype=float)
faces_igl = np.array(faces).reshape(-1, 3).astype(np.int64)
mesh_adj = igl.adjacency_list(faces_igl)  # Compute adjacency list with igl.
res = pyhaze.smooth_pvd_adj(mesh_adj, pvd_data.tolist(), num_iter=5)
```

See the [unit tests](./python/tests/test_pyhaze.py) for more examples.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/dfsp-spirit/pyhaze",
    "name": "pyhaze",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "mesh,triangular-mesh,smoothing,overlay,per-vertex data,mesh descriptor,haze,neuroimaging,MRI,brain",
    "author": "Tim Schaefer",
    "author_email": "Tim Schaefer <ts+code@rcmd.org>",
    "download_url": "https://files.pythonhosted.org/packages/d2/90/d6c80deffec81f62da5166c4633a7aecebd1c9592eccabeb7051158389b0/pyhaze-0.1.3.tar.gz",
    "platform": null,
    "description": "# pyhaze\nFast smoothing of per-vertex data on triangular meshes for Python.\n\n[![PyPI version](https://badge.fury.io/py/pyhaze.svg)](https://badge.fury.io/py/pyhaze)\n[![Anaconda-Server Badge](https://anaconda.org/dfspspirit/pyhaze/badges/version.svg)](https://anaconda.org/dfspspirit/pyhaze)\n\n\n## About\n\nThis package package performs smoothing of per-vertex data on [triangular meshes](https://en.wikipedia.org/wiki/Triangle_mesh). Such smoothing is typically used to reduce high-frequency noise and improve signal-to-noise ration (SNR). The algorithm for iterative nearest-neighbor smoothing is trivial, but involves nested tight loops, which are very slow in Python, so this package calls into C++ via [pybind11](https://github.com/pybind/pybind11) to achieve high performance.\n\n![Figure 1, Showing a brain mesh with an overlay, before and after smoothing.](./web/pyhaze.png?raw=true \"Per-vertex data on a brain mesh before (left) and after (right) smoothing.\")\n\n**Fig.1**: *Noisy per-vertex data on a brain mesh (left), and the same data after smoothing (right). White represents NA values.*\n\nThis is a Python implementation of the [haze package for R](https://github.com/dfsp-spirit/haze). The haze website offers a more detailed explanation of the motivation and use cases.\n\n\n## Installation\n\nVia pip:\n\n```shell\npip install pyhaze\n```\n\nAlternatively, if you want to use `conda`:\n\n```shell\nconda install -c dfspspirit pyhaze\n```\n\n## Usage\n\n### Example 1: Smooth data on a mesh given as a vertex index list\n\nHere is a simple example using the `pyhaze.smooth_pvd` function.\n\n```python\nimport pyhaze\nimport numpy as np\n\nvertices, faces = pyhaze.construct_cube()\n\npvd_data = np.arange(len(vertices), dtype=float)\nsmoothed_data = pyhaze.smooth_pvd(vertices, faces, pvd_data.tolist(), num_iter=5)\n```\n\nA note on the mesh representation used, so you can replace the `vertices` and `faces` with your own triangular mesh:\n\n* `vertices` is a list of lists of `float`, with dimension `N, 3` for `N` vertices. So the outer list has length `N`. The 3 columns (length of all inner lists) are the x,y,z coordinates for each vertex.\n* `faces` is a list of lists of `int`, with dimension `M, 3` for `M` faces. So the outer list has length `M`. The 3 columns (length of all inner lists) are the 3 vertices (given as indices into `vertices`) making up the respective triangular face.\n\n\n### Example 2: Smooth data on a mesh given as an adjacency list\n\nFor very large meshes, it pays off to pre-compute the adjacency list of the mesh with a fast method, such as with the `igl` Python package, which provides Python bindings for libigl, and use the `pyhaze.smooth_pvd_adj` function.\n\n```python\nimport pyhaze\nimport numpy as np\nimport igl\n\nvertices, faces = pyhaze.construct_cube()\n\npvd_data = np.arange(len(vertices), dtype=float)\nfaces_igl = np.array(faces).reshape(-1, 3).astype(np.int64)\nmesh_adj = igl.adjacency_list(faces_igl)  # Compute adjacency list with igl.\nres = pyhaze.smooth_pvd_adj(mesh_adj, pvd_data.tolist(), num_iter=5)\n```\n\nSee the [unit tests](./python/tests/test_pyhaze.py) for more examples.\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2018 Tim Sch\u00e4fer  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Fast smoothing of per-vertex data on triangular meshes.",
    "version": "0.1.3",
    "split_keywords": [
        "mesh",
        "triangular-mesh",
        "smoothing",
        "overlay",
        "per-vertex data",
        "mesh descriptor",
        "haze",
        "neuroimaging",
        "mri",
        "brain"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "bbf0b3b8647c6d818611c39edecc5220",
                "sha256": "a4dc565f890ea6f1d03661210ad4197d87c95603a6fec4077d8c86891ca4265f"
            },
            "downloads": -1,
            "filename": "pyhaze-0.1.3.tar.gz",
            "has_sig": false,
            "md5_digest": "bbf0b3b8647c6d818611c39edecc5220",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 1587494,
            "upload_time": "2022-12-10T20:49:59",
            "upload_time_iso_8601": "2022-12-10T20:49:59.540756Z",
            "url": "https://files.pythonhosted.org/packages/d2/90/d6c80deffec81f62da5166c4633a7aecebd1c9592eccabeb7051158389b0/pyhaze-0.1.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-10 20:49:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "dfsp-spirit",
    "github_project": "pyhaze",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "appveyor": true,
    "lcname": "pyhaze"
}
        
Elapsed time: 0.02652s