View Full Version : Remove Moirè effect with AviSynth+
banaguitar
14th October 2022, 18:45
Hello, how can I remove this kind of moirè effect from an old betamax video? It's already deinterlaced with qtgmc.
https://drive.google.com/file/d/1d8_mi04IDYUgBEuXmJR7YkfjrAWX4w9m/view?usp=sharing
Thanks for helping me.
johnmeyer
14th October 2022, 18:51
You deinterlaced already?? Can you still go back to the original? I ask that because of what was discovered in THIS thread:
Deinterlacing PAL gives wave artifacts (forum.doom9.org/showthread.php?p=1941010)
Another thread to look at:
Moire Effect & TFM(pp=0) Solution (http://forum.doom9.org/showthread.php?t=182154)
Selur
14th October 2022, 20:48
At this point, something like SpotLess + MCTemporalDenoise + CAS seems to do a decent job.
https://i.ibb.co/sV5Nk3N/von-der-Lipp-329.png (https://ibb.co/W2DMqKM)
(I used Vapoursynth, but those filters are available for Avisynth too.)
Also, adding some dehalo filtering might be a good idea.
Cu Selur
banaguitar
14th October 2022, 21:47
You deinterlaced already?? Can you still go back to the original? I ask that because of what was discovered in THIS thread:
Deinterlacing PAL gives wave artifacts (forum.doom9.org/showthread.php?p=1941010)
Another thread to look at:
Moire Effect & TFM(pp=0) Solution (http://forum.doom9.org/showthread.php?t=182154)
Yes, I already deinterlaced, but I can go back to the original video, that's no problem.
banaguitar
14th October 2022, 21:48
At this point, something like SpotLess + MCTemporalDenoise + CAS seems to do a decent job.
https://i.ibb.co/sV5Nk3N/von-der-Lipp-329.png (https://ibb.co/W2DMqKM)
(I used Vapoursynth, but those filters are available for Avisynth too.)
Also, adding some dehalo filtering might be a good idea.
Cu Selur
That's looks very fine
banaguitar
15th October 2022, 17:15
Here is my final script:
Import("FixRipsp2.avs")
Import("RemoveDirtMC.avs")
Import("LimitedSharpenFaster.avs")
FFVideoSource("C:\sample_raw.avi")
QTGMC(InputType=2, TR2=2)
SeparateFields()
e=SelectEven().FixRipsp2.RemoveDirtMC(50,false)
o=SelectOdd().FixRipsp2.RemoveDirtMC(50,false)
Interleave(e,o)
AddGrainC(var=1.0, uvar=0.0, hcorr=0.0, vcorr=0, seed=-1, constant=false, sse2=true)
LimitedSharpenFaster()
Weave()
Does it get even better? What are your thougths?
Before and after samples:
https://drive.google.com/file/d/1LLdJ5UvvWXKTMqBbXNMyc1Dq2KC1KZUK/view?usp=sharing
https://drive.google.com/file/d/1sGG7q_slxOZMto3NyJHkt6YfiDfvG39m/view?usp=sharing
Selur
15th October 2022, 20:37
Does it get even better? What are your thougths?
Not wanting to be rude, but in my opinion, your second video is shit.
You got an interlaced avi, you didn't deinterlace it and encoded it as progressive. (WTF)
(I also think putting hevc inside an .avi container is a bad idea, but that might be debatable.)
Either deinterlace at some point or save your file as interlaced.
johnmeyer
15th October 2022, 22:56
You blurred the problem out of existence, but I am not thrilled with the result.
banaguitar
16th October 2022, 08:55
@Selur: Thanks for your honest opinion und you are absolutely right. It looks horrible. I deinterlaced it now and put the avi in a mkv container.
@johnmeyer: I am unhappy too. I am a complete beginner in avisynth.
I changed the code:
SetFilterMTMode ("QTGMC", 2)
FFVideoSource("C:\Sample_raw.avi")
AssumeBFF()
QTGMC(preset="very slow")
MCTemporalDenoise(settings="low", edgeclean=true, ecrad=3, stabilize=true, maxr=2)
LimitedSharpenFaster()
To be honest, it looks better than before, but still not perfect. Maybe defreq could help, but I have no idea what to do with it.
Original:
https://drive.google.com/file/d/1LLdJ5UvvWXKTMqBbXNMyc1Dq2KC1KZUK/view?usp=sharing
Sample after:
https://drive.google.com/file/d/19X6uUncIwzhTNoqFrEAAmbCP4NA8mW9M/view?usp=sharing
kedautinh12
16th October 2022, 09:36
At this point, something like SpotLess + MCTemporalDenoise + CAS seems to do a decent job.
https://i.ibb.co/sV5Nk3N/von-der-Lipp-329.png (https://ibb.co/W2DMqKM)
(I used Vapoursynth, but those filters are available for Avisynth too.)
Also, adding some dehalo filtering might be a good idea.
Cu Selur
It's would better if you share your scripts. Banaguitar will trans it to avs+
banaguitar
16th October 2022, 11:48
It's would better if you share your scripts. Banaguitar will trans it to avs+
Or trial and error:D
kedautinh12
16th October 2022, 12:00
Or trial and error:D
You can try and discovery more pleasures :D
Selur
16th October 2022, 12:10
It's would better if you share your scripts. Banaguitar will trans it to avs+
# deinterlacing
AssumeBFF()
QTGMC(Preset="Fast", ediThreads=2)
# filtering
# despotting using SpotLess
SpotLess(RadT=3)
# denoising using MCTemporalDenoise
MCTemporalDenoise(settings="very high")
# sharpening
CAS(sharpness=0.70)
Should be similar to what I did in Vapoursynth:
# Imports
import vapoursynth as vs
import os
import ctypes
# Loading Support Files
Dllref = ctypes.windll.LoadLibrary("i:/Hybrid/64bit/vsfilters/Support/libfftw3f-3.dll")
import sys
# getting Vapoursynth core
core = vs.core
# Import scripts folder
scriptPath = 'i:/Hybrid/64bit/vsscripts'
sys.path.insert(0, os.path.abspath(scriptPath))
# Loading Plugins
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libvs_placebo.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/TTempSmooth/TTempSmooth.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/NEO_FFT3DFilter/neo-fft3d.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/DCTFilter.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeblockFilter/Deblock/Deblock.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libtemporalmedian.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/RemoveGrain/RemoveGrainVS.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/GrainFilter/AddGrain/AddGrain.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/FFT3DFilter/fft3dfilter.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DenoiseFilter/DFTTest/DFTTest.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/EEDI3m.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/ResizeFilter/nnedi3/NNEDI3CL.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/libmvtools.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/scenechange.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/Support/fmtconv.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/MiscFilter/MiscFilters/MiscFilters.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/DeinterlaceFilter/Bwdif/Bwdif.dll")
core.std.LoadPlugin(path="i:/Hybrid/64bit/vsfilters/SourceFilter/LSmashSource/vslsmashsource.dll")
# Import scripts
import SpotLess
import havsfunc
# source: 'C:\Users\Selur\Desktop\Sample_raw.avi'
# current color space: YUV420P8, bit depth: 8, resolution: 720x576, fps: 25, color matrix: 470bg, yuv luminance scale: limited, scanorder: bottom field first
# Loading C:\Users\Selur\Desktop\Sample_raw.avi using LWLibavSource
clip = core.lsmas.LWLibavSource(source="C:/Users/Selur/Desktop/Sample_raw.avi", format="YUV420P8", stream_index=0, cache=0, prefer_hw=0)
# Setting color matrix to 470bg.
clip = core.std.SetFrameProps(clip, _Matrix=5)
clip = clip if not core.text.FrameProps(clip,'_Transfer') else core.std.SetFrameProps(clip, _Transfer=5)
clip = clip if not core.text.FrameProps(clip,'_Primaries') else core.std.SetFrameProps(clip, _Primaries=5)
# Setting color range to TV (limited) range.
clip = core.std.SetFrameProp(clip=clip, prop="_ColorRange", intval=1)
# making sure frame rate is set to 25
clip = core.std.AssumeFPS(clip=clip, fpsnum=25, fpsden=1)
# setting field order to what QTGMC should assume (bottom field first)
clip = core.std.SetFrameProp(clip=clip, prop="_FieldBased", intval=1)
# Deinterlacing using QTGMC
clip = havsfunc.QTGMC(Input=clip, Preset="Fast", TFF=False, opencl=True) # new fps: 50
# make sure content is preceived as frame based
clip = core.std.SetFieldBased(clip, 0)
clip = SpotLess.SpotLess(clip=clip, radT=3)
# cropping the video to 682x566
clip = core.std.CropRel(clip=clip, left=18, right=20, top=4, bottom=6)
clip = core.std.AddBorders(clip=clip, left=0, right=2, top=0, bottom=2) # add borders to archive mod 4 (vsMCT) - 684x568
# denoising using MCTemporalDenoise
clip = havsfunc.MCTemporalDenoise(i=clip, settings="very high", ncpu=1)
clip = core.std.CropRel(clip=clip, left=0, right=2, top=0, bottom=2) # removing borders (vsMCT) - 682x566
# adjusting color space from YUV420P8 to YUV444P16 for vsGLSLCAS
clip = core.resize.Bicubic(clip=clip, format=vs.YUV444P16, range_s="limited")
with open("i:/Hybrid/64bit/vsfilters/GLSL/parameterized/CAS.glsl") as glslf:
glsl = glslf.read()
glsl = glsl.replace('#define SHARPENING 0.0', '#define SHARPENING 0.3')
glsl = glsl.replace('#define CAS_BETTER_DIAGONALS 1', '#define CAS_BETTER_DIAGONALS 1')
glsl = glsl.replace('#define CAS_GO_SLOWER 0', '#define CAS_GO_SLOWER 1')
glsl = glsl.replace('#define SOURCE_TRC 0', '#define SOURCE_TRC 0')
glsl = glsl.replace('#define TARGET_TRC 0', '#define TARGET_TRC 0')
clip = core.placebo.Shader(clip=clip, shader_s=glsl, width=clip.width, height=clip.height)
# adjusting output color from: YUV444P16 to YUV420P8 for x264Model
clip = core.resize.Bicubic(clip=clip, dither_type="error_diffusion", format=vs.YUV420P8, range_s="limited")
# set output frame rate to 50fps
clip = core.std.AssumeFPS(clip=clip, fpsnum=50, fpsden=1)
# Output
clip.set_output()
Cu Selur
Reel.Deel
16th October 2022, 16:26
Here's my take: https://files.videohelp.com/u/223002/banaguitar.mp4
Script used:
FFVideoSource("Sample_raw.avi")
Crop(20,6,-20,-6)
ContinuityFixer(left=2, top=2, right=2, bottom=4, radius=2)
pre = last.nnedi3(field=-2).DestripeH().DestripeV()
QTGMCp(Preset="Slower", EdiExt=pre, TR2=3, NoiseProcess=1, NoiseRestore=0.0, Sigma=4.0)
o = last
x1 = o.fluxsmootht(4)
x2 = o.removegrain(11,-1)
x22 = o.mt_makediff(mt_makediff(x2,x2.removegrain(20,-1))).MinMapBlur()
x222 = x22.removegrain(4,-1)
x222 = x222.sbr().merge(x222,0.51)
enhD = mt_lutxy(x22,x222,"128 x y - abs 2 / 1 1.6 / ^ 2.51 * x y - x y - abs 0.1 + / * +",U=2,V=2)
enh = o.mt_adddiff(enhD,U=2,V=2)
BLK = 16 # 8
ME1 = 5
ME2 = 2 # 8
_DCT = 5
sup1 = enh.MSuper(hpad=16, vpad=16, pel=2, levels=0,sharp=1)
sup2 = x1.removegrain(11).MSuper(hpad=16, vpad=16, pel=2, sharp=0)
bv2 = MAnalyse(sup2,delta=2,truemotion=false,global=true,blksize=BLK,overlap=BLK/2,search=ME1,searchparam=ME2,isb=true, dct=_DCT)
bv1 = MAnalyse(sup2,delta=1,truemotion=false,global=true,blksize=BLK,overlap=BLK/2,search=ME1,searchparam=ME2,isb=true, dct=_DCT)
fv1 = MAnalyse(sup2,delta=1,truemotion=false,global=true,blksize=BLK,overlap=BLK/2,search=ME1,searchparam=ME2,isb=false,dct=_DCT)
fv2 = MAnalyse(sup2,delta=2,truemotion=false,global=true,blksize=BLK,overlap=BLK/2,search=ME1,searchparam=ME2,isb=false,dct=_DCT)
o.mdegrain2(sup1,bv1,fv1,bv2,fv2,thsad=400,thSCD1=256,thSCD2=96)
CAS()
AddBorders(20,6,20,6)
function MinMapBlur(clip c) {
map=mt_lutxy(c.mt_expand(),c.mt_inpand(),"x y - 1 3 / * 3 +")
a = c.removegrain(4,-1)
b = c.mt_mappedblur(map,"1 2 1 2 8 2 1 2 1","dump")
aD=mt_makediff(c,a)
bD=mt_makediff(c,b)
return(c.mt_makediff(mt_lutxy(aD,bD,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?"),U=2,V=2))
}
The script is a little slow but it gets rid of almost all artifacts while keeping a natural image.
Requirements are: Dogway's QTGMC+ and DeStripe (https://github.com/Dogway/) scripts (and associated requirements), sbr (https://github.com/Asd-g/AviSynth-sbr), FluxSmooth (https://github.com/pinterf/FluxSmooth/releases), EdgeFixer (https://github.com/sekrit-twc/EdgeFixer/releases) and CAS.
The additional denoising step is from Didée: https://forum.doom9.org/showthread.php?p=1532770#post1532770
banaguitar
16th October 2022, 17:43
Here's my take: https://files.videohelp.com/u/223002/banaguitar.mp4
Thank you so much. I like it, but it's a bit blurry.
Reel.Deel
16th October 2022, 17:55
Thank you so much. I like it, but it's a bit blurry.
That's what I meant with "natural", it's no more blurry than the source. Feel free to sharpen it to your liking. Your last sample in post #9 has that over-sharpened waxy/oil painting look, I always try to avoid that. Maybe something like SeeSaw would be a good final sharperner...
Edit:
Add this to the script above and the result will be a bit sharper while not accentuating the artifacts too much.
pre = last.nnedi3(field=-2).DestripeH().DestripeV().NonlinUSM(pow=1.0, rad=2, str=0.7)
You will need: http://avisynth.nl/index.php/NonlinUSM
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.