1##   OpenCV Hierarchical Feature Selection for Efficient Image Segmentation module
2
3Author and maintainers: Yujun Shi (shiyujun1016@gmail.com), Yun Liu (nk12csly@mail.nankai.edu.cn).
4
5Hierachical Feature Selection (HFS) is a real-time system for image segmentation. It was originally proposed in [1]. Here is the original project website: http://mmcheng.net/zh/hfs/
6
7The algorithm is executed in 3 stages. In the first stage, it obtains an over-segmented image using SLIC(simple linear iterative clustering). In the last 2 stages, it iteratively merges the over-segmented  image with merging method mentioned in EGB(Efficient Graph-based Image Segmentation) and learned SVM parameters.
8
9In our implementation, we wrapped these stages into one single member function of the interface class.
10
11Since this module used cuda in some part of  the implementation, it has to be compiled with cuda support
12
13For more details about the algorithm, please refer to the original paper: [1]
14
15### usage
16
17c++ interface:
18
19```c++
20// read a image
21Mat img = imread(image_path), res;
22int _h = img.rows, _w = img.cols;
23
24// create engine
25Ptr<HfsSegment> seg = HfsSegment::create( _h, _w );
26
27// perform segmentation
28// now "res" is a matrix of indices
29// change the second parameter to "True" to get a rgb image for "res"
30res = seg->performSegmentGpu(img, false);
31```
32
33python interface:
34
35```python
36import cv2
37import numpy as np
38
39img = cv2.imread(image_path)
40
41# create engine
42engine = cv2.hfs.HfsSegment_create(img.shape[0], img.shape[1])
43
44# perform segmentation
45# now "res" is a matrix of indices
46# change the second parameter to "True" to get a rgb image for "res"
47res = engine.performSegmentGpu(img, False)
48```
49
50
51
52### Reference
53
54[1]: M. cheng, Y. Liu, Q. Hou, J. Bian, P. Torr, S. Hu, Z. Tu HFS: Hierarchical Feature Selection for Efficient Image Segmentation ECCV, Oct.2016.