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 19th December 2021, 19:32   #221  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Yeah, I processed the clip in question, removed a lot of emulsion chips, but not as many as I would like,
however the purpose was to do only very little denoise, and it did that as the purpose was to to avoid frame global changes.
Need to figure out at least one more conditional restriction so as to be able to relax YTh and CTh restriction a little.
I still want only a very light touch.
[The frames I was processing needed maybe up to about 3 small chips/dots removed on SOME frames only].
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 19th December 2021 at 19:43.
StainlessS is offline   Reply With Quote
Old 20th December 2021, 08:28   #222  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 217
My thinking is, fresh pot of coffee helped, do not restore if mask object(what you call the white blob) or any other means, doesn't exist in adjacent frames.

ns=no spot
s=spot
b=ball

Code:
frame 1      2      3
         ns    s      ns
         b      b     b
Spot in frame 2 removed and since nothing exist in either 1 or 3 then do not restore. If object like a ball exist in 1 or 3 then restore.
Spot are motionless and the ball isn't.
coolgit is offline   Reply With Quote
Old 20th December 2021, 09:08   #223  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
All you did is move the problem.
Quote:
Spot are motionless and the ball isn't.
How do you tell if ball exists in frames 1,and 2, and 3, as you say, ball isnt motionless.
[And if MoComp could tell, then ball would not disappear in the first place via Spotless]
I'm less concerned with balls, more with hands and feet, and arms and legs (but balls would be nice too).
EDIT: Anyways, have not given up yet, still plugging away at it.

EDIT: What I got right now, take comments with pinch of salt, and havta figure out what its doin'.
Code:
#AviSource(".\10Bit_Standard8_Scan_16FPS.avi")
#AviSource(".\IG18.avi")
#AviSource(".\AMOLAD.demuxed.m2v.AVI")
AviSource("D:\DVD\PBDeSpot_1.avi")
ConvertToYV24
#ConvertToYUV444
#Return last.info
#ConvertBits(16)
Src=Last
Filtered=SpotLess(RadT=1)
YTH8     = 8
CTH8     = 12
YNOISETH8 = 2
SHOW = True
SpotTest(Src,Filtered,YTH8,CTH8,YNOISETH8,SHOW)
Return Last.ConvertToRGB32

/*
    SpotTest(),
    Purpose:
        Spotless produces frame global changes [most pixels are changed], here we want to try alter only real spots where there is significant change in spotless Y [by YTh8]
        and also that are near grey in source [by CTh8], these targeted pixels are then overlayed from Spotless result onto original src.

    Src,       Pre-Spotless source
    Filtered,  Spotless result
    YTh8,      threshold for Y in 8 bit range.
    CTh8,      threshold for Chroma in 8 bit range.
    YNoiseTh8, ?????
    Show,      Show Masks.Mask is the final mask made from MaskY and MaskC.

*/
Function SpotTest(clip Src,clip Filtered,int "YTh8",int "Cth8",int "YNoiseTh8",Bool "Show") { # 8 -> 16 bit YUV444 only
    YTh8      = Min(Max(Default(YTh8,12),0),255)
    CTh8      = Min(Max(Default(CTh8,12),0),255)
    YNoiseTh8 = Min(Max(Default(YNoiseTh8,8),0),255)
    Show = Default(Show,False)
    try {bpc = Src.BitsPerComponent} catch(msg) {bpc=8}
    try {Y444=Src.IsYV24||Src.Is444} catch(msg) {Y444=false}
    Assert(Y444,"SpotTest: Must be YV24/YUV444")
    YTh      = BitLShift(YTh8,bpc-8).String
    CTh      = BitLShift(CTh8,bpc-8).String
    YNoiseTh = BitLShift(YNoiseTh8,bpc-8).String
    SY  = Src.ExtractY
    FY  = Filtered.ExtractY
    PSY = SY.SelectEvery(1,-1)
    NSY = SY.SelectEvery(1, 1)
    MaskN   = Mt_Lutxyz(PSY,SY,NSY,"x "+ YNoiseTh + " - y <= y z "+ YNoiseTh + " + <= & z "+ YNoiseTh + " - y <= y x "+ YNoiseTh + " + <= & | 0 range_max ?")
                                                                                       # ( ((x-YNoiseTh <= y) & (y <= z+YNoiseTh)) | ((z-YNoiseTh <= y) & (y <= x+YNoiseTh)) )  ? 0 : 255 ## Infix @ 8 bit
                                                                                       # ((YPrv-YNoiseTh <= YCur <= YNxt+YNoiseTh) || (YNxt-YNoiseTh <= YCur <= YPrv+YNoiseTh)) ? 0 : 255

    MaskY   = Mt_Lutxy(SY,FY,"x y - abs " + YTh + " > range_max 0 ?")                  # "(abs(x-y) > YTh) ? 255 : 0"
    MU      = Mt_Lut(Src.ExtractU,"x range_half - abs")                                # "abs(x - 128)"
    MV      = Mt_Lut(Src.ExtractV,"x range_half - abs")                                # "abs(x - 128)"
    MaskC   = Mt_Lutxy(MU,MV,"x 2 ^ y 2 ^ + .5 ^ round " + CTh + " <= range_max 0 ?")  # "(round(((x^2)+(y^2))^0.5) <= CTh) ? 255 : 0"    # 2D chroma distance from grey (by Pythagoras)
    MaskN = MaskN.mt_Expand
    MaskY = MaskY.mt_Expand
    MaskC = MaskC.mt_Expand
    MaskAnd = MaskC.Mt_Logic(MaskY,"and")                                                               #
    MaskAnd = MaskAnd.Mt_Logic(MaskN,"and")                                                                #
    MaskSelect = MaskAnd.mt_Expand.Blur(1.0)
    #
    Overlay(Src,Filtered,Mask=MaskSelect,Opacity=1.0)
    CGREY = MaskSelect.Mt_lut("range_half")
    SEP=$FF0000
    HBAR=Src.BlankClip(length=1,Height=4,color=SEP)
    LFT=StackVertical(Src.Subtitle("Src"),HBAR,Filtered.Subtitle("Filt"),HBAR,Last.Subtitle("Result"))
    MID=StackVertical(YtoUV(CGrey,CGrey,MaskN).Subtitle("MaskN"),HBAR,YtoUV(CGrey,CGrey,MaskY).Subtitle("MaskY {abs(SrcY-FiltY) > YTh}"),HBAR,YtoUV(CGrey,CGrey,MaskSelect).Subtitle("MaskSelect=MaskAnd.mt_Expand.Blur(1.0) {Blk=Src used : Wht=Filt used}"))
    RGT=StackVertical(YtoUV(CGrey,CGrey,MaskC).Subtitle("MaskC {Src Chroma distance from Grey <= Cth8"),HBAR,YtoUV(CGrey,CGrey,MaskAnd).Subtitle("MaskAnd {MaskN & MaskC & MaskY}"),HBAR,YtoUV(CGrey,CGrey,CGrey))
    VBAR=LFT.BlankClip(length=1,width=4,color=SEP)
    STK = StackHorizontal(LFT,VBAR,MID,VBAR,RGT)
    (Show) ? STK : Last
}
EDIT: some cosmetic changes.
I'm gonna get some sleep soon.

