Code Monkey home page Code Monkey logo

simple_clustering's Introduction

simple_clustering

Build Status Crates.io Docs.rs

Image segmentation library and command line tool using clustering methods.

Currently supported algorithms are the SLIC (simple linear iterative clustering) and SNIC (simple non-iterative clustering) superpixel algorithms. The crate also supports drawing basic contours around the image segments.

Comparison of original and segmented images

To use as a library, add the following to your Cargo.toml. Executable builds can be found at https://github.com/okaneco/simple_clustering/releases.

[dependencies.simple_clustering]
version = "0.2"
default-features = false

Features

  • image segmentation using SNIC and SLIC
  • find mean colors of segmented regions
  • draw contours around segment boundaries
  • command line tool for generating segmented images from JPG/PNG input files

Examples

Images are from the Berkeley Segmentation Dataset and Benchmark unless noted otherwise.

SNIC and SLIC

The algorithm can be selected with the -a option. By default, the algorithm is snic.

simple_clustering -i 295087.jpg
simple_clustering -i 295087.jpg -a slic

The suggested number of superpixels to find is specified with -k or -n. Resulting superpixel counts may be slightly greater or less than this value due to characteristics of seeding or enforcing connectivity of superpixel labels. The default setting is 1000.

simple_clustering -i 295087.jpg -k 200

The -m option is used to control the "compactness" of each superpixel. The number ranges from 1 to 20 with a tradeoff between uniform superpixel size and better boundary adherence. 1 will result in larger and more non-uniform superpixels while 20 will result in more compact and uniform superpixels. By default, -m is set to 10.

simple_clustering -i 55067.jpg -m 1
simple_clustering -i 55067.jpg -m 20

Comparison of compactness parameter, mountains Left image: -m 1. Right image: -m 20.


Contours

The segment color defaults to black, #000, but can be specified with the --segment-color option followed by a 3 or 6 digit hexadecimal RGB color. The following example sets the color to gray, #777. To save the segment contours over the original image data, add the --no-mean flag to skip generating the mean color image.

simple_clustering -i 113016.jpg -k 200 --segments --segment-color 777
simple_clustering -i 113016.jpg -k 200 --segments --no-mean

Comparison of segment paramaters, horses Left image: Segmented image with gray contours. Right image: Superpixel regions drawn over original image data.


Reference

Achanta, R., Shaji, A., Smith, K., Lucchi, A., Fua, P., & Süsstrunk, S. SLIC Superpixels. EPFL Technical Report no. 149300, June 2010.

Achanta, R., Shaji, A., Smith, K., Lucchi, A., Fua, P., & Süsstrunk, S. SLIC Superpixels Compared to State-of-the-art Superpixel Methods. IEEE Transactions on Pattern Analysis and Machine Intelligence, vol. 34, num. 11, p. 2274 – 2282, May 2012.

Achanta, R., & Süsstrunk, S. Superpixels and polygons using simple non-iterative clustering. Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, 2017.

Martin, D., Fowlkes, C., Tal, D., & Malik, J. A Database of Human Segmented Natural Images and its Application to Evaluating Segmentation Algorithms and Measuring Ecological Statistics. Proc. 8th Int'l Conf. Computer Vision, vol. 2, p. 416 – 423, July 2001.

License

This crate is licensed under either

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

simple_clustering's People

Contributors

okaneco avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

simple_clustering's Issues

Very small images may be too small to be seeded

Very small images (like 3x1 images in the doc examples) can potentially be unseeded.

We can try to fallback and fill them with seeds or return an error early. The update to 0.1.1 didn't change behavior but maybe that's something to do for a breaking change in 0.2.0.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.