vcmod


Author V. C. Mohan
Date Oct 2017
All my plugins are available for free download from "here".

vcmod plugin for vapoursynth version r24+, is free and the author does not give any guarentee for its operation. It may be downloaded and used at the users risk.

vcmod has functions named Median, Variance, Amplitude, GBlur, MBlur, Neural, Fan, SaltPepper, Veed and Histogram. These are thread safe.These are ported with suitable modifications from the original avisynth plugins. All the functions in this plugin modify pixel values as per some criteria, and hence the name.


------------------------------------------------------------------------------------------------

Amplitude

Amplitude function segments image on watershed principle. Smoothing is done if opted, restricting to boundaries within each basin. Sharpening is by spiking watershed boundaries and so must use small values. As watershed is known to over segment an image, the inputclip shold be clean and smooth. For convenience useclip parameter if set to 1, uses a pre smmothed clip( may be blurred by GBlur) for segmentation, and uses that on main input.


the script call for amplitude is

vcmod.Amplitude( clip, [ int useclip = 0] [,clip sclip,] [int connect4 = 1,] sh=[int,int,int], sm= [int,int,int])

sh and sm are smooth and sharp factors. Both arrays should not be zeroes.sh and sm arrays must be specified and are not optional. sh can be -10 to 10, and sm can be 0 to 10. connect4 if set uses near 4 points otherwise near 8 points in watershed algorithm.


------------------------------------------------------------------------------------------------

Histogram

Histogram can equalize whole frame or with moving window (slow) or match entire clip with a given frame or match as per specs given. Equalization may be severe for certain inputs, so a parameter limit which limits %age of change is provided. limit value of 0 means no limit. Windowed equalization is extremely severe. type 1 is full window equalization,type 2 is for matching with given table of up to 20 pairs (of %age luma val and %age population), minimum 2 pairs. Type 3 is for matching with a frame. fm is frame number of match clip to be used. YUV and Gray formats only are accepted.


The call is:-

vcmod.Histogram(clip [,clip clipm][,int type=1][,table=[int,int,.....] ][ ,int mf = 0][ ,int window = 0][,int limit] )


------------------------------------------------------------------------------------------------

Median

Median Filter is for eliminating certain types of noise. It uses local statistics (minimum, maximum and median values) of a moving local grid, and changes grid size depending on local statistics.

As per theory
Quote "Ordinary median filters perform well as long as the spatial density of impulsive noise is small. Adaptive Median filter can handle impulsive noise having larger probablity. An additional benefit is this seeks to preserve detail while smoothing nonimpulse noise something that the traditional median filter does not do.

The algorithm used has three purposes.
1.To remove salt and pepper (impulse) noise.
2.To smooth other noise which may not be impulsive
3.To reduce distortion such as excessive thinning or thickening of object boundaries.
" unquote

The Script call is:-

vcmod.Median (clip[, int maxgrid = 5] [,int plane[1,0,0] ] );


maxgrid is size to which grid can grow for getting statistics. Odd number 3 to 9.
plane: planes to be processed. 1 process, 0 do not. All 3 values must not be simultaneously specified as zero.
------------------------------------------------------------------------------------------------

GBlur

A separable Gaussian kernel of odd number size 3 to 11 is designed for blurring. The ksize and standard deviation can be specified.


the script call is

vcmod.GBlur(clip [, int ksize = 5][,float sd = 1.5])



------------------------------------------------------------------------------------------------

Fan



In some videos, especially those transcribed from VHS sometimes regular frequency noise is seen across the frame. Sometimes either vertical or horizontal white streaks are also seen. This function filters out such regular noise and streaks. This function works scan line by scan line. Hence if the streaks are horizontal, input may be turned left and after fan removes the streaks turned right to restore

In case of regular noise Fan need to examine data over a span (odd number from 3 to 51) of apparent wavelength(along horizontal). The central point of this span is either replaced by average or using given tolerances edges are preserved. For streaks shorter span and smaller plus tolerance can be spcified.In case YUV data process of u and v planes are optional. R,G,B planes of RGB are processed. A is just copied.


The script call is:

vcmod.Fan(clip [ , int span = 5][ ,int edge = 1][ ,int uv = 1 ])


------------------------------------------------------------------------------------------------

MBlur

MBlur blurs using values in a circle, or rectangle or along a line (motion blur) around a central point.type 1 is linear.type 2 for rectangular and type 3 for circular. The x and y coordinates are with respect to center. For circular x is treated as radius.


The script call is:

vcmod.MBlur(clip [ , int type = 1][ ,int x = 5][ ,int y = 5 ])


------------------------------------------------------------------------------------------------

Variance

