Skip to main content

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

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)

Source distribution for pysnic 1.0.4
File Size Uploaded
pysnic-1.0.4.tar.gz 14.4 kB Details

Built distribution (wheel)

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

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

Release history Release notifications | RSS feed

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.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