Giter Club home page Giter Club logo

pymeanshift's Introduction

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

pymeanshift's People

Contributors

fjean avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pymeanshift's Issues

Is there a way to get array of segments?

Is there a way to get an array of segments (instead just segmented image)? 
Looks like my request could be satisfied by c++ methods GetBoundaries and 
GetRegions. But how can I access them via python?

Original issue reported on code.google.com by [email protected] on 8 May 2013 at 10:46

Return list of regions.

The example returns the number of regions (number_regions).
How do I return the list of these regions to process one by one?

cv2.cv.cvmat VS cv.cvmat

What steps will reproduce the problem?
1. try the sample example in the project home page

What is the expected output? What do you see instead?

The function should return the segmented image.

when executing the simple example

import cv
from numpy import *
import pymeanshift as pms

name = "path to image"
im = cv.LoadImageM(name)
(segmentedImage, labelsImage, numberRegions) = pms.segmentMeanShift(im)


The following exception occurs

Traceback (most recent call last):
  File "meanshift.py", line 9, in <module>
    (segmentedImage, labelsImage, numberRegions) = pms.segmentMeanShift(im)
  File "/usr/local/lib/python2.7/dist-packages/pymeanshift.py", line 151, in segmentMeanShift
    nbRegion = _segmentMeanShiftImpl(inputImageMat, colorImageMat, labelImageMat, sigmaS, sigmaR, minRegion, speedUpLevel)
TypeError: %%typemap: could not convert input argument to an CvMat

i have printed the type of cvmat in line 151 and it was cv2.cv.mat could that 
be the problem ?

What version of the product are you using? On what operating system?
opencv : opencv 2.3.1
os : ubuntu 11.10


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 1 May 2012 at 11:56

may got numpy error.

Hello!
I recently updated my anaconda and it upgraded numpy version to 1.8.1.
and I got this error when I call "_pymeanshift.segment(image, spatial_radius, range_radius, min_density, speedup_level)" in pymeanshift.py to use "segment" function

Error: NotImplementedError: PyArray_FromDims: use PyArray_SimpleNew.

Is this due to the depency of numpy?

thank you!

Failed to build when 'bash build'

When bash setup.py build it will failed:
`` raise RuntimeError("Error: Failed to import Numpy ({}). Please check that Numpy is installed on your system.".format(exc))'Change it topython setup.py build` and everything goes well

Installation issue

Hi
Using this great tool for a long time but recently with new win 10 OS setup, I can’t figure problem with Visual C++ 2008 express Prerequisite, wasn’t able to find the right pieces. installation wiki has wrong or 404 link. It can be fixed? Please

what does the parameter min_density actually mean?

Only spatial radius hs and range radius hr are talked in the original paper, but it seems the min_density in the pymeanshift package does exert influence on the segmentation results. I am wondering what is the role of this parameter and why it is not mentioned in the original paper? The spatial radius and range radius used here is the same described in the original paper?

Thanks any guys providing any insights!

Colorspace Specification

I have a doubt regarding the returned segmented image. Is it in the LUV colorspace or does it return segmented image in the RGB colorspace ?

Where are the Clusters Locations?

I applied the code on my image and i wanted to know the locations of each cluster to apply some operations on some clusters , where could i get them ?

clusterslocation

declare minimum segment size

Hi
There is a way to define smallest segment size ?
as i play with parameters it will produce a few segment with very small size that i am unable to merge with a neighbor segment.
thanks for all

merge regions

Hi
may i ask how i can merge/remove regions?
there is a few micro region produced over the image which i want to remove or merge.
thanks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.