HistogramAdjust


Author V. C. Mohan
Date Aug 2014
EMail: mohanvc

This plugin function adjusts the histogram of a frame by either equalizing it or by matching with histogram of another image, or with given histogram table of values. Another option is "dupe" wherein instead of matching, the derived histogram from matching clip or table is substituted.

Windowed equalization or matching is possible. In this the window for deriving the input clip histogram, moves one pixel at a time and the center point of the window is altered based upon the option. The left out borders of the frame are also suitably corrected. In Windowed processing it will be possible to limit change of value to a percentage of the change determined. at limit of 100 change will be full

The function accepts YUY2 and Planar (YV12 only in 2.5 version) color formats only. However the clip to be processed and to be used for matching need not have identical color formats and dimensions. For example processing clip can be YV12 , 720 X 480 pixels while matching clip is YUY2, 256 X 16 pixels.

If equalization is to be done or matching or dupe using tabled values, then matching clip need not be specified. The second parameter is for inputting table values and is an array of integer pairs.Each pair consists of Luma (greyscale or intensity)value and the number of occurences at this value. Due to limitation of number of parameters that can be input through Avisynth, not more than 25 pairs can be specified. It will be possible to input by table any desired histogram shape. The plugin linearly interpolates and extrapolates to construct a full histogram from these values.


Details of parameters
Description Name Type Limits Default
Input clip histogram of which is to be altered clip none
The following is a table of Histogram values, to be specified only if 'table' is true
Luma value integer 0 to 255 and to inrease monotonically
population at this luma value integer non negative
Type of process type string "equal" "dupe" "match" "equal"
Is Table specified table boolean true for yes, false for no false
Clip in which image for matching is available mclip clip valid clip to be specified only if required dummy clip
frame number on clip for matching mf integer within clip 0
Is windowed processing required? window boolean true for window, false for full frame false
window width w integer odd number 3 or above, within clip frame width/4 (odd number)
window height h integer odd number 3 or above, within clip frame height/4 (odd number)
limit on % of change in value allowed. limit integer 1 to 100 100

#Usage examples:-
HistogramAdjust()
HistogramAdjust(c,type="match",mclip=mm,mf=26)
HistogramAdjust(c,15,2, 30,12, 50, 33, 90, 12,150,35,200,10, type="match",table=true,window=true, w=21, h=241,limit=50)
Below is an example of output (reduced for display) got with different parameters:

Top row: right is input image. Left is windowed equalization, middle is match with table full frame
Middle row: left full frame equalization, middle match with different table, right dupe with table
Bottom row: left windowed match 100%, middle same with limit at 50%, right same with 10% limit
The processing script used:
m1=HistogramAdjust(s,1,55,100,70,255,5,type="match",table=true, window=true,w=59,h=55)
m2=HistogramAdjust(s,1,55,100,70,255,5,type="match",table=true, window=true,w=59,h=55, limit=50)
m3=HistogramAdjust(s,1,55,100,70,255,5,type="match",table=true, window=true,w=59,h=55,limit=10)
a=stackhorizontal(m1,m2,m3)
e=HistogramAdjust(s,type="equal")
m=HistogramAdjust(s,1,55,100,70,255,55,type="match",table=true)
d=HistogramAdjust(s,1,55,100,70,255,5,type="dupe",table=true)
b=stackhorizontal(e,m,d)
e=HistogramAdjust(s,1,55,100,70,255,5,type="equal", window=true)
m=HistogramAdjust(s,1,55,100,70,255,5,type="match",table=true)
c=stackhorizontal(e,m,s)
stackvertical(c,b,a)
To my index page To Avisynth