MaskN (noiseMask) shows no noise = BLACK, noise = WHITE for current frame Cur yPixel where,
(PrvY - NoiseTh) <= CurY <= (NxtY + NoiseTh) OR (NxtY - NoiseTh) <= CurY <= (PrvY + NoiseTh) Then BLACK Else WHITE
If pixel lies between corresponding pixels in previous and next frames (with a little tolerance by NoiseTh), then not noise, else noise.
[ie No spot if BLACK, and MAYBE spot (or ball) if WHITE]

Currently, MaskC is the main problem [BLACK is colored ie dont use BALL/HAND/LEG from Filt clip, and WHITE if Copy from filt clip].
Detecting colored ball as BLACK, also tends to stop detect of what looks like white spots at high luma level (but with chroma distance above CTh).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th December 2021 at 20:42.
StainlessS is offline   Reply With Quote
Old 20th December 2021, 12:12   #224  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 217
What I was thinking was the ball would exist in the previous or next frame, as in your example post 217, by searching a part of the frame (previous or next) for similar object, say 50 by 50 pixels search area (freedom to change the variables according to video), colour shouldn't be an issue. Where the ball disappeared would be the centre of 50 by 50. Surely this would narrow down the search and mistaken identifying of details by not searching the whole frame. If it was a spot then nothing would be found and therefore not restored. In your post 217 mask y frames made it clear where the ball was and is. Comparing the ball real colour from the source frames would be the final confirmation before restoring. Neither ball in Mask y and colour have to be 100% the same in both frames, perhaps 80% is enough. Obviously this would apply to hand and foot.
coolgit is offline   Reply With Quote
Old 20th December 2021, 19:36   #225  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
OK, then please supply script code to do that, and then we is cookin'.
[If it works as well as you say, then maybe can look forward to MvTools algo update, and then this script (or parts of it) may not be needed at all]

EDIT: At present, the function is only looking to target single pixels, [EDIT: blob-ish objects are also made up of single pixels] it is possible that it may extend to blob-ish objects,
but original requirement is for fast, simple, de-speckler, which causes little global frame changes, later other main denoiser may be also used.
Its definitely just experimental at the moment.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 20th December 2021 at 21:22.
StainlessS is offline   Reply With Quote
Old 20th December 2021, 21:11   #226  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
https://academic.microsoft.com/paper...)&f=&orderBy=0

Quote:
Color space normalization: Enhancing the discriminating power of color spaces for face recognition
Abstract

This paper presents the concept of color space normalization (CSN) and two CSN techniques, i.e., the within-color-component normalization technique (CSN-I) and the across-color-component normalization technique (CSN-II), for enhancing the discriminating power of color spaces for face recognition. Different color spaces usually display different discriminating power, and our experiments on a large scale face recognition grand challenge (FRGC) problem reveal that the RGB and XYZ color spaces are weaker than the I"1I"2I"3, YUV, YIQ, and LSLM color spaces for face recognition. We therefore apply our CSN techniques to normalize the weak color spaces, such as the RGB and the XYZ color spaces, the three hybrid color spaces XGB, YRB and ZRG, and 10 randomly generated color spaces. Experiments using the most challenging FRGC version 2 Experiment 4 with 12,776 training images, 16,028 controlled target images, and 8,014 uncontrolled query images, show that the proposed CSN techniques can significantly and consistently improve the discriminating power of the weak color spaces. Specifically, the normalized RGB, XYZ, XGB, and ZRG color spaces are more effective than or as effective as the I"1I"2I"3, YUV, YIQ and LSLM color spaces for face recognition. The additional experiments using the AR database validate the generalization of the proposed CSN techniques. We finally explain why the CSN techniques can improve the recognition performance of color spaces from the color component correlation point of view.
Basically, Color Space Normalizing of YUV just involves forgetting all about the Y channel.
Used in Facial recognition, because skin tones have similar-ish U and V range values, no matter how light / dark the skin tone.

