PySNIC
Python-only implementation of the SNIC superpixels algorithm (https://www.epfl.ch/labs/ivrl/research/snic-superpixels/).
from pysnic.algorithms.snic import snic
from pysnic.algorithms.polygonize import polygonize
from pysnic.algorithms.ramerDouglasPeucker import RamerDouglasPeucker
# compute segmentation from image
segmentation, distance_map, centroids = snic(
lab_image, 500, 0.01,
update_func=lambda processed_pixels: print("processed %05.2f%%" % (processed_pixels * 100 / number_of_pixels)))
# compute polygonization from segmentation
rdp = RamerDouglasPeucker(10)
graphs = polygonize(segmentation, seeds, rdp)
See the examples folder for a minimal and more advanced example of the SNIC algorithm, as well as a graph extraction and polygonization.
Installing PySNIC
Install PySNIC using pip:
pip install pysnic
Technical details
The algorithm in this repository differs from the originally described algorithm to improve performance:
- Adding elements to the candidate queue is a costly operation. We therefore try to reduce the number queue insertions.
- Introducing a distance map: The algorithm maintains a distance map which stores the closest candidate distance. This allows prechecking, if another candidate is already registered with a smaller distance, before adding it to the queue.
- Removed normalization factors from metric calculation, as they do not change the item ordering.
Performance
This repository contains a python only implementation. Due to large numbers of single-pixel image accesses the python internal bounds-checking is likely to slow down the runtime compared to a C/C++ implementation.
Since the algorithm performs large amounts of single pixel accesses, the runtime is greatly reduced by passing
'normal' python arrays (in contrast to using numpy.ndarrays or PIL.images) to the snic-method.
Dataformats
Pixel positions are expected to be [x,y] integer coordinates. The coordinate frame for edge positions is offset by 0.5.
(Convert edge positions to image coordinates by adding 0.5). Images are expected to be 3d row-major raw python
arrays (image[row][column][features]).
Publications
The SNIC algorithm implemented in this package is based on the following publication:
@inproceedings{snic_cvpr17,
author = {Achanta, Radhakrishna and Susstrunk, Sabine},
title = {Superpixels and Polygons using Simple Non-Iterative Clustering},
booktitle = {IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
year = {2017}
}
Repository
This package is maintained under https://github.com/MoritzWillig/pysnic
License
MIT License see LICENSE.md
Metadata
Release files for pysnic 1.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysnic-1.0.4.tar.gz | 14.4 kB | Without provenance | Details for pysnic-1.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysnic-1.0.4-py3-none-any.whl | Python 3 | none | any | Details for pysnic-1.0.4-py3-none-any.whl |
Total release size: 32.5 kB
Release files / pysnic-1.0.4.tar.gz
| Download URL | pysnic-1.0.4.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bde5cfe607b00650c8b5ef7674ed031236a599e2d8ce19061f40109c0b954fb9
|
|
BLAKE2b-256 checksum How to use checksums |
638ccd3036fe602b42a17a78cdf4fd2a6309dbe8acc7500ae6e6054b5d6bd0f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Release files / pysnic-1.0.4-py3-none-any.whl
| Download URL | pysnic-1.0.4-py3-none-any.whl |
|---|---|
| Size | 18.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
14157b52d9d0e99e40721ce1236cd3a1929ff5f9f79ce243300f3ea8429957a9
|
|
BLAKE2b-256 checksum How to use checksums |
90e72f02ee637f0c4b0c481c107d0e5e076d0f842d67725a3748d536e1f8af36
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.7.0 requests/2.22.0 setuptools/51.3.3 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
|
Security for pysnic 1.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.