kharvd / pymeanshift

Python Module for Mean Shift Image Segmentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

PyMeanShift is a Python module/extension for segmenting images using the mean shift algorithm. The PyMeanShift module/extension has been designed to use Numpy arrays, which makes it compatible with the OpenCV module "cv2" and the PIL module.

The mean shift algorithm and its C++ implementation are by Chris M. Christoudias and Bogdan Georgescu. The PyMeanShift extension provides a Python interface to the meanshift C++ implementation using Numpy arrays. For more information, see the wiki page on Implementation Notes.

Installation instructions can be found on the Install wiki page. Examples of mean shift image segmentation with different parameters values are presented on the Examples wiki page.

Code example with OpenCV:

import cv2
import pymeanshift as pms

original_image = cv2.imread("example.png")

(segmented_image, labels_image, number_regions) = pms.segment(original_image, spatial_radius=6, 
                                                              range_radius=4.5, min_density=50)

Code example with PIL:

from PIL import Image
import pymeanshift as pms

original_image = Image.open("example.png")

(segmented_image, labels_image, number_regions) = pms.segment(original_image, spatial_radius=6, 
                                                              range_radius=4.5, min_density=50)

Code example using the Segmenter class:

import pymeanshift as pms

# [...]
# load image in "original_image"
# [...]

my_segmenter = pms.Segmenter()

my_segmenter.spatial_radius = 6
my_segmenter.range_radius = 4.5
my_segmenter.min_density = 50

(segmented_image, labels_image, number_regions) = my_segmenter(original_image)
Original image Segmented image

About

Python Module for Mean Shift Image Segmentation

License:GNU General Public License v3.0


Languages

Language:C++ 96.7%Language:Python 2.9%Language:C 0.4%