Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #----------------------------------------------------------------------------------------------------------
- #
- # AutoBlockNR.avsi
- #
- # 概要:
- # フィールド単位の色差成分の情報を利用して、MPEG2のブロックノイズを低減する
- #
- # 説明:
- # MPEG2のブロックノイズはフィールド単位のノイズで、かつ色差成分に顕著に反映されるノイズのようです。
- # この特性を利用して、色差成分のノイズが少ないフィールドをBOB化することにより良好なソースを得られる可能性があります。
- #
- # 使い方:
- # Usageを参照してください。
- #
- # 動作に必要なDLL:
- # TDeint.dll
- # nnedi3.dll
- # TMM.dll
- # Masktools
- # Masktools v2
- #----------------------------------------------------------------------------------------------------------
- #----------------------------------------
- # 関数サマリ
- #----------------------------------------
- #Function AutoBlockNR() : クリップを受け取り、ブロックノイズを低減して返す
- #Function AutoBlockNR_InterpolateByField() : 指定されたフレームを、片フィールド補間して返す
- #Function AutoBlockNR_Bob() : 片フィールド補間に使うBob化関数。本番用
- #Function AutoBlockNR_BobForTest() : 片フィールド補間に使うBob化関数。テスト用
- #Function Combcheck(clip c,bool "test",int "thY") : ノイズの強調表示関数。「にわとり遊び」のささみし様の関数を流用させて頂きました。
- #----------------------------------------
- # AutoBlockNR
- #----------------------------------------
- # 処理:クリップを受け取り、ブロックノイズを低減して返す
- # 引数:
- # ・th_noise_diff フィールド間にどれだけノイズ差があったら補間を行うか。値が小さいほど補間フレームは多くなりますが、誤爆も多くなります。デフォルトは12.0
- # ・tff トップフィールドファーストならtrue・・・のつもり。BOB化して汚くなるようならfalseに設定してみてください。デフォルトはtrue
- # ・test テストモードならtrue。テストモードでは各種情報が表示されるほか、BOB化に軽量関数を使うのでプレビューが早くなります。デフォルトはfalse
- # 返し値:ブロックノイズを低減したクリップ
- Function AutoBlockNR(clip c,float "th_noise_diff",bool "tff",bool "test")
- {
- # 各種グローバル関数。ScriptClipに渡すため
- global g_autoblocknr_th_noise_diff=Default(th_noise_diff,12.0)
- global g_autoblocknr_tff=Default(tff,true)
- global g_autoblocknr_test=Default(test,false)
- # メイン処理
- c.ScriptClip("""
- src=last
- # 色差ノイズを強調表示し、CombCheck()でノイズの量を測定する
- SeparateFields()
- Tweak(sat=5.0)
- UToY()
- CombCheck(test=false)
- noise_t=Trim(current_frame*2,-1).AverageLuma()
- noise_b=Trim(current_frame*2+1,-1).AverageLuma()
- noise_diff=Abs(noise_t-noise_b)
- # フィールド間のノイズの差がしきい値を越えていたら片フィールド補間。越えていなければ素通し
- src
- (noise_diff<g_autoblocknr_th_noise_diff)
- \? last
- \: (noise_t > noise_b)
- \? AutoBlockNR_InterpolateByField(current_frame,true,g_autoblocknr_tff,g_autoblocknr_test)
- \: AutoBlockNR_InterpolateByField(current_frame,false,g_autoblocknr_tff,g_autoblocknr_test)
- # テストモード用の各種情報の用意
- offset_x=10
- offset_y=10
- op=(noise_diff<g_autoblocknr_th_noise_diff)
- \? "none"
- \: (noise_t > noise_b)
- \? "bottom field"
- \: "top field"
- # テストモードでの各種情報の表示。色々表示したいが、載せるほど動作が重く・・・
- (g_autoblocknr_test==true)
- \?
- \ SubTitle("noise_diff "+String(noise_diff,"%.2f"),offset_x,offset_y,font="lucida console")
- \.SubTitle("bob "+op,offset_x,offset_y+20,font="lucida console")
- \: last
- return last
- """)
- return last
- }
- #----------------------------------------
- # AutoBlockNR_InterpolateByField
- #----------------------------------------
- # 処理:指定されたフレームを、片フィールド補間して返す
- # 引数:
- # ・frame 処理したいフレーム番号
- # ・top トップフィールドが汚れているならtrue
- # ・tff トップフィールドファーストならtrue
- # ・test テストモードならtrue
- # 返し値: BOB化クリップ
- Function AutoBlockNR_InterpolateByField(clip c,int frame,bool top,bool tff,bool test)
- {
- # トップフィールドとボトムフィールド、どちらをBob化するか判断。引数で指定されるのは汚れたフィールドであることに注意
- offset=(tff==true)
- \? (top==true) ? 1 : 0
- \: (top==true) ? 0 : 1
- # フィールドのBOB化
- c
- bobed=(test==true)?AutoBlockNR_BobForTest():AutoBlockNR_Bob()
- field=frame*2+offset
- fixed=bobed.Trim(field,-1)
- fixed=fixed.AssumeFPS(c.FrameRate)
- return fixed
- }
- #----------------------------------------
- # AutoBlockNR_BobForTest
- #----------------------------------------
- # 処理:テストモード用のBOB化関数
- # 引数:
- # 返し値: BOB化フレーム
- Function AutoBlockNR_BobForTest(clip c)
- {
- return c.Bob()
- }
- #----------------------------------------
- # AutoBlockNR_BobForTest
- #----------------------------------------
- # 処理:本番用のBOB化関数
- # 引数:
- # 返し値: BOB化フレーム
- Function AutoBlockNR_Bob(clip c)
- {
- c
- interp=nnedi3(field=-2)
- mask=tmm(mode=1)
- TDeint(mode=1, edeint=interp, emask=mask)
- return last
- }
- #----------------------------------------
- # CombCheck
- #----------------------------------------
- # 処理:ノイズの強調表示関数。「にわとり遊び」のささみし様の関数を流用させて頂きました。
- Function Combcheck(clip c,bool "test",int "thY")
- {
- test=Default(test,false)
- thY=Default(thY,16)
- c
- c1=(test==true)?Grayscale():c.BlankClip(color=$000000)
- c2=(test==true)?Grayscale().ColorYUV(gain_u=100,gain_v=100):c.BlankClip(color=$FFFFFF)
- mask1=CombMask(thY1=thY,thY2=thY)
- mt_merge(c1,c2,mask1,luma=true)
- return last
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement