Skip to content

segmentation_IntelligentScissorsMB

Computational photographyclassOpenCV 5.0.0
import { segmentation_IntelligentScissorsMB } from '@banou/opencv-wasm'

Use after await initOpenCV(). See the initialization and named imports guide.

ARGUMENTSConstructor or factory
CLASSsegmentation_IntelligentScissorsMB
RETURN TYPEOwned native handle
Call structure. A void return can still write to destination arguments. The parameter descriptions define inputs, outputs and ownership.

Native object: release it with using or delete(). Factories can return null; check before calling methods.

Intelligent Scissors image segmentation

This class is used to find the path (contour) between two points which can be used for image segmentation.

Usage example:

Reference: <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.138.3811&rep=rep1&type=pdf">"Intelligent Scissors for Image Composition"</a> algorithm designed by Eric N. Mortensen and William A. Barrett, Brigham Young University [Mortensen95intelligentscissors]

Constructors and members

static new

Create an owned segmentation_IntelligentScissorsMB object. Release native handles with using or delete().

new(): segmentation_IntelligentScissorsMB;
Returns

The segmentation_IntelligentScissorsMB 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;
Returns

The this result.

setWeights

Specify weights of feature functions

Consider keeping weights normalized (sum of weights equals to 1.0) Discrete dynamic programming (DP) goal is minimization of costs between pixels.

setWeights(weight_non_edge: number, weight_gradient_direction: number, weight_gradient_magnitude: number): segmentation_IntelligentScissorsMB;
weight_non_edge

Specify cost of non-edge pixels (default: 0.43f)

weight_gradient_direction

Specify cost of gradient direction function (default: 0.43f)

weight_gradient_magnitude

Specify cost of gradient magnitude function (default: 0.14f)

Returns

The segmentation_IntelligentScissorsMB result.

setGradientMagnitudeMaxLimit

Specify gradient magnitude max value threshold

Zero limit value is used to disable gradient magnitude thresholding (default behavior, as described in original article). Otherwize pixels with gradient magnitude >= threshold have zero cost.

Note: Thresholding should be used for images with irregular regions (to avoid stuck on parameters from high-contract areas, like embedded logos).

setGradientMagnitudeMaxLimit(gradient_magnitude_threshold_max: number): segmentation_IntelligentScissorsMB;
2 available overloads
setGradientMagnitudeMaxLimit(): segmentation_IntelligentScissorsMB;
setGradientMagnitudeMaxLimit(gradient_magnitude_threshold_max: number): segmentation_IntelligentScissorsMB;
gradient_magnitude_threshold_max

Specify gradient magnitude max value threshold (default: 0, disabled)

Returns

The segmentation_IntelligentScissorsMB result.

setEdgeFeatureZeroCrossingParameters

Switch to "Laplacian Zero-Crossing" edge feature extractor and specify its parameters

This feature extractor is used by default according to article.

Implementation has additional filtering for regions with low-amplitude noise. This filtering is enabled through parameter of minimal gradient amplitude (use some small value 4, 8, 16).

Note: Current implementation of this feature extractor is based on processing of grayscale images (color image is converted to grayscale image first).

Note: Canny edge detector is a bit slower, but provides better results (especially on color images): use setEdgeFeatureCannyParameters().

setEdgeFeatureZeroCrossingParameters(gradient_magnitude_min_value: number): segmentation_IntelligentScissorsMB;
2 available overloads
setEdgeFeatureZeroCrossingParameters(): segmentation_IntelligentScissorsMB;
setEdgeFeatureZeroCrossingParameters(gradient_magnitude_min_value: number): segmentation_IntelligentScissorsMB;
gradient_magnitude_min_value

Minimal gradient magnitude value for edge pixels (default: 0, check is disabled)

Returns

The segmentation_IntelligentScissorsMB result.

setEdgeFeatureCannyParameters

Switch edge feature extractor to use Canny edge detector

Note: "Laplacian Zero-Crossing" feature extractor is used by default (following to original article)

See: Canny

setEdgeFeatureCannyParameters(threshold1: number, threshold2: number, apertureSize: number, L2gradient: boolean): segmentation_IntelligentScissorsMB;
3 available overloads
setEdgeFeatureCannyParameters(threshold1: number, threshold2: number): segmentation_IntelligentScissorsMB;
setEdgeFeatureCannyParameters(threshold1: number, threshold2: number, apertureSize: number): segmentation_IntelligentScissorsMB;
setEdgeFeatureCannyParameters(threshold1: number, threshold2: number, apertureSize: number, L2gradient: boolean): segmentation_IntelligentScissorsMB;
threshold1

threshold1 argument (number).

threshold2

threshold2 argument (number).

apertureSize

aperture size argument (number).

L2gradient

l2gradient argument (boolean).

Returns

The segmentation_IntelligentScissorsMB result.

applyImage

Specify input image and extract image features

applyImage(image: Mat): segmentation_IntelligentScissorsMB;
image

input image. Type is #CV_8UC1 / #CV_8UC3

Returns

The segmentation_IntelligentScissorsMB result.

applyImageFeatures

Specify custom features of input image

Customized advanced variant of applyImage() call.

applyImageFeatures(non_edge: Mat, gradient_direction: Mat, gradient_magnitude: Mat, image: Mat): segmentation_IntelligentScissorsMB;
2 available overloads
applyImageFeatures(non_edge: Mat, gradient_direction: Mat, gradient_magnitude: Mat): segmentation_IntelligentScissorsMB;
applyImageFeatures(non_edge: Mat, gradient_direction: Mat, gradient_magnitude: Mat, image: Mat): segmentation_IntelligentScissorsMB;
non_edge

Specify cost of non-edge pixels. Type is CV_8UC1. Expected values are {0, 1}.

gradient_direction

Specify gradient direction feature. Type is CV_32FC2. Values are expected to be normalized: x^2 + y^2 == 1

gradient_magnitude

Specify cost of gradient magnitude function: Type is CV_32FC1. Values should be in range [0, 1].

image

Optional parameter*. Must be specified if subset of features is specified (non-specified features are calculated internally)

Returns

The segmentation_IntelligentScissorsMB result.

buildMap

Prepares a map of optimal paths for the given source point on the image

Note: applyImage() / applyImageFeatures() must be called before this call

buildMap(sourcePt: Point): void;
sourcePt

The source point used to find the paths

getContour

Extracts optimal contour for the given target point on the image

Note: buildMap() must be called before this call

getContour(targetPt: Point, contour: Mat, backward: boolean): void;
2 available overloads
getContour(targetPt: Point, contour: Mat): void;
getContour(targetPt: Point, contour: Mat, backward: boolean): void;
targetPt

The target point

contour

Output destination, filled by the native operation. The list of pixels which contains optimal path between the source and the target points of the image. Type is CV_32SC2 (compatible with std::vector<Point>)

backward

Flag to indicate reverse order of retrieved pixels (use "true" value to fetch points from the target to the source point)

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.