找回密码
 立即注册
查看: 1076|回复: 5

求助最新版的havsfunc使用

2

主题

21

回帖

0

VC币

中级会员

Rank: 3Rank: 3

积分
3787
lwjkk666 发表于 2025-1-5 12:48:19 | 显示全部楼层 |阅读模式
更新了,貌似很多参数用不了

例如报错
import havsfunc as haf
File "J:\vapoursynth_portable_24H1p_cpu+cuda.7z\vapoursynth\VapourSynthScripts\havsfunc.py", line 8, in
from vsdenoise import BM3D, nl_means, prefilter_to_full_range
ModuleNotFoundError: No module named 'vsdenoise'


然后查看了py文件里面的说明
def HQDeringmod(*args, **kwargs):
    raise vs.Error(
        "havsfunc.HQDeringmod outdated. Use 链接 instead."


譬如我想使用去ring的滤镜,说这个HQDeringmod已经移除了,使用vs-dehalo替代,问题来了,
跑去啃文档,发觉也不会用啊,求支招,该怎样调用,是import 里面的XXX.py文件,然后vs脚本那直接调用函数吗,不过试过也报错

回复

使用道具 举报

20

主题

164

回帖

20

VC币

至尊会员

Rank: 16Rank: 16Rank: 16Rank: 16

积分
244783
op200 发表于 2025-1-5 16:20:29 | 显示全部楼层
Jaded Encoding Thaumaturgy 那个里面的 vs 脚本几乎都没有文档,只能读源码

比如 vs-dehalo 的 readme 里写了 dehaloed = fine_dehalo(src)

用 vscode 打开源码搜 fine_dehalo 读就完事了(

例如 __init__.py 里 import 了 *,alpha.py 里

__all__ = [
    'fine_dehalo',
    'fine_dehalo2',
    'dehalo_alpha',
    'dehalo_sigma',
    'dehalomicron',
    'dehalo_merge'
]
fine_dehalo = _fine_dehalo()

所以 readme 里的 fine_dehalo 就是一个对象,看 class 定义里的 __call__ 就是用来初始化的(它返回了一个VideoNode对象)

__call__ 下面那一大坨注释就是用法了

虽然这坨注释也就写这个代码的人能看懂(
回复

使用道具 举报

0

主题

53

回帖

0

VC币

中级会员

Rank: 3Rank: 3

积分
5852
nyaru 发表于 2025-1-5 16:38:46 | 显示全部楼层
本帖最后由 nyaru 于 2025-1-5 16:44 编辑

你可以使用旧版
  1. def HQDeringmod2(input, p=None, ringmask=None, mrad=1, msmooth=1, incedge=False, mthr=60, minp=1, nrmode=None, sharp=1, drrep=24, thr=12.0, elast=2.0, darkthr=None, planes=[0], show=False):
  2.     if not isinstance(input, vs.VideoNode):
  3.         raise vs.Error('HQDeringmod: this is not a clip')

  4.     if input.format.color_family == vs.RGB:
  5.         raise vs.Error('HQDeringmod: RGB format is not supported')

  6.     if p is not None and (not isinstance(p, vs.VideoNode) or p.format.id != input.format.id):
  7.         raise vs.Error("HQDeringmod: 'p' must have the same format as input")

  8.     if ringmask is not None and not isinstance(ringmask, vs.VideoNode):
  9.         raise vs.Error("HQDeringmod: 'ringmask' is not a clip")
  10.    
  11.     import math
  12.     def cround(x):
  13.         return math.floor(x + 0.5) if x > 0 else math.ceil(x - 0.5)
  14.     def drscale(value, peak):
  15.         return cround(value * peak / 255) if peak != 1 else value / 255

  16.     isGray = (input.format.color_family == vs.GRAY)

  17.     neutral = 1 << (input.format.bits_per_sample - 1)
  18.     peak = (1 << input.format.bits_per_sample) - 1

  19.     if isinstance(planes, int):
  20.         planes = [planes]

  21.     if nrmode is None:
  22.         nrmode = 2 if input.width > 1024 or input.height > 576 else 1
  23.     if darkthr is None:
  24.         darkthr = thr / 4

  25.     # Kernel: Smoothing
  26.     if p is None:
  27.         p = MinBlur(input, r=nrmode, planes=planes)

  28.     # Post-Process: Contra-Sharpening
  29.     matrix1 = [1, 2, 1, 2, 4, 2, 1, 2, 1]
  30.     matrix2 = [1, 1, 1, 1, 1, 1, 1, 1, 1]

  31.     if sharp <= 0:
  32.         sclp = p
  33.     else:
  34.         pre = p.std.Median(planes=planes)
  35.         if sharp == 1:
  36.             method = pre.std.Convolution(matrix=matrix1, planes=planes)
  37.         elif sharp == 2:
  38.             method = pre.std.Convolution(matrix=matrix1, planes=planes).std.Convolution(matrix=matrix2, planes=planes)
  39.         else:
  40.             method = pre.std.Convolution(matrix=matrix1, planes=planes).std.Convolution(matrix=matrix2, planes=planes).std.Convolution(matrix=matrix2, planes=planes)
  41.         sharpdiff = core.std.MakeDiff(pre, method, planes=planes)
  42.         allD = core.std.MakeDiff(input, p, planes=planes)
  43.         ssDD = core.rgvs.Repair(sharpdiff, allD, mode=[1 if i in planes else 0 for i in range(input.format.num_planes)])
  44.         expr = f'x {neutral} - abs y {neutral} - abs <= x y ?'
  45.         ssDD = core.std.Expr([ssDD, sharpdiff], expr=[expr if i in planes else '' for i in range(input.format.num_planes)])
  46.         sclp = core.std.MergeDiff(p, ssDD, planes=planes)

  47.     # Post-Process: Repairing
  48.     if drrep <= 0:
  49.         repclp = sclp
  50.     else:
  51.         repclp = core.rgvs.Repair(input, sclp, mode=[drrep if i in planes else 0 for i in range(input.format.num_planes)])

  52.     # Post-Process: Limiting
  53.     if (thr <= 0 and darkthr <= 0) or (thr >= 128 and darkthr >= 128):
  54.         limitclp = repclp
  55.     else:
  56.         limitclp = mvf.LimitFilter(repclp, input, thr=thr, elast=elast, brighten_thr=darkthr, planes=planes)

  57.     # Post-Process: Ringing Mask Generating
  58.     if ringmask is None:
  59.         expr = f'x {drscale(mthr, peak)} < 0 x ?'
  60.         prewittm = AvsPrewitt(input, planes=[0]).std.Expr(expr=[expr] if isGray else [expr, ''])
  61.         fmask = core.misc.Hysteresis(prewittm.std.Median(planes=[0]), prewittm, planes=[0])
  62.         if mrad > 0:
  63.             omask = mt_expand_multi(fmask, planes=[0], sw=mrad, sh=mrad)
  64.         else:
  65.             omask = fmask
  66.         if msmooth > 0:
  67.             omask = mt_inflate_multi(omask, planes=[0], radius=msmooth)
  68.         if incedge:
  69.             ringmask = omask
  70.         else:
  71.             if minp > 3:
  72.                 imask = fmask.std.Minimum(planes=[0]).std.Minimum(planes=[0])
  73.             elif minp > 2:
  74.                 imask = fmask.std.Inflate(planes=[0]).std.Minimum(planes=[0]).std.Minimum(planes=[0])
  75.             elif minp > 1:
  76.                 imask = fmask.std.Minimum(planes=[0])
  77.             elif minp > 0:
  78.                 imask = fmask.std.Inflate(planes=[0]).std.Minimum(planes=[0])
  79.             else:
  80.                 imask = fmask
  81.             expr = f'x {peak} y - * {peak} /'
  82.             ringmask = core.std.Expr([omask, imask], expr=[expr] if isGray else [expr, ''])

  83.     # Mask Merging & Output
  84.     if show:
  85.         if isGray:
  86.             return ringmask
  87.         else:
  88.             return ringmask.std.Expr(expr=['', repr(neutral)])
  89.     else:
  90.         return core.std.MaskedMerge(input, limitclp, ringmask, planes=planes, first_plane=True)

  91. def MinBlur(clp, r=1, planes=None):
  92.     if not isinstance(clp, vs.VideoNode):
  93.         raise vs.Error('MinBlur: this is not a clip')

  94.     if planes is None:
  95.         planes = list(range(clp.format.num_planes))
  96.     elif isinstance(planes, int):
  97.         planes = [planes]

  98.     matrix1 = [1, 2, 1, 2, 4, 2, 1, 2, 1]
  99.     matrix2 = [1, 1, 1, 1, 1, 1, 1, 1, 1]

  100.     if r <= 0:
  101.         RG11 = sbr(clp, planes=planes)
  102.         RG4 = clp.std.Median(planes=planes)
  103.     elif r == 1:
  104.         RG11 = clp.std.Convolution(matrix=matrix1, planes=planes)
  105.         RG4 = clp.std.Median(planes=planes)
  106.     elif r == 2:
  107.         RG11 = clp.std.Convolution(matrix=matrix1, planes=planes).std.Convolution(matrix=matrix2, planes=planes)
  108.         RG4 = clp.ctmf.CTMF(radius=2, planes=planes)
  109.     else:
  110.         RG11 = clp.std.Convolution(matrix=matrix1, planes=planes).std.Convolution(matrix=matrix2, planes=planes).std.Convolution(matrix=matrix2, planes=planes)
  111.         if clp.format.bits_per_sample == 16:
  112.             s16 = clp
  113.             RG4 = clp.fmtc.bitdepth(bits=12, planes=planes, dmode=1).ctmf.CTMF(radius=3, planes=planes).fmtc.bitdepth(bits=16, planes=planes)
  114.             RG4 = mvf.LimitFilter(s16, RG4, thr=0.0625, elast=2, planes=planes)
  115.         else:
  116.             RG4 = clp.ctmf.CTMF(radius=3, planes=planes)

  117.     expr = 'x y - x z - * 0 < x x y - abs x z - abs < y z ? ?'
  118.     return core.std.Expr([clp, RG11, RG4], expr=[expr if i in planes else '' for i in range(clp.format.num_planes)])

  119. def AvsPrewitt(clip, planes=None):
  120.     if not isinstance(clip, vs.VideoNode):
  121.         raise vs.Error('AvsPrewitt: this is not a clip')

  122.     if planes is None:
  123.         planes = list(range(clip.format.num_planes))
  124.     elif isinstance(planes, int):
  125.         planes = [planes]

  126.     return core.std.Expr([clip.std.Convolution(matrix=[1, 1, 0, 1, 0, -1, 0, -1, -1], planes=planes, saturate=False),
  127.                           clip.std.Convolution(matrix=[1, 1, 1, 0, 0, 0, -1, -1, -1], planes=planes, saturate=False),
  128.                           clip.std.Convolution(matrix=[1, 0, -1, 1, 0, -1, 1, 0, -1], planes=planes, saturate=False),
  129.                           clip.std.Convolution(matrix=[0, -1, -1, 1, 0, -1, 1, 1, 0], planes=planes, saturate=False)],
  130.                           expr=['x y max z max a max' if i in planes else '' for i in range(clip.format.num_planes)])

  131. def mt_inflate_multi(src, planes=None, radius=1):
  132.     if not isinstance(src, vs.VideoNode):
  133.         raise vs.Error('mt_inflate_multi: this is not a clip')

  134.     for i in range(radius):
  135.         src = core.std.Inflate(src, planes=planes)
  136.     return src
复制代码
回复

使用道具 举报

2

主题

21

回帖

0

VC币

中级会员

Rank: 3Rank: 3

积分
3787
lwjkk666  楼主| 发表于 2025-1-5 19:34:22 | 显示全部楼层
nyaru 发表于 2025-1-5 16:38
你可以使用旧版

好的,只能自己封一个调用了

新的那个我是真的看不明白,主要老报错,但是又不知道错在哪,感觉对于新人不是很友好
回复

使用道具 举报

2

主题

21

回帖

0

VC币

中级会员

Rank: 3Rank: 3

积分
3787
lwjkk666  楼主| 发表于 2025-1-5 19:34:51 | 显示全部楼层
op200 发表于 2025-1-5 16:20
Jaded Encoding Thaumaturgy 那个里面的 vs 脚本几乎都没有文档,只能读源码

比如 vs-dehalo 的 readme 里 ...

谢谢回复,我试试
回复

使用道具 举报

7

主题

107

回帖

48

VC币

高级会员

Rank: 4

积分
25000
Ryougi_Kukoc 发表于 2025-1-5 21:44:50 | 显示全部楼层
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表