The segraph library provides modules for creating graphs from SLIC segments. This can be used with PyStruct library for image segmentation using CRF.
These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See examples to see a quick example.
You will need to have NumPY installed on your system. The segraph library was built with Python 2.7, keeping in mind the stability with Python 3+, but it is not guranteed.
pip install numpy
There are multiple ways to install segraph on your system:
segraph is now available at https://pypi.python.org/pypi/segraph/0.5
1. Download the tar/zip from https://pypi.python.org/pypi/segraph/0.5
2. Move the package to your desired location / python version, and unzip the archive.
Optionally, if you have a linux-based machine (Ubuntu/OSX):
tar xvzf segraph-0.x.tar.gz -C /path/to/desireddirectory
3. Migrate to the segraph folder, and run
python setup.py install
pip install segraph
To upgrade,
pip install --upgrade segraph
segraph can be very helpful for creating graphs from SLIC segmented images (superpixels). Here is an example usage:
from skimage.segmentation import slic
from skimage.util import img_as_float
from skimage import io as skimageIO
from segraph import create_graph
import numpy as np
image = img_as_float(skimageIO.imread("segraph/data/flowers.png"))
segments = slic(image, n_segments=500, sigma=1.0)
# Create graph of superpixels
vertices, edges = create_graph(segments)
# Compute centers:
gridx, gridy = np.mgrid[:segments.shape[0], :segments.shape[1]]
centers = dict()
for v in vertices:
centers[v] = [gridy[segments == v].mean(), gridx[segments == v].mean()]
segraph can be used with PyStruct library for image segmentation using CRF.
You are welcome to send a pull-request.
Thanks to all the contributors for making it even more awesome !
- @pinkfloyd06
- Abhinandan Dubey - @alivcor - Human Interaction Lab, Stony Brook University
This project is licensed under the GNU General Public License v3 - see the LICENSE.md file for details