Log in

View Full Version : HotSpot Suppressor - need speed up suggestions


Forensic
25th January 2015, 20:46
I wrote a script to suppress intermittent hot spots (e.g. flashing lights in front of a dashcam). The function gradually blends increasing lumen shifts as pixel values approach pure white, but is painfully slow due to the looped Levels commands used to swap each target luminosity value for another. An uncompressed test file is available HERE (https://www.yousendit.com/download/UlRTQk0wdVVUME94djhUQw).

Can anyone suggest a faster method or -hopefully- convert it to a plug-in that is AviSynth 2.58 (and optionally 2.6) compatible? I appreciate any assistance.

### function HotSpotSuppressor() ###
### v1.0 by "Forensic" 24 Jan 2015 ###
### Needed filter : Gscript ###

function HotSpotSuppressor(clip clip, int "loop", int "strength", float "opacity") {
loop = default(loop,20)
strength = default(strength,5)
opacity = default(opacity,.2)

Assert(loop >=1 && loop <=40 ? true : false, chr(10) + "Loop variable must be a positive integer from 1 to 40" + chr(10))
Assert(strength >=1 && strength <=10 ? true : false, chr(10) + "Strength variable must be a positive integer from 1 to 10" + chr(10))
Assert(opacity >=.1 && opacity <=.9 ? true : false, chr(10) + "Opacity variable must be a positive number from .1 to .9" + chr(10))

GScript("""
a = clip
mask = a.greyscale.bicubicresize( int( a.width/16 )*4, int( a.height/16 )*4 ).bicubicresize( a.width, a.height ) #resize to ignore salt noise
for( b=0,loop,1 ) {
oldLumen = 255-loop+b
newValue = max( 0,255-strength*b ) #used for the newLumen value and also the gamma shift
mask = mask.levels( oldLumen, newValue, 0, newValue, 255 )
blend = a.Overlay( a.Overlay( mask, mode = "subtract" ), mode = "subtract" )
clip = clip.Overlay( blend, mode = "blend", opacity=opacity )
}
return (clip)
""")}

EDIT: In short, what bogs done my code is the need for a fast way to do "For every YUV video pixel with a Y value of exactly A, change that Y value to B"

johnmeyer
26th January 2015, 00:14
I'd sure look at StanlessS' RT_Stats: it has functions that would do all the heavy lifting for you, and do it quickly.

Forensic
26th January 2015, 01:41
I did not realize that RT_Stats could do that. Thanks.

Forensic
26th January 2015, 07:53
Never mind. I came up with a simple effective solution.


function HotSpotSuppressor (clip clip) {
return (clip.overlay(clip.greyscale.bicubicresize(48,48).bicubicresize(clip.width,clip.height).levels(128,.5,255,254,255,coring=false).levels(254,128,255,0,64,coring=false),mode="subtract"))
}