Skip to content

Install

Frédéric Jean edited this page Aug 14, 2015 · 7 revisions

Prerequisites

To install PyMeanShift from the source code (source package or Git repository), Python 2.7 (or 3.2) and Numpy development headers are required:

  • On recent Debian-based (ex. Ubuntu) Linux distributions, the Python headers are provided by the package python-dev (2.7) or python3-dev (3.2); The Numpy headers are provided by the package python-numpy-dev (2.7) or python3-numpy-dev (3.2).
  • On recent Redhat-based Linux distributions (ex. Fedora), the Python headers are provided by the package python-devel (2.7) or python3-devel (3.2); The Numpy headers are provided by the package numpy (2.7) or python3-numpy (3.2).
  • On MacOS X, the Python headers are installed during the Python installation process (with the official Python release, not the MacOS X version of Python); The Numpy headers are installed during the Numpy installation process.
  • On Windows, the Python headers are installed during the Python installation process. The Numpy headers are installed during the Numpy installation process.

Build and Install

  1. The Python extension is compiled as follows: * Linux and MacOS X (in a terminal window): bash cd path-to-pymeanshift-sources ./setup.py build * Windows (at the command prompt): bash cd path-to-pymeanshift-sources python setup.py build
  2. The wrapper module and the extension can be installed as follows: * Systemwide, for all users (admin privileges are needed):
    • Linux and MacOS X (in a terminal window):
    sudo ./setup.py install
    • Windows (at the command prompt, from an admin account):
    python setup.py install
* For one user only:
  * **Linux** and **MacOS X** (in a terminal window):
  ```bash
  ./setup.py install --user
  ```
  * **Windows** (at the command prompt):
  ```bash
  python setup.py install --user
  ```
  1. If everything went fine, it should be possible to import the pymeanshift module in Python code. The module provides a function named segment and a class named Segmenter.

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)
Clone this wiki locally