Log in

View Full Version : Problems with Histogram/Tweak and Other Teething Problems


Richard1485
15th December 2017, 22:57
I'm having trouble with Histogram. At first, I tried to load the plugin, but that generated an error message telling me that the plugin was already loaded, at which point I realized that it is now built in. :p So I removed the call to LoadPlugin(), but I now receive an error message saying that there is no function called hist.

I took the code from the usage section (https://github.com/dubhater/vapoursynth-histogram) of Histogram.

core.std.hist.Color2(video)

Apologies for the newb question! I installed VapourSynth only yesterday and am trying to teach myself VapourSynth and basic Python at the same time. (I'm much more used to AviSynth's way of doing things.)

Are_
15th December 2017, 23:34
It's core.hist.Color2(video)

Selur
15th December 2017, 23:36
Try core.hist.Color(...) without the 'std',... (Are_ was faster ;))

Richard1485
16th December 2017, 00:19
Thank you both! That works. I'm still uncertain about when to use std or core and when not to. Moreover, the documentation says that it's possible to chain filters with a dot (like AviSynth), but I'm receiving error messages when I do so.

Selur
16th December 2017, 08:42
Sorry, never tried that. I usually don't chain filters in Avisynth either. :)

Are_
16th December 2017, 13:17
Every plugin should start with the core, but once it is there you can't call it again in the same call.

Then the namespace of the plugin follows it, it is like the container of all functions the plugin has. That's what you usually see like std, resize, hist...

And after that, you call the function you want from that plugin, Color2 for example.

clip = core.resize.Bicubic(clip, 640, 480)
clip = core.hist.Color2(clip)

becomes

clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.

Ofc to create the core there are many methods, you can use
from vapoursynth import core
which is ugly and prone to produce shit code or the good old
import vapoursynth as vs
core = vs.get_core()
That being said the ugly way is quite good for short scripts.

Richard1485
16th December 2017, 14:20
Sorry, never tried that. I usually don't chain filters in Avisynth either. :)

Oh, I see. Is there a technical reason for that or is it just preference? :)

Every plugin should start with the core, but once it is there you can't call it again in the same call.

Then the namespace of the plugin follows it, it is like the container of all functions the plugin has. That's what you usually see like std, resize, hist...

And after that, you call the function you want from that plugin, Color2 for example.

clip = core.resize.Bicubic(clip, 640, 480)
clip = core.hist.Color2(clip)

becomes

clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.

Thanks for the explanation! Yeah, the latter example that you posted looks like what I'm used to doing in AviSynth.


Ofc to create the core there are many methods, you can use
from vapoursynth import core
which is ugly and prone to produce shit code or the good old
import vapoursynth as vs
core = vs.get_core()
That being said the ugly way is quite good for short scripts.


I'm really glad that you posted this. I've been seeing the two ways of doing it all over place and wondered which was right or whether they were linked to different versions of Python or whatever. I started by following the documentation, which uses the new way, but after what you've said, I think that I might use the old way. In fact, my current script has a mix of the two because some functions refer to vs, which in the new way remains undefined. :o

hBIkOa7m
16th December 2017, 15:08
clip = core.resize.Bicubic(clip, 640, 480).hist.Color2(clip)
The downside about this is it can get ugly pretty fast and if you get errors it makes them harder to track down.


It seems to be quite common that people writing filter code make absolutely no effort to format their code in a way that makes it maintainable or readable. Even if you're only running the script as a one-off job, I've never understood why people make it harder for themselves.