From a given representative window, the global variance is determined. In a moving grid the local variance is determined and the center of the grid point is modified in relation to these two variances. The algorithm ensures that local edges are not destroyed. Repeated use of this function cleans image and may be used for very noisy clips. In case of YUV formats it is optional whether U and V planes are also to be processed. For RGB all 3 planes are processed. The window is specified by left x coord lx, width wd, top y coord ty, height ht and fn the frame number in which this window is located. The window should be as large as possible but have near uniform luma for YUV or Gray formats or uniform color and intensity for RGB format


The call script is :-

vcmod.Variance(clip,int lx,int wd,int ty,int ht [,int fn = 0][,int uv = 0][,int xgrid = 5][,int ygrid = 5])


------------------------------------------------------------------------------------------------

Neural

Given an input ( first frame of clip) and its corresponding desired output ( first frame of tclip which has been obtained through some linear processing), Neural trains itself to get an output as close to desired output as possible. Training window should represent all possible input variations and be as small as possible. Given input grid size ( xpts * ypts) to work on and corresonding desred center points, through repeated iterations and different starting weight sets it finds weights that result in minimum error. The weight set can be saved in a text file and later used for same or similar data . This saves training time that can take several seconds to a few minutes. The input clip is then processed using these weights.


txt can be either "none", "read" or "save". In case of read or save fname with full path and file name be given to read from or save to. If "none" it neither saves nor reads a file. if "save" relevant parameters and training progress (error sum) will be saved to a file. If "read", then it gets all parameters from the previously saved file. No other parameters need to be specified then.
Iter is number of iterations and bestof is how many times process repeated with new weight sets.
wset : if set to 0, uses internal random numbers at each zeroeth iter. If set to 1, it uses time to seed random number generation.
tlx, trx, tty, tby are left x, right x, top y, bottom y coordinates of window to use for training. Time for training is proportional to xpts * ypts * (trx - tlx - xpts) * (tby - tty - ypts) * iter * bestof. A max of xpts * ypts = 225 and minimum 9. xpts and ypts be odd positive numbers.
rgb : with RGB input if set to 0 for r, or 1 for g or 2 for blue plane is used for training. For YUV, or Gray only Y is processed.
The call script is :-

vcmod.Neural(clip,[str txt = "none"[ ,str fname][,clip tclip]] [,int iter = 200][ ,int bestof = 1][, int wset = 0][,int xpts = 3][, int ypts = xpts][, int tlx = xpts][, int trx = width - xpts][, int tty = ypts][, int tby = height - ypts][, int rgb = 1])


for test used following script.
# input was blurred by GBlur to use as desired output.
ret2 = core.vcmod.GBlur(ret,ksize=7,sd=2)
ret1 = core.vcmod.Neural(ret, txt ="save", fname = r'c:\temp\modNeural.txt', tclip = ret2,xpts = 7, iter = 200, bestof = 10,wset = 0,tlx = 250, trx = 450, tty = 100, tby = 300,rgb = 0 )

-----------------------------------------------------------------------------------------------

SaltPepper

Using morphology method filters off salt and pepper noise from input data.

All formats input accepted.
Planes array. The plane set to 0 : no process, 1: Desalt, 2: DePepper, 3 : DeSalt and Depepper.
tol: tolerance above or below surrounding pixels to accept. Max 5.
avg : if salt or pepper found and if avg is set to 1, pixel value will be replaced by average of surrounding. Otherwise nearest valid pixel value.

SaltPepper(clip [,planes = [3,3,3]][,tol = 3][,avg= 1] )



-----------------------------------------------------------------------------------------------

Veed



Veed filter originally developed to remove some greenish hue seen. Later it was extended with option for any or all color planes.Uses gaussian predicted value of the center in a circular area of radius rad, filter strength str. Any plane set to 0 is not processed. If set to 1 filtered. plus and minus limits to accept can be specified.

veed(clip[,rad = 5][,float str = 5] [,int planes = [1,1,1]][,int plimt = 3][,int mlimit = 3] )





-----------------------------------------------------------------------------------------------
Example code and results. Input on left, output on right.
# Histogram
core.vcmod.Histogram(ret)



# Variance
core.vcmod.Variance(ret,lx=50,wd=50,ty=150,ht=100)



# Median
core.vcmod.Median(ret, maxgrid = 5, plane=[1,0,0])



# Amplitude Extreme right difference of input and output heightened
#smoothened by GBlur
ret2 = core.vcmod.GBlur(ret,ksize=5,sd=2)
ret1 = core.vcmod.Amplitude(ret,sh=[2,0,0],sm=[10,0,0], useclip=1,sclip=ret2)
ret2 = core.std.MakeDiff(ret1,ret)
#Difference heightened by equalization
ret2 = core.vcmod.Histogram(ret2)
ret=core.std.StackHorizontal(clips=[ret,ret1,ret2])



To my index page down load plugin To vapoursynth