-
Notifications
You must be signed in to change notification settings - Fork 28
Install
Frédéric Jean edited this page Aug 14, 2015
·
7 revisions
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.
- Also needed: Visual C++ 2008 Express Edition with SP1 (http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express).
- Also needed for Python 64 bits: Windows 7 Platform SDK is needed (with some hacks) to compile a 64 bits extension for Python 64 bits (see http://mattptr.net/2010/07/28/building-python-extensions-in-a-modern-windows-environment/ ); A 64 bits version of Numpy is also required; An unofficial release is available at http://www.lfd.uci.edu/~gohlke/pythonlibs/ (the installer contains both the binaries and the headers).
- 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
- 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
```
- 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)