Skip to main content

SNIC superpixels algorithm

Project description

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

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

pysnic-1.0.4.tar.gz (14.4 kB view details)

Uploaded Source

Built Distribution

pysnic-1.0.4-py3-none-any.whl (18.1 kB view details)

Uploaded Python 3

File details

Details for the file pysnic-1.0.4.tar.gz.

File metadata

  • Download URL: pysnic-1.0.4.tar.gz
  • Upload date:
  • Size: 14.4 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pysnic-1.0.4.tar.gz
Algorithm Hash digest
SHA256 bde5cfe607b00650c8b5ef7674ed031236a599e2d8ce19061f40109c0b954fb9
MD5 ed9fa0d2f3bd883f9602c593c7d361b0
BLAKE2b-256 638ccd3036fe602b42a17a78cdf4fd2a6309dbe8acc7500ae6e6054b5d6bd0f5

See more details on using hashes here.

File details

Details for the file pysnic-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pysnic-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 18.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pysnic-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 14157b52d9d0e99e40721ce1236cd3a1929ff5f9f79ce243300f3ea8429957a9
MD5 df72b03c2cb646dd26faa7f8823fe5e8
BLAKE2b-256 90e72f02ee637f0c4b0c481c107d0e5e076d0f842d67725a3748d536e1f8af36

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page