版面规则
提问时请注意:尽量详细描述操作过程、AVS脚本内容等,最好能写出片名,只贴图有时无法看出问题原因。
提示:发布原创内容请尽量使用附件上传。使用网盘会出现过期失效的问题,请注意。
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

GrainStabilize v0.3 - 高速的时域降噪脚本

随手写了个高速的时域降噪脚本。

思路是很久以前就说过的,将源和RemoveGrain之后画面做比较,将二者差别作为grain,只对这个grain做stabilization。需要的话可以用p自定义on-top grain remover代替RemoveGrain。

有做luma adaptive,默认luma高的地方stabilization强度大,luma低的地方强度降低,防止暗场杯具。(不过其实通常来说最容易出banding的并非是luma完全等于0/16的地方,而是大约按OreAQ标准dark/M.dark交界线上下,所以预设用的是adapt=64)

速度应该非常快,正常来说对1080可以实时吧……如果不需要luma adaptive的话,可以用adapt=-1,速度会更快,或者即使只是用稍微不准确些的adapt=0应该也能快一些……

其实我很想称之为On-top Grain Calmer,简称OGC的……

用法:

代码: 全选

GrainStabilize(clip input, int "temp", int "radius", int "adapt", int "rep", bool "luma", bool "chroma", clip "p")
参数名应该都是各种常用脚本里非常通用的,具体看代码里说明……

下載:GrainStabilize_v0.3.avsi

[syntax lang="avisynth" lines="f" filename="GrainStabilize_v0.3.avsi"]###################################################
### ###
### GrainStabilize.avsi ###
### ###
### By 06_taro ( astrataro@gmail.com ) ###
### ###
### v0.3 - 20 Feb 2012 ###
### ###
###################################################
###
###
### Temporal-only on-top grain stabilizer
### Only stabilize the difference ( on-top grain ) between source clip and spatial-degrained clip
###
### Support YV12 input only
###
###
### +-------------+
### | CHANGELOG |
### +-------------+
###
### v0.3 - 21 February 2012:
### - Use repair to remove temporal artifacts
###
### v0.2 - 20 February 2012:
### - Add "radius"
###
### v0.1 - 19 February 2012:
### - First script
###
###
### +----------------+
### | REQUIREMENTS |
### +----------------+
###
### -> RemoveGrain (v1.0)
### -> Masktools2 (v2a48)
###
###
### +-------+
### | USAGE |
### +-------+
###
### GrainStabilize(int temp, int radius, int adapt, bool luma, bool chroma, clip p)
###
###
### +-----------+
### | GENERAL |
### +-----------+
###
### temp [int, default: 50]
### ------------------
### Strength for temporal stabilization of on-top grain
### 0 = nervous
### ..
### 100 = calm
###
### radius [int, default: 1]
### ------------------
### Radius for temporal stabilization of on-top grain
###
### adapt [int, default: 64]
### -------------------
### Threshold for luma-adaptative grain
### -1 = off
### 0 = source
### ..
### 255 = invert
###
### rep [int, default: 3]
### ------------------
### Mode of repair, used to remove artifacts introduced by temporal soften
###
### luma, chroma [bool, default: true]
### ----------------------
### Whether to process luma/chroma plane or not
###
### p [clip, default = not set]
### ----------------------
### Define your own on-top grain removed clip instead of using internal RemoveGrain
### e.g., GrainStabilize( p=PNLM2(strength=32, wSpan=2, tSpan=0) )
###
###

