Skip to content

alexlouden/image-segmentation

Repository files navigation

Image segmentation

Image segmentation web service designed for hosting on Heroku.

The API is inspired by imgix - you pass in the image url (optionally urlencoded), control the algorithm with query parameters, and recieve a segmented image as the response (or a JSON formatted error). This allows you to embed it in a web page, or play with the algorithm in your browser without having to install any software.

https://segment-image.herokuapp.com/<image_url>?cluster_method=kmeans&num_clusters=10

The image above on the right is generated by the following URL (open it in your browser and try changing the parameters!):

https://segment-image.herokuapp.com/http://i.imgur.com/hsiR4hV.jpg?cluster_method=meanshift&quantile=0.015&colour_space=ycrcb

The service supports the following parameters:

Parameter Description
cluster_method ward, meanshift or kmeans
colour_space rgb, hsv, hls, ycrcb, lab or luv
num_clusters integer between 1 and 100, e.g. 5 (required with ward and kmeans)
quantile a float between 0 and 1, e.g. 0.01 (required with meanshift)

Ward is interesting, because it's configured with connectivity constraints - it'll cluster colours together by region. It's also the slowest algorithm, so may timeout (after ~25 seconds).

Deployment

Deploy

Notes

Configure Redis to evict the less recently used keys first:

heroku redis:maxmemory --policy allkeys-lru

Gallery


Method Meanshift quantile=0.07 Meanshift quantile=0.15
RGB
HSV
HLS
YCrCb
LAB
LUV
Method K-Means num_clusters=4 K-means num_clusters=8
RGB
HSV
HLS
YCrCb
LAB
LUV
Method Ward num_clusters=6 Ward num_clusters=15
RGB
HSV
HLS
YCrCb
LAB
LUV