Some, above maybe of some use. [we are using only U and V in the chroma distance thingy].

EDIT: I did see a pdf saying similar to above for YUV but deleted it.
Maybe Color Space Normalizing of YUV or Facial recognition in YUV is specifically what we want, so above extract is maybe not the one we ideally want.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 21st December 2021 at 00:29.
StainlessS is offline   Reply With Quote
Old 20th December 2021, 23:58   #227  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 217
Just chucking in ideas, was thinking of the top of my head. Obviously i don't know the full capabilities of avisynth.
coolgit is offline   Reply With Quote
Old 21st December 2021, 00:34   #228  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Obviously i don't know the full capabilities of avisynth.
Obviously, Nobody knows the full capabilities of avisynth.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 12th January 2022, 22:40   #229  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 217
Stainless - tried to message you but your inbox is full.
coolgit is offline   Reply With Quote
Old 13th January 2022, 03:12   #230  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Coolgit, sorry, bit involved,
I is a bit busy,
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 30th June 2022, 12:16   #231  |  Link
coolgit
Registered User
 
Join Date: Apr 2019
Posts: 217
Remove line 306 downwards and insert this...

Code:
prev = SpotLessT.selectevery(1,-1)
next = SpotLessT.selectevery(1,1)
SpotLessSCT=src.SCSelect_HBD(next,prev,SpotLessT,show=false)

prev = SpotLessF.selectevery(1,-1)
next = SpotLessF.selectevery(1,1)
SpotLessSCF=src.SCSelect_HBD(next,prev,SpotLessF,show=false)

SpotLessSCF2P=SpotLess(SpotLessSCF,BlkSz=BlkSzF,OLap=OLapF,pel=1,Tm=False,Bblur=BblurF,ThSAD=3000,RadT=RadT) # Useful for many small defects per frame and not cleared on first pass.
																											 #	2nd pass should clear up remaining defects and improve quality on 1st pass.
S1 = StackHorizontal(\
sub(src, "Source", txt_sz),\
sub(SpotLessT, "Spotless TM true", txt_sz),\
sub(SpotLessF, "Spotless TM false", txt_sz)\
)
S2 = StackHorizontal(\
sub(SpotLessSCT, "Spotless TM true and scene change", txt_sz),\
sub(SpotLessSCF, "Spotless TM false and scene change", txt_sz),\
sub(SpotLessSCF2P, "Spotless 2 pass TM false and scene change", txt_sz)\
)
output = StackVertical(S1,S2)

Return output                           # Comparison


#Return SpotLessSCT                      # Conversion
#Return SpotLessSCF
#Return SpotLessSCF2P
#Return SpotLessT
#Return SpotLessF

# Debugging to check scene change detection------------------------------------
prev = SpotLessT.selectevery(1,-1)
next = SpotLessT.selectevery(1,1)
SpotLessSCTDM=src.SCSelect_HBD(next,prev,SpotLessT,show=true)

SSCTD1 = StackHorizontal(\
sub(src.AddBorders(0,30,0,0), "Source", txt_sz),\
sub(SpotLessSCTDM.AddBorders(0,30,0,0), "Spotless and scene change with metrics", txt_sz)\
)
SSCTD2 = StackHorizontal(\
sub(SpotLessSCT.AddBorders(0,30,0,0), "Spotless and scene change without metrics", txt_sz),\
sub(BlankClip(src).AddBorders(0,30,0,0), "Blank", txt_sz)\
)
outputD = StackVertical(SSCTD1,SSCTD2)

#Return outputD                           # Comparison
Added two new choices.
1. Use SpotLessF with scene changes for clips with small defects only.
2. 2nd pass available to improve on 1st pass.
coolgit is offline   Reply With Quote
Old 13th August 2022, 23:47   #232  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
DoubleRate deinterlacer template, uses SpotLess. For DGIndex / DGIndexNV. [works with either, copy to their Templates Directory]

Need some tester to suggest optimal defaults, but pretty damn good as it is.
Uses Spotless(RadT=1) on separated Even/Odd fields, where removes spots and reduces any artifically added grain [added to hide how bad the clip is].

DespotDeinterlaceDbleRate.avs
Code:
### DgIndex / DgIndexNV, Template, DespotDeinterlaceDbleRate.avs

# Temp Pre-Processing step for Interlaced, with Spotless() on separated fields, prior to deinterlace.
#    Spotless(RadT=1) nicely reduces any artificial grain as well as getting rid of single field/frame spots.
#    We sort of prefer BOBMOD = 1, YadifMod2 deinterlace with little/no additional overprocessing at pre-proc stage. Although can BOBMOD=2, ie QTGMC.
# Output is YV24, save AVI from VDub2, with eg Fast Recompress, Codec UT_Video, YUV444 BT.601 VCM

VideoFileName   = "__vid__"
AudioFileName   = "__aud__"
AudioDelay      = Value("__del__")

###############

vExt = GetFilenameExtension(VideoFileName)

If(vExt == ".dgi")  { DGSource(VideoFileName)    } # DGIndexNV
Else                { Mpeg2Source(VideoFileName) } # DGIndex

AudioExt = GetFilenameExtension(AudioFileName)

# May prefer other audio source, but these usually work just fine.
Audio=      (AudioExt==".ac3") ? NICAC3Source(AudioFileName,channels=2,DRC=0)
        \ : (AudioExt==".mpa"||AudioExt=="mp1"||AudioExt==".mp2"||AudioExt==".mp3") ? NicMPG123Source(AudioFileName,Normalize=False)
        \ : (AudioExt==".wav") ? RaWavSource(AudioFileName)
        \ : (AudioExt==".dts") ? NicDTSSource(AudioFileName)
        \ : (AudioExt==".w64") ? RaWavSource(AudioFileName,samplerate=6)
        \ : 0

