# TweakHist

Author V. C. Mohan
Date Dec 2016
EMail: mohanvc

This 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.

The function accepts RGB, YUY2 and Planar color formats. 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. However their bit depths must be same.

If matching with given table values, then matching clip need not be specified. The second parameter is a table of integer pairs.Each pair consists of Luma ( intensity)value and the second number is %population (type = 3) or %cummulative population (type = 4) at this value.The table is normalized by the function and so approximate values are OK. 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 normalized histogram from these values. In case of RGB input the selected color histogram is tweaked ( in case all 3 color components of RGB input are to be tweaked the function may be invoked in the script 3 times). For other formats only Y value histogram is tweaked.

This function is thread safe. MT_NICE_FILTER and supports all avisynth+ supported formats (except stacked formats).

Details of parameters
Description | Name | Type | Limits | Default
Input clip (histogram of which is to be tweaked) |  | clip |  | none
The following is a table of Histogram values in %ages, to be specified only if 'table' is true |  |  |  |
Luma value % of maximum |  | integer | 0 to 100 % and to inrease monotonically |
% age of population or cummulative population at this luma value |  | integer | non negative. In case of type = 4, should monotonically increase and Max value is 100 %. |
Type of process | type | integer | 1 for equalization 2. for matching with specified frame, 3 for matcing with given table of Luma, population %ages. 4. for matching with table of luma vs cummulative population %ages | 1
Clip in which image for matching is available | mclip | clip | valid clip to be specified for type = 2 option | dummy clip
frame number on clip for matching | mf | integer, may be specified for type = 2 option | within clip | 0
limit on % of change in value from original for tweaking allowed. | limit | integer | 1 to 100 | 100
color of RGB input to process. | rgb | integer | 0: red, 1 : Green, 2: Blue | 1 (green)

#Usage examples:-

    TweakHist()
    TweakHist(c,type=2,mclip=mm,mf=26)
    TweakHist(c,15,2, 30,12, 50, 33, 90, 12,150,35,200,10, type=3,limit=50)
    TweakHist(20,1,150,100,255,110, type=4,limit = 70)
    # RGB input. Repeated for each color
    TweakHist(limit = 70,rgb = 0)
    TweakHist(limit = 70,rgb = 1)
    TweakHist(limit = 50, rgb = 2)

To my index page | down loadmodPlus plugin | To Avisynth