Function GrainStabilize(clip input, int "temp", int "radius", int "adapt", int "rep", bool "luma", bool "chroma", clip "p"){

temp = Default(temp, 50)
radius = Default(radius, 1)
adapt = Default(adapt, 64)
rep = Default(rep, 3)
luma = Default(luma, true)
chroma = Default(chroma, true)

Assert( input.IsYV12, "GrainStabilize: only support YV12 colorspace!" )
Assert( temp>=0 && temp<=100, "GrainStabilize: invalid value for temp(0~100)!" )
Assert( adapt>=-1 && adapt<=255, "GrainStabilize: invalid value for adapt(-1~255)!" )

Y = luma ? 3 : 2
U = chroma ? 3 : 2
V = chroma ? 3 : 2

pre_nr = Defined(p) ? p : input.RemoveGrain(luma?20:0, chroma?20:0)

diff_nr = mt_makediff(input, pre_nr, Y=Y, U=U, V=V)

diff_sb = (luma&&chroma) ? diff_nr.TemporalSoften(radius, 255, 255, scenechange=255, mode=2)
\ : luma ? diff_nr.TemporalSoften(radius, 255, 0, scenechange=255, mode=2)
\ : chroma ? diff_nr.TemporalSoften(radius, 0, 255, scenechange=255, mode=2)
\ : diff_nr

diff_mg = (temp == 0) ? diff_nr
\ : (temp == 100) ? diff_sb
\ : (luma&&chroma) ? Merge(diff_nr, diff_sb, temp/100.)
\ : luma ? MergeLuma(diff_nr, diff_sb, temp/100.)
\ : chroma ? MergeChroma(diff_nr, diff_sb, temp/100.)
\ : diff_nr

stabled = rep==0 ? mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V)
\ : mt_adddiff(pre_nr, diff_mg, Y=Y, U=U, V=V).Repair(input, mode=rep)

Lmask = adapt==0 ? input.RemoveGrain(19, -1)
\ : adapt==255 ? input.mt_invert(U=1, V=1).RemoveGrain(19, -1)
\ : input.mt_lut("x "+string(adapt)+" - abs 255 * "+string(adapt)+" 128 - abs 128 + /", U=1, V=1).RemoveGrain(19, -1)

return adapt==-1 ? stabled
\ : mt_merge(input, stabled, Lmask, luma=chroma, Y=Y, U=U, V=V)

}[/syntax]
上次由 06_taro 在 2012-03-12 0:28,总共编辑 4 次。
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
4h4h270
帖子: 163
注册时间: 2011-04-10 17:59

Re: 高压求助

拜谢taro大,你这个脚本是不是和DS的Grainopt的原理类似~
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: 高压求助

取diff做stable這點思路上是類似的,不過其實我這裡測試時,即使保持默認參數開啟luma adaptive,這個腳本的速度還是比GrainOpt還快,而GrainOpt還不是luma adaptive的……另外對diff做stable的過程是不同的。GrainOpt即使不說那堆奇怪的bug,本身結果也比較詭異……

其實我一直想要的最理想的grain tool是一個spatial/temporal re-orderer,保持spatial/temporal的複雜度都基本上不變,從而psycho-visual上和原始clip幾乎看不出區別(GrainOpt想做到這點,實際上根本做不到),只是對噪點在spatial/temporal做re-order。因此不一定是降噪,視情況有可能噪點量保持不變只是pattern變化,甚至有可能是加噪。re-order之後雖然看起來相同,但是pattern要更加易於DCT/wavelet編碼器進行預測。如果能做到這樣的話就真的是在保持視覺近乎相同的情況下省碼率了(當然PSNR/SSIM肯定會悲劇掉……)。而且如果這種方法確實可行的話,不但可以作為一個video filter,還可以作為編碼器的一種psy優化。實際上psy-rd在保持複雜度方面和這個有點類似,只是它不是靠re-order,而是直接rd過程有選擇性地捨棄部分細節。而且因為和編碼器需要做的一些計算有重複之處,效率也會更高。
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
Holy
核心会员
核心会员
帖子: 235
注册时间: 2010-09-24 9:28

Re: 高压求助

貌似109行的input、stabled兩個位置放反了…
图片
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

GrainStabilize v0.2

沒反吧……luma mask值越高說明亮度越高,越可以安全地stabilize,也就越使用stabled;值越低的越使用input……

順便v0.2,增加"radius"參數設定temporal stabilization的radius。如果是以降低編碼需要的碼率為目的而盡量不想改變視覺感官的話,用1或者2就差不多了,不建議用過高的數值(理論上這樣,實際上重噪點片子我拿3~4去跑的時候動態播放結果目測也沒啥bias,更高的沒試過……)。

正好CPU閒下來了,跑個速度測試,i7-2670qm,avs2avi空跑,1920x1080,高躁SBMV,
temp=50, radius=1, adapt=64, luma=true, chroma=true, 大約30fps,CPU佔用約40%
temp=50, radius=2, adapt=64, luma=true, chroma=true, 大約28fps,CPU佔用約40%
也就是說24p的實時跑完全沒問題……
上次由 06_taro 在 2012-03-12 0:26,总共编辑 10 次。
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
-o-o-304-o-o-
超级版主
帖子: 640
注册时间: 2010-10-10 20:00
来自: US
联系: 网站

Re: 高压求助

PNLM的那个处理器检测似乎有问题,AMD推土机以前和intelC2D以前的老U都存在opt=0的bug问题,手动opt=1(强制SSE2)就行了

(LZ反应的问题我倒觉得像是内存不足的问题,且不说P4本身的能力问题……2G内存还要考虑x264的消耗,用MC且avs上不限制内存的话爆掉很正常吧…………解决方法倒是有如下选择:1.换不怎么吃内存的avs滤镜,2.先跑无损再压片)

高压的话denoise有必要,但是上到MC这个看具体的情况吧……,MCTD的话,对于实写中的噪点,处理效果确实不错,不过老实话说,速度真不敢恭维(目前各pass搭配最多的也就是fft3dgpu和PNLM了……用fft3dgpu的话速度上略好但是对于显卡的要求高,TTSM的效果不错但是对于处理器的要求又高……LZ目前贴出来的机器我觉得跑这2个可能都受罪……)。从速度的角度考虑的话,反正都是高压了,单独一个高强度PNLM在有mask的保护下线条勉强还能看,低码率下块也会少些……当然了,如果需要更好地效果的话,可能只有换机器,或者给足码率这样才会比较好吧……
► 显示剧情透露 En Taro 06!Taro Pie NC Fanclub project始动!聊天用Q群开放中
► 显示剧情透露 胸中有万言,退敌无一策,是谓书生误国"
► 显示剧情透露 前辈们的信念
► 显示剧情透露 妇联招新广告,走过路过可以看看撒
► 显示剧情透露 香芋派,后期菊苣们的一致选择
► 显示剧情透露 众菊苣喜评香芋派
► 显示剧情透露 聊天用工具
头像
Holy
核心会员
核心会员
帖子: 235
注册时间: 2010-09-24 9:28

Re: 高压求助

嗯…是我理解錯作用了@@"
图片
头像
4h4h270
帖子: 163
注册时间: 2011-04-10 17:59

Re: 高压求助

我自己用dfttest试了带MC轰动画没有啥优势...
PNLM感觉默认强度线条就比较糊了 {:cat_6}

taro大这个脚本真心好用,一直希望能有这种东西.
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

GrainStabilize - v0.3

GrainStabilize v0.3
使用repair來去除temporal soften導致的一些artifacts,速度基本沒有影響。
現在temp/radius即使略高一些也比較安全了……
上次由 06_taro 在 2012-03-12 0:25,总共编辑 3 次。
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。
头像
06_taro
核心会员
核心会员
帖子: 998
注册时间: 2010-09-22 18:32
来自: United Kingdom
联系: 网站

Re: 高压求助

分吧……本來只是隨手寫著玩玩的,沒想到稍微調整了下之後真的可以實用……

PS: 還有文檔庫裡MCTDmod的分類錯了……不是去鋸齒而是降噪……
つまんねー事聞くなよ!

I, personally, for me, believe (obviously sometimes) that my OS choice is right. That's me. I'm not telling you that you should believe it. Learn the facts, and the origins behind the facts, and make up your own damn mind. That's why you have one. (source)

Follow me: @06_taro

304——
为纪念伟大的宇宙史上最强压制304先生,联合国教科文组织决定,将每年的第304天,即平年的10月31日或者闰年的10月30日,定为世界304日。

回到 “AviSynth”