Assert(!isInt(Audio),"NO AUDIO")

(!isInt(Audio)) ? AudioDub(Audio).DelayAudio(AudioDelay).Trim(0,0) : NOP    # Trim, chop/add audio to length

(!isInt(Audio) && AudioRate() <> 44100) ? ResampleAudio(44100)     : NOP    # If you want 44.1 KHz (I do)


####### CONFIG ##########

AssumeTFF                                                                   # Whatever (check) : Almost always TFF for PAL DVD. Default field order is BFF.

ConvertToYV24(Interlaced=true)

FINAL    = False      # True, switch off SUBS, STACK, and Title

DBLRATE  = true       # Output rate Double input
RADT     = 1          # Spotless() on separated fields only, before de-interlaced.
DEGRAIN_FIELDS=False  # True, Degrain separated fields rather than deinterlaced frames (On one or other, but Not both). [done after Spotless when on separated fields].
BOBMOD=1              # 0=BOB, 1=YadifMod2, 2=QTGMC.

FRAMES   = 0          # McDegrainSharp(frames=FRAMES), (0=Dont McDegrainSharp) # McDegrainSharp() on fields if DEGRAIN_FIELDS=true, else on frames [Never on both].
CSHARP   = 0.03       # Very light McDegrainSharp sharpen arg



               # For Spotless on separated fields.
ThSAD  = 1000  #  Ditto
ThSAD2 = 990   #  Ditto
PEL    = 2     #  Ditto
CHROMA = True  #  Ditto
BlkSz  = 16    #  Ditto
TM     = False #  Ditto
DC     = "RemoveGrain(1).Blur(0.3,0.3)"        # DC = Detect Clip. Or Just "Blur(0.3)"

                # Deinterlace mode

BOB_FUNC_0 =    """Bob()"""                                                                                                    # Cheap & cheerful Doublerate simple Bob.
BOB_FUNC_1 =    """YadifMod2(Order=-1,Mode=1,edeint=NNedi3(Field=-2, nns=2))"""                                                # Doublerate Yadifmod2 filter.
                # # Field-2=double rate, internal parity value to start : Order-1=Internal Parity. Mode 1=double rate do spactial check (3=no spatial check).

BOB_FUNC_2 =    """QTGMC(Preset="fast",NoisePreset="Fast",SourceMatch=2,Lossless=2,EZKeepGrain=0.4,Sharpness=0.1, tr2=0)"""    # Doublerate QTGMC filter.

FUNC       =   Select(BOBMOD, BOB_FUNC_0, BOB_FUNC_1, BOB_FUNC_2)
FNAME      =   Select(BOBMOD,"BOB",      "YADIF",     "QTGMC")


PRE_FETCH=4    # 1 = No Prefetch, Else eg 4 = Prefetch(4) ie MT mode

###            # Display stuff
SUBS   = True
STACK  = True # Show Src and Result
TITLE  = true # Show Title Bar
TITNUM = True # Show Frame Number on Title Bar (Only if TITLE)

##### End Config ##########

Src=Last


PROCESS_FIELDS = (RADT>0 || (DEGRAIN_FIELDS && FRAMES>0))   # any Field pre-processing before deinterlacing ?

# DeSpot and/or McDeGrainSharp on fields
Sep      = Src.SeparateFields
SEP_Even = Sep.SelectEven
SEP_Even = (RADT>0) ? SEP_Even.SpotLess(Radt=RADT,thsad=ThSAD,thsad2=ThSAD2,Pel=PEL,chroma=CHROMA,blksz=BLKSZ,tm=TM,glob=True,dc=SEP_Even.Eval(DC)) : SEP_Even
SEP_Even = (DEGRAIN_FIELDS && FRAMES>0) ? SEP_Even.McDeGrainSharp(frames=FRAMES,csharp=CSHARP)  : SEP_Even
SEP_Odd  = Sep.SelectOdd
SEP_Odd  = (RADT>0) ? SEP_Odd.SpotLess(Radt=RADT,thsad=ThSAD,thsad2=ThSAD2,Pel=PEL,chroma=CHROMA,blksz=BLKSZ,tm=TM,glob=True,dc=SEP_Odd.Eval(DC))   : SEP_Odd
SEP_Odd  = (DEGRAIN_FIELDS && FRAMES>0) ? SEP_Odd.McDeGrainSharp(frames=FRAMES,csharp=CSHARP)  : SEP_Odd
PreProc  = (PROCESS_FIELDS) ? Interleave(Sep_Even,Sep_Odd).Weave : Src

Deint  = PreProc.Eval(FUNC)  # Double Rate deinterlace
Deint  = (!DEGRAIN_FIELDS && FRAMES>0) ? Deint.McDeGrainSharp(frames=FRAMES,csharp=CSHARP)  : Deint
Result = (!DBLRATE)   ? Deint.SelectEven                                                   : Deint

SUBS  = (!FINAL&&SUBS)
TITLE = (!FINAL&&TITLE)
STACK = (!FINAL&&STACK)

SUBTXT    = (!DBLRATE) ? FNAME+"_DEINTERLACED-EVEN" : FNAME+"_DblRate-DEINTERLACED"


RESULT = (SUBS)      ? Result.Subtitle(SUBTXT,Align=5)                                     : Result

SrcTest = (!DBLRATE) ? Src : Src.ChangeFPS(Src.FrameRateNumerator*2,Src.FrameRateDenominator)

