Hierarchical Feature Selection for Efficient Image Segmentation#
The opencv hfs module contains an efficient algorithm to segment an image. This module is implemented based on the paper Hierarchical Feature Selection for Efficient Image Segmentation, ECCV 2016. The original project was developed by Yun Liu(yun-liu/hfs).
Introduction to Hierarchical Feature Selection#
This algorithm is executed in 3 stages:
In the first stage, the algorithm uses SLIC (simple linear iterative clustering) algorithm to obtain the superpixel of the input image.
In the second stage, the algorithm view each superpixel as a node in the graph. It will calculate a feature vector for each edge of the graph. It then calculates a weight for each edge based on the feature vector and trained SVM parameters. After obtaining weight for each edge, it will exploit EGB (Efficient Graph-based Image Segmentation) algorithm to merge some nodes in the graph thus obtaining a coarser segmentation After these operations, a post process will be executed to merge regions that are smaller then a specific number of pixels into their nearby region.
In the third stage, the algorithm exploits the similar mechanism to further merge the small regions obtained in the second stage into even coarser segmentation.
After these three stages, we can obtain the final segmentation of the image. For further details about the algorithm, please refer to the original paper: Hierarchical Feature Selection for Efficient Image Segmentation, ECCV 2016
Classes#
Name |
Description |
|---|---|
Class cv::hfs::HfsSegment#
#include <opencv2/hfs.hpp>Collaboration diagram for cv::hfs::HfsSegment:
Public Member Functions#
Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Clears the algorithm state. |
|
|
Returns true if the Algorithm is empty (e.g. in the very beginning or after unsuccessful read. |
|
|
Reads algorithm parameters from a file storage. |
|
|
||
|
|
|
|
Stores algorithm parameters in a file storage. |
|
|
Static Public Member Functions#
Static Public Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
|
Loads algorithm from the file. |
|
|
Loads algorithm from a String. |
|
Reads algorithm from the file node. |
Additional Inherited Members#
Protected Member Functions inherited from cv::Algorithm
Return |
Name |
Description |
|---|---|---|
|
Member Function Documentation#
getMinRegionSizeI()#
int cv::hfs::HfsSegment::getMinRegionSizeI()
Python:
cv.hfs.HfsSegment.getMinRegionSizeI() -> retval
getMinRegionSizeII()#
int cv::hfs::HfsSegment::getMinRegionSizeII()
Python:
cv.hfs.HfsSegment.getMinRegionSizeII() -> retval
getNumSlicIter()#
int cv::hfs::HfsSegment::getNumSlicIter()
Python:
cv.hfs.HfsSegment.getNumSlicIter() -> retval
getSegEgbThresholdI()#
float cv::hfs::HfsSegment::getSegEgbThresholdI()
Python:
cv.hfs.HfsSegment.getSegEgbThresholdI() -> retval
getSegEgbThresholdII()#
float cv::hfs::HfsSegment::getSegEgbThresholdII()
Python:
cv.hfs.HfsSegment.getSegEgbThresholdII() -> retval
getSlicSpixelSize()#
int cv::hfs::HfsSegment::getSlicSpixelSize()
Python:
cv.hfs.HfsSegment.getSlicSpixelSize() -> retval
getSpatialWeight()#
float cv::hfs::HfsSegment::getSpatialWeight()
Python:
cv.hfs.HfsSegment.getSpatialWeight() -> retval
performSegmentCpu()#
Mat cv::hfs::HfsSegment::performSegmentCpu(
InputArray src,
bool ifDraw = true )
Python:
cv.hfs.HfsSegment.performSegmentCpu(src[, ifDraw]) -> retval
do segmentation with cpu This method is only implemented for reference. It is highly NOT recommanded to use it.
performSegmentGpu()#
Mat cv::hfs::HfsSegment::performSegmentGpu(
InputArray src,
bool ifDraw = true )
Python:
cv.hfs.HfsSegment.performSegmentGpu(src[, ifDraw]) -> retval
do segmentation gpu
Parameters
src— the input imageifDraw— if draw the image in the returned Mat. if this parameter is false, then the content of the returned Mat is a matrix of index, describing the region each pixel belongs to. And it’s data type is CV_16U. If this parameter is true, then the returned Mat is a segmented picture, and color of each region is the average color of all pixels in that region. And it’s data type is the same as the input image
setMinRegionSizeI()#
void cv::hfs::HfsSegment::setMinRegionSizeI(int n)
Python:
cv.hfs.HfsSegment.setMinRegionSizeI(n)
: set and get the parameter minRegionSizeI. This parameter is used in the second stage mentioned above. After the EGB segmentation, regions that have fewer pixels then this parameter will be merged into it’s adjacent region.
setMinRegionSizeII()#
void cv::hfs::HfsSegment::setMinRegionSizeII(int n)
Python:
cv.hfs.HfsSegment.setMinRegionSizeII(n)
: set and get the parameter minRegionSizeII. This parameter is used in the third stage mentioned above. It serves the same purpose as minRegionSizeI
setNumSlicIter()#
void cv::hfs::HfsSegment::setNumSlicIter(int n)
Python:
cv.hfs.HfsSegment.setNumSlicIter(n)
: set and get the parameter numSlicIter. This parameter is used in the first stage. It describes how many iteration to perform when executing SLIC.
setSegEgbThresholdI()#
void cv::hfs::HfsSegment::setSegEgbThresholdI(float c)
Python:
cv.hfs.HfsSegment.setSegEgbThresholdI(c)
: set and get the parameter segEgbThresholdI. This parameter is used in the second stage mentioned above. It is a constant used to threshold weights of the edge when merging adjacent nodes when applying EGB algorithm. The segmentation result tends to have more regions remained if this value is large and vice versa.
setSegEgbThresholdII()#
void cv::hfs::HfsSegment::setSegEgbThresholdII(float c)
Python:
cv.hfs.HfsSegment.setSegEgbThresholdII(c)
: set and get the parameter segEgbThresholdII. This parameter is used in the third stage mentioned above. It serves the same purpose as segEgbThresholdI. The segmentation result tends to have more regions remained if this value is large and vice versa.
setSlicSpixelSize()#
void cv::hfs::HfsSegment::setSlicSpixelSize(int n)
Python:
cv.hfs.HfsSegment.setSlicSpixelSize(n)
: set and get the parameter slicSpixelSize. This parameter is used in the first stage mentioned above(the SLIC stage). It describes the size of each superpixel when initializing SLIC. Every superpixel approximately has \(slicSpixelSize \times slicSpixelSize\) pixels in the beginning.
setSpatialWeight()#
void cv::hfs::HfsSegment::setSpatialWeight(float w)
Python:
cv.hfs.HfsSegment.setSpatialWeight(w)
: set and get the parameter spatialWeight. This parameter is used in the first stage mentioned above(the SLIC stage). It describes how important is the role of position when calculating the distance between each pixel and it’s center. The exact formula to calculate the distance is \(colorDistance + spatialWeight \times spatialDistance\). The segmentation result tends to have more local consistency if this value is larger.
create()#
static Ptr< HfsSegment > cv::hfs::HfsSegment::create(
int height,
int width,
float segEgbThresholdI = 0.08f,
int minRegionSizeI = 100,
float segEgbThresholdII = 0.28f,
int minRegionSizeII = 200,
float spatialWeight = 0.6f,
int slicSpixelSize = 8,
int numSlicIter = 5 )
Python:
cv.hfs.HfsSegment.create(height, width[, segEgbThresholdI[, minRegionSizeI[, segEgbThresholdII[, minRegionSizeII[, spatialWeight[, slicSpixelSize[, numSlicIter]]]]]]]) -> retval
cv.hfs.HfsSegment_create(height, width[, segEgbThresholdI[, minRegionSizeI[, segEgbThresholdII[, minRegionSizeII[, spatialWeight[, slicSpixelSize[, numSlicIter]]]]]]]) -> retval
: create a hfs object
Parameters
height— the height of the input imagewidth— the width of the input imagesegEgbThresholdI— parameter segEgbThresholdIminRegionSizeI— parameter minRegionSizeIsegEgbThresholdII— parameter segEgbThresholdIIminRegionSizeII— parameter minRegionSizeIIspatialWeight— parameter spatialWeightslicSpixelSize— parameter slicSpixelSizenumSlicIter— parameter numSlicIter
Source file#
The documentation for this class was generated from the following file:
opencv2/hfs.hpp