View Full Version : Better Dirt Removal Method..?
VideoMilk78
26th April 2025, 23:48
I've recently received scans to some martial arts films. Most dirt removal methods e.g. spotless, removedirtmc, and remove spots all remove limbs and what not... I've looked into delta restore but it's just not suitable for my needs, the closest I've gotten is Despot with the adjustable max spot size but the actual cleaning part of despot isn't great. I have already figured out a motion compensation algorithm but am not versed in Avisynth enough to tackle actual dirt removal. These are my requirements:
1. A dirt removal method that has the ability to specify minimum and maximum horizontal and vertical spot size
2. Is able to fill in colored scratches with minimum splotches
3. Has minimum effect on the grain although if this is a tradeoff I can deal with it
Thanks in advance
StainlessS
27th April 2025, 10:02
Posted elsewhere [for Descratch]:
DeScratch is a Spatial only filter to remove eg scratches on film.
To be of much use it would need be used before any temporal processing that would migrate the scratches to other frames,
making the problem more difficult to correct. As such, I would say that it would need to be applied before anything
else in your current script.
I have had limited success with Descratch, but very light settings can help, it also has a nasty habit of removing vertical edges that
should be there, eg telegraph poles sometimes disappear.
Posted elsewhere [for Despot]:
blur (from 0 to 4, default 1)
Value (length) of local spatial blur near borders of deleted spots
tsmooth (from 0 to 127, default 0)
Control temporal smoothing in static areas (except spots and motion).
Set approximate threshold of pixel luma variance in 3 frames,
The more variance exceed this threshold, the less temporal smoothing.
0 - no temporal smoothing.
Blur, I think only affects a little area around a removed spot, should not really be a problem.
Suggest never use tsmooth (ever), but especially if doing mulitple passes of despot with different parameters.
EDIT: Using tsmooth will migrate non-removed spots into adjacent frames making them un-removable
in future despot passes.
tsmooth is frame global except where spots removed, without tsmooth, only alters frame where spots are fixed.
So, if doing multiple Despots at differing spot sizes, always use tsmooth=0, except maybe on last Despot instance, and/or no additional temporal processing later.
Some despot stuff from long ago:- https://forum.doom9.org/showthread.php?p=1444658#post1444658 # oops fixed link
Some Descratch stuff from long ago:- https://forum.doom9.org/showthread.php?p=1688042#post1688042
VideoMilk78
27th April 2025, 22:55
Thanks for the recommendation, another question I have is whether or not Despot can utilize more than F,O,B? Can I use more vectors? Up to 5 would be ideal...
Docs state this
bool mc = false
Uses a 3-fold interleaved stream to allow motion-compensated analysis. Only the second frame every three frames is processed and returned. The input stream should be in the form: Interleave (forward, original, backward), where forward and backward are the frames N-1 and N+1 reconstructed with motion compensation. See the MVTools2 plug-in for more information.
StainlessS
28th April 2025, 08:52
Can I use more vectors? Up to 5 would be ideal...
The mc arg was added after my last serious use of DeSpot [linked post was 2010, mc arg added 2013].
Dont think so, sorry.
There is no example use of mc arg in docs, but there is example usage of motion compensated despot in despot docs
:- http://avisynth.nl/index.php/DeSpot
# Example script with external mask from MVTools2 (you may tune optional MAnalyse parameters):
AviSource("Blah.avi")
i = last
prefilt = i.DeGrainMedian() # prefiltered for better motion analysis
# analyse and compensate motion forward and backward (to current frame)
ml = 100 # mask scale
thscd1 = 400 # scene change
super=i.MSuper() # super clip
superprefilt = prefilt.MSuper() # super filtered clip
vf = superprefilt.MAnalyse(isb=false) # forward vectors
cf = i.MFlow(super, vf, thscd1 = thscd1) # previous compensated forward
sadf = i.MMask(vf, ml=ml,kind=1,gamma=1, thscd1 = thscd1) # forward SAD mask
msadf = sadf.MT_Binarize(20, upper=true) # binary inverted forward SAD mask
vb = superprefilt.MAnalyse(isb=true) # backward vectors
cb = i.MFlow(super, vb, thscd1 = thscd1) # next compensated backward
sadb = i.MMask(vb, ml=ml, gamma=1, kind=1, thscd1 = thscd1) # backward SAD mask
msadb = sadb.MT_Binarize(20, upper=true) # binary inverted backward SAD mask
msad = MT_Logic(msadf,msadb,"or") # combined inverted SAD mask
msad = msad.MT_Expand() # expanded inverted SAD mask
msadi = Interleave(msad, msad, msad) # interleaved 3-frame inverted SAD mask
# This mask is high (255) where at least one motion estimation is good,
# so these areas will be protected
Interleave(cf,i,cb) # interleave forward compensated, source, and backward compensated
DeSpot(p1=30,p2=12,pwidth=800,pheight=600,mthres=20,merode=33,\
sign=0,show=0,seg=0,color=true,motpn=true, extmask=msadi)
SelectEvery(3,1) # get filtered source
which looks not too dissimilar to DeNoiseNEW() in 2010 linked thread.
If you do (desperately) want to try 2 forward / 2 backward vectors, then you would need achieve that yourself, and avoid the mc arg thingy,
and pluck out the middle frame of every 5 on completion.
Perhaps someone else knows how best to add the additional vectors into the mix. [I just dont feel up to it :( ]
EDIT: Actually, I dont think that you can use 2 fwd, 2 bkwd, I dont think it makes sense, the despot thingy works by
compare with adjacent frames, not by adjacent AND adjacent +/- 1 frames, so it dont make sense, (at least to me).
EDIT: Sounds to me like the mc arg just does the equivalent of the SelectEvery(3,1) above in CODE block in BLUE.
VideoMilk78
28th April 2025, 23:39
Does removedirt (restore motion blocks) only have access to first and last or is it static? If this is the case then if it can work with more than backw/forw then shouldn't despot with mc=false work the same? If not knowing your skill would it not be pretty easy to modify it to do so?
StainlessS
29th April 2025, 11:52
Sorry, no can do, perhaps others with more experience of "removedirt (restore motion blocks)" and such can help,
I dont spend that much time with Avisynth or D9 nowadays.
VideoMilk78
29th April 2025, 18:45
Alright, no worries. I ended up figuring out a good solution for the actual cleaning :D However another problem has come up and that is the fact that Despot doesn't support HDR :(
Busty
10th May 2025, 17:27
@ VideoMilk78:
would you mind sharing your "good solution"? I'd like to try that on some VHS captures with errors a bit similar to scratches.
VideoMilk78
11th May 2025, 17:15
It will not work on VHS material
VideoMilk78
11th May 2025, 17:18
Here are some results on film
left=original
middle=cleaned
right=difference
https://i.postimg.cc/vgrPZ0mF/temp-Image69-A6uu.avif (https://postimg.cc/vgrPZ0mF)
https://i.postimg.cc/GHhMbJwV/temp-Image-CCf-Gc-P.avif (https://postimg.cc/GHhMbJwV)
Busty
12th May 2025, 20:26
I see. Although it wouldn't help me then, maybe someone else on this forum might benefit from your solution. Just saying.
VideoMilk78
4th June 2025, 21:42
@StainlessS would it be possible to add a minimum spot size parameter to despot?
StainlessS
5th June 2025, 11:46
Cant you just mess with DeNoiseLight as given in first link
Function DeNoiseLight(clip Last)
{
yuy2=(isYUY2())?true:false
Last= (yuy2)?Interleaved2planar():Last
DeSpot(p1=34,p2=12,mthres=14,color=true,tsmooth=0,pwidth=128,pheight=128,seg=2,mscene=25,show=0,planar=yuy2)
Last=(yuy2)?Planar2Interleaved():Last
Return Last
}
I think those to mess with are maybe p1, p2, mthres, seg.
EDIT: Untested
Function DeNoiseLight(clip Last,int "p1",int "p2",int "mthres",bool "color",int "seg")
{
p1 = Default(p1,34)
p2 = Default(p2,12)
mthres = Default(mthres,14)
color = Default(color,true)
seg = Default(seg,2)
yuy2=(isYUY2())?true:false
Last= (yuy2)?Interleaved2planar():Last
DeSpot(p1=p1,p2=p2,mthres=mthres,color=color,tsmooth=0,pwidth=128,pheight=128,seg=seg,mscene=25,show=0,planar=yuy2)
Last=(yuy2)?Planar2Interleaved():Last
Return Last
}
VideoMilk78
5th June 2025, 17:53
I'll give those parameters a try but I still think a minimum size parameter would prove useful
StainlessS
5th June 2025, 22:31
Then ask the author.
EDIT:
You will not likely find Kevin Atkinson , Fizick, or cretindesalpes (developers of despot),
You can explore docs on wiki, and call with additional args.
http://avisynth.nl/index.php/DeSpot
VideoMilk78
5th June 2025, 23:41
Ended up ditching despot and going back to removedirtmc and pairing it with my own restore grain script.
Heres the results I came up with and I think I'm going to settle with this for now.
https://i.postimg.cc/2Vxv7d7X/temp-Image-C2iet-G.avif (https://postimg.cc/2Vxv7d7X)
https://i.postimg.cc/1fSwF7wq/temp-Image-Ns-Yw-PU.avif (https://postimg.cc/1fSwF7wq)
johnmeyer
6th June 2025, 00:36
Despot is useless for removing dirt from film. I know because I spent hours and hours trying.
RemoveDirtMC works, but you have to get the right parameters. You'll find quite a few scripts I've posted. Just search using my user name and RemoveDirtMC.
SpotlessS also works really well and is better than RemoveDirtMC.
Lots of interesting information in this thread:
[film transfer] Remove dirt but keep grain? (https://forum.doom9.org/showthread.php?p=1942618#post1942618)
You'll find a "torture test" clip I provided for testing in this post:
https://forum.doom9.org/showthread.php?p=1945111#post1945111
It is a torture test because it contains several problems, like a baseball in flight, that can cause dirt removal to remove valid objects.
VideoMilk78
6th June 2025, 01:50
I thought despot had potential but as you say it seems I was wrong. I've read through the threads before however thank you for linking them as they are indeed full of knowledge.
StainlessS
6th June 2025, 09:01
Despot does have the advantage of only affecting detected spots area of frame (when tsmooth=0),
RemoveDirtMC, Spotless and others will affect full frame.
Despot can be difficult to use (hence my reluctance to play with it again).
VideoMilk78
6th June 2025, 15:13
Understandable, the main reason I wanted despot is the ability to specify the spot size but the actual repair ability is suboptimal.
If spotless could have parameters that would ignore spots any larger or smaller than the parameters specify that would be a game changer but I don't know how one would go about adding those
johnmeyer
6th June 2025, 17:56
The one thing that intrigued me about Despot is its ability to limit spot removal to white spots, or black spots. This cuts false removal by 50% when you know that spots are all black (for movie film) or white (for movie negatives or video dropouts).
StainlessS
6th June 2025, 18:53
The are lots of args, some of which I've never used (was updated since I last used it)
http://avisynth.nl/index.php/DeSpot
DeSpot (clip, int "mthres", int "mwidth", int "mheight", int "merode", bool "interlaced", bool "median", int "p1", int "p2", \
int "pwidth", int "pheight", bool "ranked", int "sign", int "maxpts", int "p1percent", int "dilate", bool "fitluma", int "blur", \
int "tsmooth", int "show", int "mark_v", bool "show_chroma", bool "motpn", int "seg", bool "color", int "mscene", \
int "minpts", clip "extmask", bool "planar", string "outfile", bool "mc", int "spotmax1", int "spotmax2")
Selur
6th June 2025, 19:08
(still hoping for a Vapoursynth port of Despot,... (https://github.com/vapoursynth/despot/issues/1))
VideoMilk78
6th June 2025, 20:15
The one thing that intrigued me about Despot is its ability to limit spot removal to white spots, or black spots. This cuts false removal by 50% when you know that spots are all black (for movie film) or white (for movie negatives or video dropouts).
That is a big one as well. Didn't seem that accurate though?
EDIT: I should mention that this isn't as big for me as most of the defects on my negative scans are blueish? Dunno why but it is what it is... maybe the ability to select an average color for defects?
VideoMilk78
6th June 2025, 20:55
(still hoping for a Vapoursynth port of Despot,... (https://github.com/vapoursynth/despot/issues/1))
Is this something else??
https://i.postimg.cc/06LSd8Fn/Screenshot-2025-06-06-at-3-53-57-PM.png (https://postimg.cc/06LSd8Fn)
Selur
7th June 2025, 05:06
That is not a proper port, that only supports the basic idea (see: https://github.com/Selur/VapoursynthScriptsInHybrid/blob/5873c560e1536bc96dc53e94d5f1302afbea71b5/artifacts.py#L7) which is why most of the options are disabled. myrsloik started a port, but sadly lot motivation/time. So there is no proper DeSpot for Vapourynth atm.
VideoMilk78
7th June 2025, 15:20
Ah, after all this fiddling with it I have given up and started playing with spotless+delta_restore again but with a more advanced restored grain function. might want to look into rewriting deltarestore for vapoursynth instead
tormento
13th June 2025, 10:33
might want to look into rewriting deltarestore for vapoursynth instead
If not much effort, please consider a AVS+ porting too.
VideoMilk78
14th June 2025, 03:48
If not much effort, please consider a AVS+ porting too.
Delta Restore is a function originally made for Avisynth+?
See https://forum.doom9.org/showthread.php?t=182831
tormento
14th June 2025, 09:27
Delta Restore is a function originally made for Avisynth+?
I’m 2021 as far as I can understand. Many things changed.
Selur
14th June 2025, 10:20
Many things changed.
They have?
Looking at the whole SpotDel: https://pastebin.com/UmLQny6Z
it requires:
# Dependencies:
# mvtools2: https://github.com/pinterf/mvtools/
# masktools2: https://github.com/pinterf/masktools
# MedianBlur2: https://github.com/pinterf/MedianBlur2 for MedianBlurTemporal in SpotLess
# manyPlus: http://www.avisynth.nl/users/vcmohan/index.html for GBlur
tormento
14th June 2025, 19:03
They have?
Does it support other spaces than YV12?
VideoMilk78
14th June 2025, 20:14
Seemingly, I've used it on 2k hdr scans
VideoMilk78
14th June 2025, 20:15
They have?
Looking at the whole SpotDel: https://pastebin.com/UmLQny6Z
it requires:
# Dependencies:
# mvtools2: https://github.com/pinterf/mvtools/
# masktools2: https://github.com/pinterf/masktools
# MedianBlur2: https://github.com/pinterf/MedianBlur2 for MedianBlurTemporal in SpotLess
# manyPlus: http://www.avisynth.nl/users/vcmohan/index.html for GBlur
I actually recommend using the one linked here
https://forum.doom9.org/showthread.php?p=1946031#post1946031
It seems to give me better results although maybe I'm seeing things
Selur
19th March 2026, 21:06
For those interested in a Vapoursynth port, see SpotDelta (https://github.com/Selur/VapoursynthScriptsInHybrid/blob/master/SpotLess.py).
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.