SrcOut = (!TITLE)?SrcTest:(!DBLRATE) ? Src.TSub("Source",TITNUM) : Src.TSub("Source DblRate via ChangeFPS, ie dupes",TITNUM).ChangeFPS(Src.FrameRateNumerator*2,Src.FrameRateDenominator)

RESULT = (!TITLE) ? RESULT :(!DBLRATE) ? Result.TSub("Result SingleRate",TITNUM) : Result.TSub("Result DblRate",TITNUM)

(STACK) ? Stackhorizontal(SrcOut, Result) : Result

(PRE_FETCH>1) ? Prefetch(PRE_FETCH) : NOP  # I had problems using x64 and Prefetch [Access Violation], culprit was old IsCombedTIVTC, fixed via Pinterf version.

Return Last

#####################
# Stack Overhead Subtitle Text, with optional FrameNumber shown.
Function TSub(clip c,string Tit,Bool "ShowFrameNo",Int "Col"){
    c.BlankClip(height=20,Color=Default(Col,0))
    (Default(ShowFrameNo,False))?ScriptClip("""Subtitle(String(current_frame,"%.f] """+Tit+""""))"""):Trim(0,-1).Subtitle(Tit)
    Return StackVertical(c).AudioDubEx(c)
}

Function GetFilenameExtension(String fn) {
    fn=fn.RevStr    i1=fn.FindStr("\")  i2=fn.FindStr("/")
    i=(i1==0) ? i2 : (i2==0) ? i1 : min(i1,i2)
    fn=(i>0) ? Fn.LeftStr(i-1) : fn
    i=fn.FindStr(".")
    Return (i>0)?fn.LeftStr(i).RevStr:""
}
EDIT: Intended where entire input clip is known to be interlaced, not mix of interlaced and progressive.

Here a [vob source] frame picked out at nearly random, shows stacked with subs. [CLICK ME]

I did not look for frame with spots, but shows grain reduction.

EDIT:
Changed Frames=0 [MDegrainSharp off by default], and default CSHARP=0.03 [was 0.1]
Makes it a bit faster by default {less pre-processing}, and even milder sharpen if switched on.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th August 2022 at 06:06.
StainlessS is offline   Reply With Quote
Old 14th August 2022, 00:56   #233  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
StainlessS,

I just used (today!) Spotless on half an hour of 1956 NFL (American football) film. It nailed spots that the old RemoveDirtMC wouldn't touch.

I'm still looking for a way to add adjustments for spot size and color. These "spots" (they were mostly circles) were all white. At other times most spots are black. Adding this capability would add one other feature: ignore real objects, most of which are not near-black or near-white. I still lose a lot of shirt buttons as people move around. In this project, the ball often disappeared and I had to create a separate video that didn't have any dirt removal and cut to that when the ball disappeared. That is tedious work.

However, even as is, I'm finding it more useful than RemoveDirtMC for many projects.

So, thanks again for the excellent work!

Here is a before/after. All those white circles on the black uniforms on the left were moving around like a snowstorm from frame to frame, and it got 90% of them.
johnmeyer is offline   Reply With Quote
Old 14th August 2022, 06:12   #234  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Slight alterations to previously given DgIndex/DgIndexNV script template. [McDegrainSharp(Frames=0) by default, ie off, faster]

For Spot size, BlkSz maybe at least twice as wide/tall as spots. And also, ThSAD,ThSAD2 affects result. [ThSAD >= ThSAD2].

Also this lot from Docs [I doubt that I can easily make it less opaque].

Code:
ThSAD, Default 10000=NEARLY OFF(ie ignore hardly any bad blocks), 0 < ThSAD < 16320(8*8*255). 8x8 block SAD threshold at radius 1 (ie at current_frame +- 1) [SAD, Sum of Absolute (pixelwise) Differences].
    ThSAD and ThSAD2 suggested absolute minimum of maybe about 400.
    ThSAD and ThSAD2 thresholds are based on 8 bit 8x8 block, irrespective of colorspace depth or BlkSz, max=8x8x255=16320, use same thresholds where High Bit Depth.
    In mvTools MCompensate(), when creating a compensated block the SAD between compensated block and the same original block in current_frame, the 8 bit SAD is measured and if
    greater than SAD threshold then that block is ignored and uses original block from current frame instead. [The compensated block is judged too different, so ignored & original block used instead
    in the result MCompensated frame].
    Where eg ThSAD=64, AVERAGE absolute single pixel difference threshold would be 64/(8*8)=1, so AVERAGE absolute pixel difference greater than 1 would ignore that mcompensated block and use the
    block from current frame in the resulting mcompensated frame instead. This example allows for all pixels in a 8x8 block to be different by 1, or a single pixel in 8x8 block to be different by 64,
    or some other mixture.
      A problem with above is, if a low ThSAD and current_frame block is mostly noise, so compensated blocks could be judged bad because they are too different to the bad noisey block, and the result
    block may/will be just as bad as the noisy source block. A possible solution to this problem is to have a higher SAD threshold and/or have a bigger BlkSize so that the number of bad source pixels
    after converting/scaling to as if an 8x8 block, will contain fewer bad noise pixels. So, SpotLess BlkSz arg would ideally maybe 4 or more times the area of the largest spots that you have, and a SAD
    threshold big enough so as to not ignore the block [ wild guess minimum SAD threshold for big spot sizes of (8x8x255)/4 = 4080 ].
    Where a complete source frame is bad, then maybe should have very high (eg 10000) SAD threshold, and BlkSz may not really matter too much.
      It is not the end of the world if some of the compensated blocks are ignored and swapped for the original current_frame block. Nor is it the end of the world if
    no blocks were ignored because of high SAD threshold. The final result pixel is median pixel value of (2*RadT+1) motion compensated blocks, so allowing for some mistakes by choosing the
    middle [EDIT: median] pixel value.
    I've just tested real bad double frame, full frame luma and chroma corruption, with below line:
        SpotLess(RadT=5,ThSAD=1000000,ThSAD2=1000000,pel=2,chroma=false,BlkSz=8,Olap=4,tm=false,glob=false,bBlur=0.0)
    And although both SAD thresholds of 1 million, are totally impossible and so no blocks could possibly be ignored and yet we still got pretty good results, all frames were fixed
    as we still had the temporal median filter to fall back on and pick the middle pixel value.

    From mvtools2 docs:
      ThSAD is SAD threshold for safe (dummy) compensation.
          If block SAD is above the thSAD, the block is bad, and we use source block instead of the compensated block. Default is 10000 (practically disabled).

ThSAD2, Default ThSAD, 0 < ThSAD2 < 16320(8*8*255), Lower removes fewer spots, but less chance of blurring.
    ThSAD2 sets the SAD [Sum of Absolute Differences] threshold for most distant frame from current_frame at distance RadT, with those frames that are distances in-between 1 and RadT
    acquiring a SAD threshold linearly interpolated between the two.
    From mvtools2 docs:
      ThSAD2:
          Defines the SAD soft threshold for the furthest frames at current_frame +- RadT.
          The actual SAD threshold for each reference frame is a smooth interpolation between the original thSAD (close to the current frame)
          and thSAD2. Setting thSAD2 lower than thSAD allows large temporal radii and good compensation for low SAD blocks while reducing the global error and the
          risk of bluring when the result of MCompensate is passed to a temporal denoising filter.
    EDIT: Although I have said that SAD threshold being too high could result in blurred frames, that is really taken from above "risk of bluring" line from mvtools docs,
    however, that warning says "temporal denoising filter", which might suggest pixel averaging, whereas we are using pixel median. I'm not sure that blurring would be the result
    of having too high a SAD threshold.
Several guys earlier in thread did some mods where arms/legs were recovered, there are links to other scripts.

Also, Dogways posted here:- https://forum.doom9.org/showthread.p...48#post1959548
Quote:
It might be obvious but maybe looking into current algorithms (Wiki) can provide some insight. I plan to give it a stab in a few weeks.
So maybe something in the pipeline one day.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th August 2022 at 06:14.
StainlessS is offline   Reply With Quote
Old 14th August 2022, 16:14   #235  |  Link
johnmeyer
Registered User
 
Join Date: Feb 2002
Location: California
Posts: 2,691
Thanks for those hints. That helps a lot.
johnmeyer is offline   Reply With Quote
Old 28th September 2022, 04:05   #236  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
SpotLess v1.07, see first post.

Repeat post here, and zip @ mediafire in sig below this post.

SpotLess.avsi v1.07

Code:
/*
    SpotLess v1.07. temporal spot/noise remover, by StainlessS @ Doom9.   https://forum.doom9.org/showthread.php?t=181777
    Original idea from Didée post :-                                      https://forum.doom9.org/showthread.php?p=1402690#post1402690
    Req:- Pinterf MvTools2(), Pinterf Medianblur2() with MedianBlurTemporal rather than the MedianBlurT() from Didée post.
          With appropriate plugins, will be AVS+ colorspace and x64 compatible.
          Fine using Avs+ Prefetch() so long as current Pinterf plugins, and Frame Accurate source. RequestLinear() following the source filter might suffice as frame accurate source filter.

    NOT FOR cartoon/anime, live video only, sorry.

    v1.01, Remove RadT Max check. Add MSuper(hpad=16,vpad=16). Add BlkSz arg.
    v1.02, Add some stuff.
    v1.03, Frame size auto config of args removed (found instances where caused problems). Added Glob and bBlur args.
    v1.04, Script breaking changes, I guess is more flexible if can also set ThSAD, inserted ThSAD 3rd arg. RadT now default 1, was 2, dont over denoise unless requested.
    v1.05, Additional checks on args.
    v1.06, Glob Default true, Almost always better.
    v1.07, bBlur Default changed from 0.0 OFF, to 0.3, slower but better for mc analysis. Maybe try 0.6 for HD to overcome HD 'grittiness'.
               ThSAD default changed from 10,000 to 255 * (8/2 * 8/2), ie 1/4 of 8x8 block at 255, ie 1/4 BlkSz spots @ max SAD. Also ThSAD2 a bit less than ThSAD.
               Added dc arg, detect clip.

    SpotLess(clip c,int "RadT"=1,int "ThSAD"=255*(8/2 * 8/2),int "ThSAD2"=ThSAD-(8*8),int "pel"=2,bool "chroma"=true, int "BlkSz"=8,Int "Olap"=BlkSz/2,
            \ bool "tm"=true,Bool "glob"=True,Float "bBlur"=0.3, clip "dc"=Undefined)

    RadT, 1 or more, Default 1. Removes Spots on up to RadT [Temporal Radius] consecutive frames.
        RadT > 2 will usually be overkill. Setting too high could possibly result in blurring.
        Each pixel in result frame is median pixel value of (2*RadT+1) motion compensated frames (including source, ie current_frame-RadT to current_frame+RadT).

    ThSAD, Default 255 * (8/2 * 8/2) ie 4080 <ie 1/4 of 8x8 block at 255, ie 1/4 BlkSz spots @ max SAD>.
        0 < ThSAD < 16320(8*8*255). 8x8 block SAD threshold at radius 1 (ie at current_frame +- 1) [SAD, Sum of Absolute (pixelwise) Differences].
        ThSAD and ThSAD2 suggested absolute minimum of maybe about 400.
        ThSAD and ThSAD2 thresholds are based on 8 bit 8x8 block, irrespective of colorspace depth or BlkSz, max=8x8x255=16320, use same thresholds where High Bit Depth.
        In mvTools MCompensate(), when creating a compensated block the SAD between compensated block and the same original block in current_frame, the 8 bit SAD is measured and if
        greater than SAD threshold then that block is ignored and uses original block from current frame instead. [The compensated block is judged too different, so ignored & original block used instead
        in the result MCompensated frame].
        Where eg ThSAD=64, AVERAGE absolute single pixel difference threshold would be 64/(8*8)=1, so AVERAGE absolute pixel difference greater than 1 would ignore that mcompensated block and use the
        block from current frame in the resulting mcompensated frame instead. This example allows for all pixels in a 8x8 block to be different by 1, or a single pixel in 8x8 block to be different by 64,
        or some other mixture.
          A problem with above is, if a low ThSAD and current_frame block is mostly noise, so compensated blocks could be judged bad because they are too different to the bad noisey block, and the result
        block may/will be just as bad as the noisy source block. A possible solution to this problem is to have a higher SAD threshold and/or have a bigger BlkSize so that the number of bad source pixels
        after converting/scaling to as if an 8x8 block, will contain fewer bad noise pixels. So, SpotLess BlkSz arg would ideally maybe 4 or more times the area of the largest spots that you have, and a SAD
        threshold big enough so as to not ignore the block [ wild guess minimum SAD threshold for big spot sizes of (8x8x255)/4 = 4080 ].
        Where a complete source frame is bad, then maybe should have very high (eg 10000) SAD threshold, and BlkSz may not really matter too much.
          It is not the end of the world if some of the compensated blocks are ignored and swapped for the original current_frame block. Nor is it the end of the world if
        no blocks were ignored because of high SAD threshold. The final result pixel is median pixel value of (2*RadT+1) motion compensated blocks, so allowing for some mistakes by choosing the
        middle pixel value.
        I've just tested real bad double frame, full frame luma and chroma corruption, with below line:
            SpotLess(RadT=5,ThSAD=1000000,ThSAD2=1000000,pel=2,chroma=false,BlkSz=8,Olap=4,tm=false,glob=false,bBlur=0.0)
        And although both SAD thresholds of 1 million, are totally impossible and so no blocks could possibly be ignored and yet we still got pretty good results, all frames were fixed
        as we still had the temporal median filter to fall back on and pick the middle pixel value.

        From mvtools2 docs:
          ThSAD is SAD threshold for safe (dummy) compensation.
              If block SAD is above the thSAD, the block is bad, and we use source block instead of the compensated block. Default is 10000 (practically disabled).

    ThSAD2, Default ThSAD-(8*8), 0 < ThSAD2 <= ThSAD < 16320(8*8*255), Lower removes fewer spots, but less chance of blurring.
        ThSAD2 sets the SAD [Sum of Absolute Differences] threshold for most distant frame from current_frame at distance RadT, with those frames that are distances in-between 1 and RadT
        acquiring a SAD threshold linearly interpolated between the two.
        From mvtools2 docs:
          ThSAD2:
              Defines the SAD soft threshold for the furthest frames at current_frame +- RadT.
              The actual SAD threshold for each reference frame is a smooth interpolation between the original thSAD (close to the current frame)
              and thSAD2. Setting thSAD2 lower than thSAD allows large temporal radii and good compensation for low SAD blocks while reducing the global error and the
              risk of bluring when the result of MCompensate is passed to a temporal denoising filter.
        EDIT: Although I have said that SAD threshold being too high could result in blurred frames, that is really taken from above "risk of bluring" line from mvtools docs,
        however, that warning says "temporal denoising filter", which might suggest pixel averaging, whereas we are using pixel median. I'm not sure that blurring would be the result
        of having too high a SAD threshold.

    Pel,     Default 2. 1, 2, or 4. Maybe set 1 for HD+. (1=precision to pixel, 2=half pixel, 4=quarter pixel)

    Chroma,  Default True. MAnalyse chroma arg. If true, use chroma in block matching when creating vectors. Maybe use False if source B&W or color noise.

    BlkSz,   Default 8. MAnalyse BlkSize. Bigger blksz quicker and perhaps better for HD clips. [Info: current Pinterf MvTools allows for BlkSize=12, and overlap=6]

    OLap,    Default half BlkSz, Block overlap.

    Tm,      TrueMotion Default True. Some folk swear truemotion=false is better.

    Glob,    Default True (True v1.06, was same as Tm, true almost always better), Allow set MAnalyse(global) independently of TrueMotion.
             From MvTools2 docs for MAnalyse,
               global
                 Estimate global motion (at every level) and use it as an additional predictor.
                 Only pan shift is estimated (no zoom and rotation).
                 Use false to disable, use true to enable.

    bBlur,   Default 0.3. If used, Suggest about 0.3, where MAnalyse create vectors is performed on denoised (blurred) super clip
             for better motion analysis. Maybe try 0.6 for HD clip to counteract HD 'grittiness'. bBlur ignored if dc clip specified,
             If providing bBlur, then ALWAYS specify as named argument ie bBlur=bBlur, we will likely insert any additional MvTools args
             before bBlur to keep them together.

    dc,      Default UnDefined. If dc Specified, then must be same size and colorspace as source clip.
             If detection clip specified then bBlur prefilter arg is ignored, and analysis is performed on
             dc.MSuper() clip [ instead of c.Blur(bBlur).MSuper() ]. Allows to provide your own prefiltered clip.
             If providing dc clip, then ALWAYS specify as named argument ie dc=DC, we will likely insert any additional MvTools args
             before bBlur to keep them together.

*/

Function SpotLess(clip c,int "RadT",int "ThSAD",int "ThSAD2",int "pel",bool "chroma", int "BlkSz",Int "Olap",bool "tm",Bool "glob",
    \ Float "bBlur", clip "dc" ) {
    myName   = "SpotLess: "
    RadT     = Default(RadT,1)                 # Temporal radius. (MCompensate arg)
    ThSAD    = Default(ThSAD,255*(8/2 * 8/2))  # SAD threshold at radius 1. Here is max'ed out at 255 * 1/4 of 8*8 block <ie 4080> (MvTools Default 10,000 is nearly OFF, maybe way Too High).
                                               #     Maybe above 255*8/2*8/2 still a bit high, maybe 128*(8/2 * 8/2) Better <ie 2048>. For General noise perhaps somethimg like 24 * (8 * 8) <ie 1536>.
    ThSAD2   = Default(ThSAD2,ThSAD-(8*8))     # SAD threshold at radius RadT(a bit less than ThSAD).
    Pel      = Default(pel,2)                  # Default 2. 1, 2, or 4. Maybe set 1 for HD+. (1=precision to pixel, 2=precision to half pixel, 4=quarter pixel)
    Chroma   = Default(chroma,True)            # MAnalyse chroma arg. If set to true, use chroma in block matching.
    BlkSz    = Default(BlkSz,8)                # Default 8. MAnalyse BlkSize. Bigger blksz quicker and perhaps better, esp for HD clips. Maybe also better where BIG noise.
    OLap     = Default(OLap, BlkSz/2)          # Default half of BlkSz.
    Tm       = Default(tm,True)                # TrueMotion, Some folk swear MAnalyse(truemotion=false) is better.
    Glob     = Default(glob,True)              # Default True, Allow set MAnalyse(global) independently of TrueMotion.
    bBlur    = Default(bblur,0.3)              # Default 0.3. Suggest about 0.3 for better motion analysis, but a bit slower.
    HasDC    = dc.Defined                      # bblur ignored if HasDC, ie user already provided prefiltered clip.
    Assert(1 <= RadT,myName + " 1 <= RadT")
    Assert(0.0 <= bblur <= 1.58, myName + "0.0 <= bblur <= 1.58")
    Assert(pel==1 || pel==2 || pel==4, myName + "pel==1 || pel==2 || pel==4")
    pad = max(BlkSz,8)
    sup = (HasDC ? dc : bBlur>0.0  ? c.blur(bBlur) : c ).MSuper(hpad=pad,vpad=pad,pel=pel, sharp=2)
    # Only 1 Level required where not MAnalyse-ing.
    sup_rend = (HasDC||bBlur>0.0) ? c.MSuper(hpad=pad,vpad=pad,pel=pel, sharp=2,Levels=1) : sup
    MultiVec = sup.MAnalyse(multi=true, delta=RadT,blksize=BlkSz,overlap=OLap,chroma=Chroma,truemotion=Tm,global=Glob)
    c.MCompensate(sup_rend, MultiVec, tr=RadT, thSad=ThSAD, thSad2=ThSAD2)
    MedianBlurTemporal(radiusY=0,radiusU=0,radiusV=0,temporalradius=RadT)  # Temporal median blur only [not spatial]
    SelectEvery(RadT*2+1,RadT)                                             # Return middle frame
}
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 28th September 2022, 06:52   #237  |  Link
TDS
Formally known as .......
 
TDS's Avatar
 
Join Date: Sep 2021
Location: Down Under.
Posts: 965
[QUOTE=StainlessS;1975475]SpotLess v1.07, see first post.

Repeat post here, and zip @ mediafire in sig below this post.

SpotLess.avsi v1.07

Can't find it
__________________
Long term RipBot264 user.

RipBot264 modded builds..
TDS is offline   Reply With Quote
Old 28th September 2022, 10:42   #238  |  Link
kedautinh12
Registered User
 
Join Date: Jan 2018
Posts: 2,153
[QUOTE=TDS;1975479]
Quote:
Originally Posted by StainlessS View Post
SpotLess v1.07, see first post.

Repeat post here, and zip @ mediafire in sig below this post.

SpotLess.avsi v1.07

Can't find it
Just copy script above
kedautinh12 is online now   Reply With Quote
Old 28th September 2022, 13:44   #239  |  Link
TDS
Formally known as .......
 
TDS's Avatar
 
Join Date: Sep 2021
Location: Down Under.
Posts: 965
[QUOTE=kedautinh12;1975492]
Quote:
Originally Posted by TDS View Post

Just copy script above
I did do that, but the other option is not there....that's all.

I had this working a while back, but something must have changed, as currently, I can't get it to work.

But it's a script I wouldn't use too often, anyway.

Thanks.
__________________
Long term RipBot264 user.

RipBot264 modded builds..
TDS is offline   Reply With Quote
Old 28th September 2022, 14:28   #240  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Sorry, and thanks guys, its on MediaFire now.

@ TDS,
maybe you missed out the final "}" at end of script, its easily done.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 28th September 2022 at 14:56.
StainlessS is offline   Reply With Quote
Reply

Tags
denoise, despot, prefilter

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 10:35.


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