Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 25th January 2015, 20:46   #1  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
HotSpot Suppressor - need speed up suggestions

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.

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.

Code:
###   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"

Last edited by Forensic; 25th January 2015 at 22:01.
Forensic is offline   Reply With Quote
Old 26th January 2015, 00:14   #2  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,695
I'd sure look at StanlessS' RT_Stats: it has functions that would do all the heavy lifting for you, and do it quickly.
johnmeyer is offline   Reply With Quote
Old 26th January 2015, 01:41   #3  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
I did not realize that RT_Stats could do that. Thanks.
Forensic is offline   Reply With Quote
Old 26th January 2015, 07:53   #4  |  Link
Forensic
Registered User
 
Join Date: Apr 2008
Location: California, USA
Posts: 127
Never mind. I came up with a simple effective solution.


Code:
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"))
}
Forensic is offline   Reply With Quote
Reply

Tags
hotspot, levels, opacity, plug-in, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:55.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.