Exemple #1
0
def segment(image,
            spatial_radius,
            range_radius,
            min_density,
            speedup_level=SPEEDUP_HIGH):
    '''
    Segment the input image (color or grayscale).
    
    Keyword arguments:
    image -- Input image (2-D or 3-D numpy array or compatible).
    spatial_radius -- Spatial radius of the search window (integer).
    range_radius -- Range radius of the search window (float).
    min_density -- The minimum point density of a region in the segmented
                   image (integer).    
    speedup_level -- Filtering optimization level for fast execution
                     (default: high). See SpeedUpLevel.
    
    Return value: tuple (segmented, labels, nb_regions)
    segmented -- Image (Numpy array) where the color (or grayscale) of the
                 regions is the mean value of the pixels belonging to a region.
    labels -- Image (2-D Numpy array, 32 unsigned bits per element) where a
              pixel value correspond to the region number the pixel belongs to.
    nb_regions -- The number of regions found by the mean shift algorithm.
    
    NOTES: To avoid unnecessary image conversions when the function is called,
    make sure the input image array is 8 unsigned bits per pixel and is
    contiguous in memory.    
    
    '''
    return _pymeanshift.segment(image, spatial_radius, range_radius,
                                min_density, speedup_level)
Exemple #2
0
    def __call__(self, image):
        '''
        Segment the input image (color or grayscale).
        
        Keyword arguments:
            image -- Input image (2-D or 3-D numpy array or compatible).
            
        Return value: tuple (segmented, labels, nb_regions)
        segmented -- Image (Numpy array) where the color (or grayscale) of the
                     regions is the mean value of the pixels belonging to a region.
        labels -- Image (2-D Numpy array, 32 unsigned bits per element) where a
                  pixel value correspond to the region number the pixel belongs to.
        nb_regions -- The number of regions found by the mean shift algorithm.
    
        NOTES: To avoid unnecessary image conversions when the function is called,
        make sure the input image array is 8 unsigned bits per pixel and is
        contiguous in memory.    
            
        '''
        if self._spatial_radius is None:
            raise ValueError("Spatial radius has not been set")
        if self._range_radius is None:
            raise ValueError("Range radius has not been set")
        if self._min_density is None:
            raise ValueError("Minimum density has not been set")

        return _pymeanshift.segment(image, self._spatial_radius,
                                    self._range_radius, self._min_density,
                                    self._speedup_level)
Exemple #3
0
 def __call__(self, image):
     '''
     Segment the input image (color or grayscale).
     
     Keyword arguments:
         image -- Input image (2-D or 3-D numpy array or compatible).
         
     Return value: tuple (segmented, labels, nb_regions)
     segmented -- Image (Numpy array) where the color (or grayscale) of the
                  regions is the mean value of the pixels belonging to a region.
     labels -- Image (2-D Numpy array, 32 unsigned bits per element) where a
               pixel value correspond to the region number the pixel belongs to.
     nb_regions -- The number of regions found by the mean shift algorithm.
 
     NOTES: To avoid unnecessary image conversions when the function is called,
     make sure the input image array is 8 unsigned bits per pixel and is
     contiguous in memory.    
         
     '''
     if self._spatial_radius is None:
         raise ValueError("Spatial radius has not been set")
     if self._range_radius is None:
         raise ValueError("Range radius has not been set")
     if self._min_density is None:
         raise ValueError("Minimum density has not been set")        
     
     return _pymeanshift.segment(image, self._spatial_radius, self._range_radius, self._min_density, self._speedup_level)
Exemple #4
0
def segment(image, spatial_radius, range_radius, min_density, speedup_level=SPEEDUP_MEDIUM):
    '''
    Segment the input image (color or grayscale).
    
    Keyword arguments:
    image -- Input image (2-D or 3-D numpy array or compatible).
    spatial_radius -- Spatial radius of the search window (integer).
    range_radius -- Range radius of the search window (float).
    min_density -- The minimum point density of a region in the segmented
                   image (integer).    
    speedup_level -- Filtering optimization level for fast execution
                     (default: high). See SpeedUpLevel.
    
    Return value: tuple (segmented, labels, nb_regions)
    segmented -- Image (Numpy array) where the color (or grayscale) of the
                 regions is the mean value of the pixels belonging to a region.
    labels -- Image (2-D Numpy array, 32 unsigned bits per element) where a
              pixel value correspond to the region number the pixel belongs to.
    nb_regions -- The number of regions found by the mean shift algorithm.
    
    NOTES: To avoid unnecessary image conversions when the function is called,
    make sure the input image array is 8 unsigned bits per pixel and is
    contiguous in memory.    
    
    '''        
    return _pymeanshift.segment(image, spatial_radius, range_radius, min_density, speedup_level)
Exemple #5
0
def segment(img, spatial_radius, range_radius, min_density, return_colors=False) :
	'''
	Segment the image into regions using the Mean Shift algorithm. An image of same 
	shape is returned containing the region id of each pixel.
	'''
	import _pymeanshift as _pms     # @UnresolvedImport

	# Check if the image has the minimum size for the algorithm to run properly 
	w, h, c = img.shape      # @UnusedVariable
	if (w <= 2*range_radius) or (h <= 2*range_radius) :
		segmented_img = np.zeros((w,h), np.int)
		labels_img = np.zeros((w,h), np.int)
		nregions = 1
		
	else:
		segmented_img, labels_img, nregions = _pms.segment(img, spatial_radius, range_radius, min_density)
	
	if return_colors :
		return segmented_img, labels_img, nregions
	else :
		return labels_img
Exemple #6
0
def segment(image, spatial_radius, range_radius, min_density):
    return _pymeanshift.segment(image, spatial_radius, range_radius,
                                min_density, _pymeanshift.SPEEDUP_HIGH)
Exemple #7
0
def segment(image, spatial_radius, range_radius, min_density):
    return _pymeanshift.segment(image, spatial_radius, range_radius, min_density, _pymeanshift.SPEEDUP_HIGH)