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 13th November 2010, 05:29   #1  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
DeHalo-ing only certain segments

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, 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.
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 13th November 2010, 06:05   #2  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
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 is offline   Reply With Quote
Old 13th November 2010, 06:09   #3  |  Link
manono
Moderator
 
Join Date: Oct 2001
Location: Hawaii
Posts: 7,406
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
manono is offline   Reply With Quote
Old 13th November 2010, 06:54   #4  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by manono View Post
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!
__________________
Gorgeous, delicious, deculture!

Last edited by asarian; 13th November 2010 at 07:05.
asarian is offline   Reply With Quote
Old 13th November 2010, 09:42   #5  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by manono View Post
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(400, 500, "YourFilterHere")
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 15th November 2010, 18:14   #6  |  Link
Masaru
Registered User
 
Join Date: Aug 2010
Posts: 5
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.
Masaru is offline   Reply With Quote
Old 15th November 2010, 19:14   #7  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
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.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 15th November 2010, 23:46   #8  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Thanks all for the help!

I can't get a decent dehalo-ing going, though; see this image of two stills. 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)
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 16th November 2010, 00:06   #9  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Quote:
Originally Posted by asarian View Post
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.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)

Last edited by Didée; 16th November 2010 at 00:42.
Didée is offline   Reply With Quote
Old 16th November 2010, 00:58   #10  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,391
Source: [the very image you posted]


Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)

Result:


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.

Code:
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:


All halos gone, with only very minor damage.

G'nite.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 16th November 2010, 01:54   #11  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by Didée View Post
Source: [the very image you posted]


Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)

Result:


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.

Code:
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:


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.
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 16th November 2010, 17:32   #12  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by Gavino View Post
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.
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 16th November 2010, 18:44   #13  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by asarian View Post
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).
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 16th November 2010, 18:54   #14  |  Link
asarian
Registered User
 
Join Date: May 2005
Posts: 1,462
Quote:
Originally Posted by Gavino View Post
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
__________________
Gorgeous, delicious, deculture!
asarian is offline   Reply With Quote
Old 16th November 2010, 19:30   #15  |  Link
ajp_anton
Registered User
 
ajp_anton's Avatar
 
Join Date: Aug 2006
Location: Stockholm/Helsinki
Posts: 805
Quote:
Originally Posted by Didée View Post
Source: [the very image you posted]


Try #1: Plain dehalo_alpha, just with adjusted radii: dh_alpha(rx=1.75,ry=2.5)

Result:


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.

Code:
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:


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 =)
ajp_anton is offline   Reply With Quote
Reply

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 12:03.


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