You can chain methods AND use new lines - if you make each line only do one job errors are much easier to track down. By wrapping the block in parenthesis you can newline as much as you like. This is the preferred way in Python (https://www.python.org/dev/peps/pep-0008/#indentation). Some MWE:


import vapoursynth as vs
core = vs.get_core()

clip = (core.std.BlankClip()
.resize.Bicubic(1280, 720)
.text.ClipInfo()
.std.Turn180()
)

clip.set_output()


You can also just escape the newlines with a backslash. I think this is more ugly than parenthesis.


import vapoursynth as vs
core = vs.get_core()

clip = core.std.BlankClip() \
.resize.Bicubic(1280, 720) \
.text.ClipInfo() \
.std.Turn180()

clip.set_output()


You should line up your indentation on the dots.

Richard1485
16th December 2017, 15:43
^ The second option looks like the way I do things in AviSynth, although I tab the backspaces to make them line up and look a little neater. I'll try the first in VapourSynth. It does look more elegant. :)

EDIT: I now have a problem with Tweak().


import adjust

video2 = core.adjust.Tweak(video,hue=XX)

The result is an error.


ModuleNotFoundError: No module named "adjust"


The documentation says (https://github.com/dubhater/vapoursynth-adjust):

Drop adjust.py someplace where Python can find it, then use import adjust in your scripts.

I don't know where Python can find adjust.py. I tried putting it in the same directory as the script, but obviously that's the wrong thing to do.

The documentation has a Plugin Autoloading (http://www.vapoursynth.com/doc/autoloading.html#windows) section, but it doesn't seem to refer to .py files, and I'd prefer to load things manually anyway, at least for the time being.

poisondeathray
16th December 2017, 17:04
I don't know where Python can find adjust.py. I tried putting it in the same directory as the script, but obviously that's the wrong thing to do.



I place .py in the python => lib => site-packages directory . Then you can import it with "import adjust"

Another useful .py is HAvsFunc.py by HolyWu - it has many familiar avisynth functions
https://forum.doom9.org/showthread.php?t=166582

(PS. when I come across "std", I take penicillin :D)

Richard1485
16th December 2017, 17:44
Thanks! Unfortunately, that generates a syntax error that points to line 7 of adjust.py itself, possibly because it was written with an older version of Python in mind. I'm using 3.64 with the latest 64-bit version of VapourSynth.

(PS. when I come across "std", I take penicillin :D)

That's probably wise. :)

poisondeathray
16th December 2017, 17:52
Thanks! Unfortunately, that generates a syntax error that points to line 7 of adjust.py itself, possibly because it was written with an older version of Python in mind. I'm using 3.64 with the latest 64-bit version of VapourSynth.



I don't even have a line 7. It's blank.

I think I'm using this one
https://forum.doom9.org/showthread.php?t=172808

Richard1485
16th December 2017, 18:13
^ With that version, renamed to adjust.py, I receive a different error.

AttributeError: No attribute with the name adjust exists. Did you mistype a plugin namespace?

poisondeathray
16th December 2017, 18:20
Weird, it works here

I'm using it like this


import vapoursynth as vs
import adjust
core = vs.get_core()
#clip = whateversourcefilter()
clip = adjust.Tweak(clip, sat=0.5)
clip.set_output()

Richard1485
16th December 2017, 18:43
Got it! I removed core before adjust.Tweak() and moved import adjust so it came before core = vs.get_core(), and it's working. I think the VapourSynth port of Tweak() works like SmoothTweak() in AviSynth in that when one adjusts hue it shifts the chroma in a linear fashion along an axis. With the original Tweak(), I could rotate/turn the chroma like turning a key in a lock.

poisondeathray
16th December 2017, 18:45
Yes, the one in that post separated U, V hue like smoothtweak .

I only added separate settings for hue v and u (idea taken from SmoothTweak plugin).


The original one by dubhater is more like classic tweak

Richard1485
16th December 2017, 18:56
In that case, I wish I could get the original one to work, but it doesn't. Maybe it's meant for 32-bit VapourSynth; I'm using the 64-bit version.

EDIT: It's a shame that one cannot have both approaches to hue. The ability to rotate the chroma is useful, in my opinion.

poisondeathray
16th December 2017, 19:18
In that case, I wish I could get the original one to work, but it doesn't. Maybe it's meant for 32-bit VapourSynth; I'm using the 64-bit version.

EDIT: It's a shame that one cannot have both approaches to hue. The ability to rotate the chroma is useful, in my opinion.

It works the same way, you can just drop it in and replace

If you want to use both at the same time, just rename one (e.g adjust2.py) and use a different namespace e.g import adjust2 as adjust2


import vapoursynth as vs
import adjust
import adjust2 as adjust2
core = vs.get_core()
#clip = whateversourcefilter()
clip = adjust.Tweak(clip, hue=20)
clip = adjust2.Tweak(clip, huev=10)
clip.set_output()

DJATOM
16th December 2017, 20:02
> import adjust2 as adjust2
that is redundant
import adjust2 will be the same

Selur
17th December 2017, 10:43
Oh, I see. Is there a technical reason for that or is it just preference?
Mainly: readability and easier debugging. :)

Richard1485
17th December 2017, 17:21
If you want to use both at the same time, just rename one (e.g adjust2.py) and use a different namespace e.g import adjust2 as adjust2


Oh, I agree. The problem is that the first version still fails to work for me, so what I meant was that it's a shame that the introduction of the huev and hueu parameters in the second version came at the expense of hue, rather than supplementing it, because if it hadn't, I'd have the solution by now. I feel the same about the change in the function of hue from Tweak() to SmoothTweak() in AviSynth because I'd like to use the latter to rotate chroma, but that doesn't seem to be possible. In fact, initially, I loaded the 64-bit version of SmoothTweak() (successfully) in VapourSynth with that purpose in mind and only subsequently tried the VapourSynth port of Tweak().

Mainly: readability and easier debugging. :)

Ah, I see. I find I can debug my AviSynth scripts well enough, but it's always good for me to see how someone else does it. As a non-programmer, I've picked up what I know mainly through copying others' ways of working.

poisondeathray
17th December 2017, 18:16
Oh, I agree. The problem is that the first version still fails to work for me



Thanks! Unfortunately, that generates a syntax error that points to line 7 of adjust.py itself, possibly because it was written with an older version of Python in mind. I'm using 3.64 with the latest 64-bit version of VapourSynth.


I don't even have a line 7 in either version adjust.py

I doubt it's a python issue

Maybe try downloading it again ?

Richard1485
17th December 2017, 20:05
I've got it to work. I cut and pasted the code into Notepad and saved it as adjust2.py. Obviously, the file was becoming corrupt during download somehow. Thanks for your help!