This was the other section where I thought to show what it was doing. So, again, quoting, and this time adding the analytical graphics (note that the before & after windows are the same; Histogram is being used only to display the spectrum) ...
Spaced Ranger said:
To remove the color and work strictly in luminance, the merged blanks are desaturated (0% color):
continued:
As this is supposed to become a flat background, the reverse of the brightness variation will be averaged [to] itself to produce flat brightness. This is accomplished by inverse ... Of course, inverse works across the entire dark-to-light spectrum and our darkness has become inverted to lightness.
continued:
With levels, the lightness can be brought down back to it's original darkness baseline (but still inverted). By using a Histogram function, one can see the range-spike of the picture both before and after the inversion. In this case, the range before was 32-54 and the range after is 181-213. Therefore, the high range is brought low in levels with:
* Input low = 181
* Input high = 213
* Output low = 32
* Output high = 54
and is so applied:
So the result of these Layer steps was that the background luminance-spike was mirrored in-place.
Note: There shouldn't be manual reading and entering of numbers to make it work, as I did here. Better designed, it should be a state machine (https://en.wikipedia.org/wiki/Finite-state_machine). One only inputs any source and any source-blank, to have it blindly produce the proper correction. Avisynth should have functionality to handle this.