Watershed


Author V. C. Mohan
Date Oct 2015

If one assumes the image values (0 to 255) represents the elevation in an rectangular area of x and y, then watershed lines and individual basins can be demarcated. Such a segmentation of the image is useful for some applications such as recoloring.

Using an algorithm developed by Vincent- Soille,this plugin determines watershed lines and labels individual basins with unique numbers. Typically over segmentation may occur. This can be avoided by filtering input clip by various means viz: Gaussian blurring (GaussBlur of ColorIt), Adaptive Median filtering (AdaptiveMedian), adaptive noise filtering (DeNoise), using gradient image as input (SharpEdge of ColorIt) or similar techniques. The names in parenthesis are functions available in plugins by this author.

This plugin can output watershed lines (as white or black) and or display basins within a range of numbers having same grey values. Thresholds for limiting processing to certain grey value ranges and display range of basin numbers are provided.

A test facility for processing repeatedly only the startframe, by endframe number of times with linearly changing parameters is provided. Also the regular processing can be limited to only a window. In case of Y U V formats, if colored input is used and grey=false is set, then the correspondence of the segmentation with original image is seen clearly. Otherwise during test run the window background is greyed.


Details of parameters
Description Name Type Limits Default
Input clip clip none
Starting frame number to process sf integer within clip 0
End frame number to process ef integer within clip and not less than sf last frame
4 close neighbours or 8 neighbours to be considered?? connect4 boolean true for 4, false for 8 true
Are watershed lines to be marked white or black? white boolean true for white, false for 0 true
Process window left x at start frame lx integer within frame, less than rx 0
Process window top y at start frame ty integer within clip, less than by 0
Process window right x at start frame rx integer within clip, more than lx frame width-1
Process window bottom y at start frame by integer within frame, more than ty frame height-1
Process window left x at end frame elx integer within frame, less than erx lx
Process window top y at end frame ety integer within clip, less than eby ty
Process window right x at end frame erx integer within clip, more than elx rx
Process window bottom y at end frame eby integer within frame, more than ety by
lower cut off of grey values to process at start frame lt integer 0 to 255, not more than ut 0
upper cut off of grey values to process at start frame ut integer 0 to 255, not less than lt 255
lower cut off of grey values to process at end frame elt integer 0 to 255, not more than fut lt
upper cut off of grey values to process at end frame eut integer 0 to 255, not less than flt ut
Is this a test run? test boolean true or false false
Grey scale window? grey boolean true or false false
Show basins? showbasins boolean true or false true
threshold %age at start frame above which basins are shown lb integer 0 to 99 0
threshold %age at start frame below which basins are shown ub integer 1 to 100 100
threshold %age at end frame above which basins are shown elb integer 0 to 99 lb
threshold %age at end frame below which basins are shown eub integer 1 to 100 ub
Whether watershed lines are to be shown? watershed boolean true or false true

Usage examples:-
test mode with watershed lines black display
#watershed(last,0,100, c4=false,white=false,lt=1,ut=255,test=true,lb=0,ub=100,showbasins=false, watershed=true)
test mode with basins only display
#watershed(last,0,100, c4=false,white=false,lt=20,ut=220,test=true,lb=0,ub=20,elb=80, eub=100,showbasins=true, watershed=false)
#Normal processing
#watershed(last, c4=false,white=false,lt=20,ut=200,lb=0,ub=50,showbasins=true, watershed=true)
Input blurred with GaussBlur

Watershed Output


To my index page To Avisynth