Skip to content

Vapoursynth Connected Components Label Filtering from OpenCV.

Notifications You must be signed in to change notification settings

dtlnor/VapourSynth-cv_ccl_filter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VapourSynth-cv_ccl_filter

Vapoursynth Connected Components Label Filtering from OpenCV.

Description

Using OpenCV's connectedComponentsWithStats to compute the connected components labeled image of a boolean image and also get statistics for each label. Then filter the labeled content based on the statistical results.

Require VS API >= 4.0

Usage

Exclude the labels above ccl_thr

core.cv_ccl.ExcludeCCLAbove(clip mask, int cc_thr[, int connectivity, int ccl_type, int cc_stat_type])

Exclude the labels under ccl_thr

core.cv_ccl.ExcludeCCLUnder(clip mask, int cc_thr[, int connectivity, int ccl_type, int cc_stat_type])

Read all the stats from cv::connectedComponentsWithStats to FrameProps

core.cv_ccl.GetCCLStats(clip mask[, int connectivity, int ccl_type])

For example, if you want to remove all the connected components smaller than 2500 pixels (in area) inside your mask clip, you can simply write:

core.cv_ccl.ExcludeCCLUnder(mask, 2500)
Sample

Original
image

ExcludeCCLUnder 2500
image

ExcludeCCLAbove 2500
image

If you want to get all the ccl stats data, using core.cv_ccl.GetCCLStats, you will get FrameProps like:

_CCLStatNumLabels
_CCLStatAreas
_CCLStatLefts
_CCLStatTops
_CCLStatWidths
_CCLStatHeights
_CCLStatCentroids_x
_CCLStatCentroids_y

which should contains array (except _CCLStatNumLabels) if the input clip isn't a blank clip. Note that the first label is always the background label, so you will like to get the frame prop like this

f.props.get('_CCLStatAreas', None)[1:]

Parameters:

  • mask

    Clip to process. Binarize Gray8 clip only.

  • cc_thr

    Use to compare with the results of statistics with cc_stat_type.

  • connectivity

    8 or 4 for 8-way or 4-way connectivity respectively. Exact param in cv::connectedComponentsWithStats.
    Default 8

  • ccl_type

    cv::ConnectedComponentsAlgorithmsTypes
    connected components algorithm

    • 0 - SAUF algorithm
    • 1 - BBDT algorithm
    • 2 - Spaghetti algorithm

    Default -1 Auto (Spaghetti algorithm)

  • cc_stat_type

    cv::ConnectedComponentsTypes
    connected components statistics

    • 0 - The leftmost (x) coordinate which is the inclusive start of the bounding box in the horizontal direction.
    • 1 - The topmost (y) coordinate which is the inclusive start of the bounding box in the vertical direction.
    • 2 - The horizontal size of the bounding box.
    • 3 - The vertical size of the bounding box.
    • 4 - The total area (in pixels) of the connected component.

    Default 4 Area.

About

Vapoursynth Connected Components Label Filtering from OpenCV.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages