hfs_HfsSegment
import { hfs_HfsSegment } from '@banou/opencv-wasm'Use after await initOpenCV(). See the initialization and named imports guide.
Native object: release it with using or delete(). Factories can return null; check before calling methods. Inherits Algorithm.
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(https://github.com/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
Constructors and members
static create
: create a hfs object param: height: the height of the input image param: width: the width of the input image param: segEgbThresholdI: parameter segEgbThresholdI param: minRegionSizeI: parameter minRegionSizeI param: segEgbThresholdII: parameter segEgbThresholdII param: minRegionSizeII: parameter minRegionSizeII param: spatialWeight: parameter spatialWeight param: slicSpixelSize: parameter slicSpixelSize param: numSlicIter: parameter numSlicIter
create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number, minRegionSizeII: number, spatialWeight: number, slicSpixelSize: number, numSlicIter: number): hfs_HfsSegment | null;8 available overloads
create(height: number, width: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number, minRegionSizeII: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number, minRegionSizeII: number, spatialWeight: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number, minRegionSizeII: number, spatialWeight: number, slicSpixelSize: number): hfs_HfsSegment | null;create(height: number, width: number, segEgbThresholdI: number, minRegionSizeI: number, segEgbThresholdII: number, minRegionSizeII: number, spatialWeight: number, slicSpixelSize: number, numSlicIter: number): hfs_HfsSegment | null;heightheight argument (number).
widthwidth argument (number).
segEgbThresholdIseg egb threshold i argument (number).
minRegionSizeImin region size i argument (number).
segEgbThresholdIIseg egb threshold ii argument (number).
minRegionSizeIImin region size ii argument (number).
spatialWeightspatial weight argument (number).
slicSpixelSizeslic spixel size argument (number).
numSlicIternum slic iter argument (number).
The hfs_HfsSegment | null result.
clone
Create another handle to the same native object. This retains the object without copying its pixels or algorithm state; dispose both handles separately.
clone(): this;The this result.
setSegEgbThresholdI
: 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.
setSegEgbThresholdI(c: number): void;cc argument (number).
getSegEgbThresholdI
Read the seg egb threshold i.
: 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.
getSegEgbThresholdI(): number;The number result.
setMinRegionSizeI
: 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.
setMinRegionSizeI(n: number): void;nn argument (number).
getMinRegionSizeI
Read the min region size i.
: 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.
getMinRegionSizeI(): number;The number result.
setSegEgbThresholdII
: 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.
setSegEgbThresholdII(c: number): void;cc argument (number).
getSegEgbThresholdII
Read the seg egb threshold ii.
: 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.
getSegEgbThresholdII(): number;The number result.
setMinRegionSizeII
: set and get the parameter minRegionSizeII. This parameter is used in the third stage mentioned above. It serves the same purpose as minRegionSizeI
setMinRegionSizeII(n: number): void;nn argument (number).
getMinRegionSizeII
Read the min region size ii.
: set and get the parameter minRegionSizeII. This parameter is used in the third stage mentioned above. It serves the same purpose as minRegionSizeI
getMinRegionSizeII(): number;The number result.
setSpatialWeight
: 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.
setSpatialWeight(w: number): void;ww argument (number).
getSpatialWeight
Read the spatial weight.
: 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.
getSpatialWeight(): number;The number result.
setSlicSpixelSize
: 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.
setSlicSpixelSize(n: number): void;nn argument (number).
getSlicSpixelSize
Read the slic spixel size.
: 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.
getSlicSpixelSize(): number;The number result.
setNumSlicIter
: set and get the parameter numSlicIter. This parameter is used in the first stage. It describes how many iteration to perform when executing SLIC.
setNumSlicIter(n: number): void;nn argument (number).
getNumSlicIter
Read the num slic iter.
: set and get the parameter numSlicIter. This parameter is used in the first stage. It describes how many iteration to perform when executing SLIC.
getNumSlicIter(): number;The number result.
performSegmentGpu
do segmentation gpu param: src: the input image param: ifDraw: 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
performSegmentGpu(src: Mat, ifDraw: boolean): Mat;2 available overloads
performSegmentGpu(src: Mat): Mat;performSegmentGpu(src: Mat, ifDraw: boolean): Mat;srcsrc argument (Mat).
ifDrawif draw argument (boolean).
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
performSegmentCpu
do segmentation with cpu This method is only implemented for reference. It is highly NOT recommanded to use it.
performSegmentCpu(src: Mat, ifDraw: boolean): Mat;2 available overloads
performSegmentCpu(src: Mat): Mat;performSegmentCpu(src: Mat, ifDraw: boolean): Mat;srcsrc argument (Mat).
ifDrawif draw argument (boolean).
The Mat result. Release returned native handles with using or delete(), including handles nested in results.
These signatures describe this package. Upstream documentation can mention optional backends that are absent from this build. Check runtime compatibility before choosing a backend or file format.