View Full Version : DeHalo-ing only certain segments
asarian
13th November 2010, 05:29
Hello,
I'd like to dehalo parts of an Anime, but not the entire source. Let's say I have a total of 1,000 frames, and I want to add an additional dehalo_alpha and unfilter function to the section between, say, 400-500 frames. Is that possible with AviSynth?
I found something called ConditionalFilter (http://avisynth.org/mediawiki/ConditionalFilter), which looks like it might work for me; but, frankly, I have no idea how it's done. It all looks incredibly complex. Has anyone ever done this before? If so, I wouldn't mind hearing how. :)
Thanks.
manono
13th November 2010, 06:05
Part of stickboy's RemapFrames filter is ReplaceFramesSimple which I usually use for this sort of thing:
http://avisynth.org/stickboy/
Its use would be something like this:
BaseClip=Last
SourceClip=BaseClip.YourFilterHere
ReplaceFramesSimple(BaseClip,SourceClip,Mappings="[0 46] [58 98] [116 155] [169 209]")
The number pairs are the first and last frame numbers where you want the filter used.
manono
13th November 2010, 06:09
If you're just going to use the filter once, as in your example, easier might be:
A=Trim(0,399)
B=Trim(400,500).YourFilterHere
C=Trim(501,0)
A+B+C
asarian
13th November 2010, 06:54
Part of stickboy's RemapFrames filter is ReplaceFramesSimple which I usually use for this sort of thing:
http://avisynth.org/stickboy/
Its use would be something like this:
BaseClip=Last
SourceClip=BaseClip.YourFilterHere
ReplaceFramesSimple(BaseClip,SourceClip,Mappings="[0 46] [58 98] [116 155] [169 209]")
The number pairs are the first and last frame numbers where you want the filter used.
Thanks, manono! This looks real promising! :) I'll go experiment with it rightaway!
Gavino
13th November 2010, 09:42
If you're just going to use the filter once, as in your example, easier might be:
A=Trim(0,399)
B=Trim(400,500).YourFilterHere
C=Trim(501,0)
A+B+C
Or, more simply:
ApplyRange (http://avisynth.org/mediawiki/ApplyRange)(400, 500, "YourFilterHere")
Masaru
15th November 2010, 18:14
I've always wondered which method of those is the least memory consuming. I remember always ending up with encoding each part separately on more complex scripts, as even trying to fully load one of those to AvsP resulted with an error.
Gavino
15th November 2010, 19:14
As far as memory use is concerned, they should all be more or less the same, and cannot really be bettered for the example cases given.
However, if you want to apply the filter to several different segments (with the same arguments each time), then ReplaceFramesSimple (manono's first suggestion) is more efficient than repeated calls to ApplyRange, because only one instance of the filter is created.
asarian
15th November 2010, 23:46
Thanks all for the help!
I can't get a decent dehalo-ing going, though; see this image of two stills (http://www.mediafire.com/i/?85d6x83f491u4xw). The one at the bottom is supposed to be dehalo-ed, but it appears to not have done anything at all. :( I used the following test script:
FFVideoSource("F:\jobs\test.mkv")
Crop(202, 2, -202, -2)
BaseClip=Last
SourceClip=BaseClip.DeHalo_alpha(rx=2.7, ry=2.7, brightstr=1.3)
# SourceClip=BaseClip.YAHR()
ReplaceFramesSimple(BaseClip,SourceClip,Mappings="[0 107]")
[0 107] in this case are all frames (this was just a test, after all).
Maybe I'm not doing it right, but the result is a bit disappointing. The halo around Lain's chin is still as much present as before. Does anyone have any idea as to why dehalo-ing does not seem to occur? Maybe there's too much grain in the source? (Blu-Ray)
Didée
16th November 2010, 00:06
The one at the bottom is supposed to be dehalo-ed, but it appears to not have done anything at all.
Just guessing, but maybe the halos are too broad for dehalo_alpha - it uses a fixed radius for back-checking, and maybe the radius is too small.
Oh, btw ... it is exactly the other way round. The top one is the one with dehalo_alpha applied, and the bottom one is the original. ;)
Edit: Nah, wait ... there must've been a mistake on your side. Dehalo_alpha is very effective on that picture. I'm preparing data, will come in a few minutes.
Didée
16th November 2010, 00:58
Source: [the very image you posted]
Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)
Result:
http://img602.imageshack.us/img602/6454/dha1.th.png (http://img602.imageshack.us/i/dha1.png/)
All halos are gone. Primary goal achieved. Dehalo_alpha is effective.
But the result is not "nice", there's too much flattening and loss of line darkness etc.
Try #2: dehalo_alpha with contra-sharpening to restore the loss. Settings of dehalo_alpha a bit more tweaked.
o = last
DH = o.dehalo_alpha(rx=1.75,ry=2.8,darkstr=0.66)
bb = DH.removegrain(11)
xD = mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1))
\ .mt_lut("x 128 - 2.49 * 128 +")
xDD = mt_lutxy(xD,mt_makediff(o,DH),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
DH.mt_adddiff(xDD,U=2,V=2)
Sorry for the ugly code, I am tired.
Result:
http://img257.imageshack.us/img257/1921/dha2.th.png (http://img257.imageshack.us/i/dha2.png/)
All halos gone, with only very minor damage.
G'nite. :)
asarian
16th November 2010, 01:54
Source: [the very image you posted]
Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)
Result:
http://img602.imageshack.us/img602/6454/dha1.th.png (http://img602.imageshack.us/i/dha1.png/)
All halos are gone. Primary goal achieved. Dehalo_alpha is effective.
But the result is not "nice", there's too much flattening and loss of line darkness etc.
Try #2: dehalo_alpha with contra-sharpening to restore the loss. Settings of dehalo_alpha a bit more tweaked.
o = last
DH = o.dehalo_alpha(rx=1.75,ry=2.8,darkstr=0.66)
bb = DH.removegrain(11)
xD = mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1))
\ .mt_lut("x 128 - 2.49 * 128 +")
xDD = mt_lutxy(xD,mt_makediff(o,DH),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
DH.mt_adddiff(xDD,U=2,V=2)
Sorry for the ugly code, I am tired.
Result:
http://img257.imageshack.us/img257/1921/dha2.th.png (http://img257.imageshack.us/i/dha2.png/)
All halos gone, with only very minor damage.
G'nite. :)
You're a brilliant man, Didée! And I can't thank you enough. :) Obviously I'll go study your code in detail, so I can apply these things for future reference.
asarian
16th November 2010, 17:32
As far as memory use is concerned, they should all be more or less the same, and cannot really be bettered for the example cases given.
However, if you want to apply the filter to several different segments (with the same arguments each time), then ReplaceFramesSimple (manono's first suggestion) is more efficient than repeated calls to ApplyRange, because only one instance of the filter is created.
The only possible drawback to ReplaceFramesSimple I can see, is that "YourFilterHere" (in manono's example) is called for every frame, whereas you'll only be using its output for a few select ranges (if "YourFilterHere" happens to be complex, you could lose a lot of time). 'ApplyRange' appears to function more like a 'case' conditional, only processing "YourFilterHere" for those frames needed.
Gavino
16th November 2010, 18:44
The only possible drawback to ReplaceFramesSimple I can see, is that "YourFilterHere" (in manono's example) is called for every frame, whereas you'll only be using its output for a few select ranges
It's true that in the script, "YourFilterHere" is called with the entire clip as its argument. However, because Avisynth filters only process individual frames on demand, it will only process those frames which are requested from it by ReplaceFramesSimple. So there is no unnecessary work done (unless it's a rare filter that has to partially process all frames of its input clip in advance, eg to compute a maximum of some kind).
asarian
16th November 2010, 18:54
It's true that in the script, "YourFilterHere" is called with the entire clip as its argument. However, because Avisynth filters only process individual frames on demand, it will only process those frames which are requested from it by ReplaceFramesSimple. So there is no unnecessary work done (unless it's a rare filter that has to partially process all frames of its input clip in advance, eg to compute a maximum of some kind).
That's good to know. Thanks. :) Seems AviSynth is a bit more efficient than I gave it credit for. :P
ajp_anton
16th November 2010, 19:30
Source: [the very image you posted]
Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)
Result:
http://img602.imageshack.us/img602/6454/dha1.th.png (http://img602.imageshack.us/i/dha1.png/)
All halos are gone. Primary goal achieved. Dehalo_alpha is effective.
But the result is not "nice", there's too much flattening and loss of line darkness etc.
Try #2: dehalo_alpha with contra-sharpening to restore the loss. Settings of dehalo_alpha a bit more tweaked.
o = last
DH = o.dehalo_alpha(rx=1.75,ry=2.8,darkstr=0.66)
bb = DH.removegrain(11)
xD = mt_makediff(bb,bb.repair(bb.repair(bb.medianblur(2,-333,-333),1),1))
\ .mt_lut("x 128 - 2.49 * 128 +")
xDD = mt_lutxy(xD,mt_makediff(o,DH),"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?")
DH.mt_adddiff(xDD,U=2,V=2)
Sorry for the ugly code, I am tired.
Result:
http://img257.imageshack.us/img257/1921/dha2.th.png (http://img257.imageshack.us/i/dha2.png/)
All halos gone, with only very minor damage.
G'nite. :)
WTF just happened? How do you "just write" something like that like it's nothing, and then say you're tired =)
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.