Log in

View Full Version : Filter region based


Mounir
9th May 2022, 20:29
I got a bit of a problem. I got this vhs that's got larges snowy patches (i mean large bands) here and there but the location is not always the same (top, bottom, middle etc..)

So far i came up with this but i don't know how i can adapt the filter border to deal with various locations in the same script. I really don't want to filter the whole frame.


# Noise Location 1:
avisource()
filter_borders(last, 0, 0, -0, -130)

function filter_borders(clip c, int Left, int Top, int Right, int Bottom)
{
inner = Crop(c, 0, 0, -0, -130)
ReplaceFramesSVPFlow(c,48135,1) #

Overlay(last, inner, Left, Top) # overlay unfiltered inner portion
}

This works fine then i'd like to do another noise location and a different frame in time:

Noise location 2 :
avisource()
filter_borders(last, 0, 170, -0, -0)

function filter_borders(clip c, int Left, int Top, int Right, int Bottom)
{
inner = Crop(c, 0, 170, -0, -0) # pour 48136

ReplaceFramesSVPFlow(c,50145,1)

Overlay(last, inner, Left, Top) # overlay unfiltered inner portion
}



LoadPlugin("C:\Program Files (x86)\AviSynth 2.6\plugins\svpflow1.dll")
LoadPlugin("C:\Program Files (x86)\AviSynth 2.6\plugins\svpflow2.dll")

function ReplaceFramesSVPFlow(clip Source, int N, int X)
{
# N is number of the 1st frame in Source that needs replacing.
# X is total number of frames to replace
#e.g. ReplaceFramesSVPFLow(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for SVPFlow interpolation

start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point

start+end
AssumeFPS(1) #temporarily FPS=1 to use mflowfps

super=SVSuper("{gpu:1}")
vectors=SVAnalyse(super, "{}")
SVSmoothFps(super, vectors, "{rate:{num:"+String(X+1)+", den:1}}", mt=1)

AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
Trim(1, framecount-1) #trim ends, leaving replacement frames

Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
}



Thanks for the help

manono
10th May 2022, 02:28
I'm not entirely sure what you're up to, but to filter a part of a frame or series of frames I do it this way:

###Interpolate part of a series of frames
A=Last
B=ReplaceFramesMC(30756,4)
B=B.Crop(610,0,0,-362)
Overlay(A,B,610,0)

Here's ReplaceFramesMC:
function ReplaceFramesMC(clip Source, int N, int "X")
{
# N is number of the 1st frame in Source that needs replacing.
# X is total number of frames to replace
#e.g. ReplaceFramesMC(101, 5) would replace 101,102,103,104,105 , by using 100 and 106 as reference points for mflowfps interpolation

X = Default(X, 1)

start=Source.trim(N-1,-1) #one good frame before, used for interpolation reference point
end=Source.trim(N+X,-1) #one good frame after, used for interpolation reference point

start+end
AssumeFPS(1) #temporarily FPS=1 to use mflowfps

super = MSuper(pel=2, hpad=0, vpad=0, rfilter=4)
backward_1 = MAnalyse(super, chroma=false, isb=true, blksize=16, searchparam=3, plevel=0, search=3, badrange=(-24))
forward_1 = MAnalyse(super, chroma=false, isb=false, blksize=16, searchparam=3, plevel=0, search=3, badrange=(-24))
backward_2 = MRecalculate(super, chroma=false, backward_1, blksize=8, searchparam=1, search=3)
forward_2 = MRecalculate(super, chroma=false, forward_1, blksize=8, searchparam=1, search=3)
backward_3 = MRecalculate(super, chroma=false, backward_2, blksize=4, searchparam=0, search=3)
forward_3 = MRecalculate(super, chroma=false, forward_2, blksize=4, searchparam=0, search=3)
MBlockFps(super, backward_3, forward_3, num=X+1, den=1, mode=0)

AssumeFPS(FrameRate(Source)) #return back to normal source framerate for joining
Trim(1, framecount-1) #trim ends, leaving replacement frames

Source.trim(0,-N) ++ last ++ Source.trim(N+X+1,0)
}

You can use your own interpolator. If only a single frame gets interpolated, you don't need the "1":

###Interpolate part of a single frame
A=Last
B=ReplaceFramesMC(30756)
B=B.Crop(610,0,0,-362)
Overlay(A,B,610,0)

jagabo at videohelp.com developed ReplaceFramesMC from an already existing interpolator. And, of course, it can be made more efficient by not using "A=Last" and replacing the "A" with "Last" in the last line. But that's the way my brain works.

Mounir
10th May 2022, 13:30
It don't seem to work the way i want. I have to use ReplaceFramesMC on a specific part of the frame (not the whole frame) and then change that part according to needs / use replaceframesmc again.

manono
10th May 2022, 20:15
I have to use ReplaceFramesMC on a specific part of the frame...
That's what the crop line does - it filters only the part of the frame(s) still uncropped. You save the ReplaceFramesMC as an avs or avsi. I load it as an "Import" line in the script. If saved as an avsi in your plugins folder it should load automatically.

...then change that part according to needs / use replaceframesmc again.
Every time you use it, change the crop values. Don't use the crop values I showed as they are just an example. I use it dozens of times with each movie project.

StainlessS
11th May 2022, 01:52
Mounir, is it anything like the stuff in this thread ? [single field damage]
Identify bad fields in a capture :- https://forum.doom9.org/showthread.php?t=183582

https://i.postimg.cc/1nhgNZ1T/defect-field-00.jpg (https://postimg.cc/1nhgNZ1T)

ie, is it always full width 'band' of crap ?
If always full width, how variable is the vertical position ? [EDIT: From your earlier posts is very variable, ie H=-130{bad bottom of frame} and Y=170{bad top of frame}]
If so, does it affect top or bottom fields only, or full frame ?
If single field only, is it always the same field ?
What is max consecutive frame count of bad frames ?

I will not be on-line (well not very likely) for at least two days. [EDIT: My busyness postponed until Thursday/Friday]

EDIT: A few threads I bookmarked, posted here to avoid having to find them again.

Identify bad fields in a capture :- https://forum.doom9.org/showthread.php?p=1960487&highlight=quad#post1960487
automate static removal :- https://forum.doom9.org/showthread.php?t=175640
DirtBox_MI v0.03 - 4th Sept 2018 :- https://forum.doom9.org/showthread.php?t=175708
Script and Time? :- https://forum.doom9.org/showthread.php?p=1711486
repair frames that start & stop at wrong position: https://forum.doom9.org/showthread.php?t=168410
Calculating row information? :- https://forum.doom9.org/showthread.php?p=1886303

Post a sample.

Mounir
11th May 2022, 14:30
Turns out i'm an idiot it can work like this just change the number for filter_borders2:

filter_borders(last, 0, 0, -0, -130)
function filter_borders(clip c, int Left, int Top, int Right, int Bottom)
{
inner = Crop(c, 0, 0, -0, -130)
ReplaceFramesSVPFlow(c,48135,1) #
Overlay(last, inner, Left, Top) # overlay unfiltered inner portion
}
#
filter_borders2(last, 0, 172, -0, -0)
function filter_borders2(clip c, int Left, int Top, int Right, int Bottom)
{
inner = Crop(c, 0, 172, -0, -0)
ReplaceFramesSVPFlow(c,50014,1) #

Overlay(last, inner, Left, Top) # overlay unfiltered inner portion
}