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 > VapourSynth

Reply
 
Thread Tools Search this Thread Display Modes
Old 3rd September 2015, 16:07   #241  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
@MonoS, Thanks. Your tests look promising. I'll be doing some tests, perhaps this weekend.
Here I uploaded a sequence of png images at 16 bits. I have also included the blender scene in case any of you want to play with it
https://www.dropbox.com/s/xfndrsx5gw...scene.zip?dl=0

Download Blender (OpenSource, Free). Open the scene with Blender. The scene is set to use nvidia GPU (CUDA). If you do not have a good graphics card, in the right panel under "Render" in "Device" choose "CPU". Then on that panel a little below under "Performance" in "Tiles" you put a value of 32 in X and Y (32 is not related to bits, this is only frame size of each thread processor). To render the scene, in above menu in "Render" > "Render Animation". The images are saved by default in your "tmp" folder. Esc aborts rendering. If you want to play with the scene, the right mouse button selects objects. For navigate the 3D view (orbit) press the middle mouse button. You can play animation in the viewport (not rendered) by clicking the play button below in the timeline. What I say just if you want to spend a little fun time with Blender 3D . This scene is very simple just for testing and renders it relatively quickly.

Regarding noise reduction, I think random noise patterns is the right way to proceed, especially if the image has no quick/fast changes between frame and frame. Without knowing much about this, I think it would be relative easy to detect noise with static noise pattern, but then some algorithm should reconstruct the image below the noise considering neighbors pixels, and that would be quite difficult and maybe without good result.

@feisty2, do you know some very simple script where I can test whether "KNLMeansCL" is working well? I think OpenCL headres I installed to compile it only work with opensource drivers (I'm using "nvidia" driver), but I do not know.
YAFU is offline   Reply With Quote
Old 3rd September 2015, 16:16   #242  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,398
Code:
##Load Vaporsynth
import vapoursynth as vs
core = vs.get_core()
##Load The Source Clip
clp = core.imwri.Read('png-50/%04d.png', firstnum=1, alpha=False)
clp = core.fmtc.bitdepth (clp, bits=32, fulls=True, fulld=True, flt=True)
clp = core.fmtc.matrix (clp, mat="601", fulls=True, fulld=True)
##The Actual KNLMeansCL
clp = core.knlm.KNLMeansCL(clp, d=0, a=24, s=4, h=3.2)
##Output
clp.set_output ()
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 3rd September 2015, 16:40   #243  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
Yes, I get the error
Code:
Failed to evaluate the script:
Python exception: knlm.KNLMeansCL: VapourSynthCreate error (clBuildProgram)!
Traceback (most recent call last):
  File "vapoursynth.pyx", line 1469, in vapoursynth.vpy_evaluateScript (src/cython/vapoursynth.c:23703)
  File "/media/TEMPORAL/scrypt.vpy", line 9, in <module>
    clp = core.knlm.KNLMeansCL(clp, d=0, a=24, s=4, h=3.2)
  File "vapoursynth.pyx", line 1368, in vapoursynth.Function.__call__ (src/cython/vapoursynth.c:22272)
vapoursynth.Error: knlm.KNLMeansCL: VapourSynthCreate error (clBuildProgram)!

I'll search what I need to compile correctly for nvidia in Linux.
YAFU is offline   Reply With Quote
Old 3rd September 2015, 17:34   #244  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 184
I made some more test and consideration, and i noticed that after the first denoising stage the only noise left is on the low lights so i've modified the second denoising stage to use a mask

Code:
deno1 = core.mv.Degrain2(clip=input, super=super, mvbw=mvbw, mvfw=mvfw, mvbw2=mvbw2, mvfw2=mvfw2, thsad=400)
def f(x):
	if x < 12000:
		return 65535
	else:
		return 0
maskY = core.std.Lut(deno, [0], function=f).std.ShufflePlanes([0], vs.GRAY)
mask = core.std.ShufflePlanes([maskY, maskY, maskY], [0,0,0], vs.YUV)

deno2 = core.dfttest.DFTTest(deno, sigma=2.5)

ret = core.std.MaskedMerge(deno,deno2, mask)#.fmtc.bitdepth(bits=8, dmode=7)

ret.set_output()

#remove the # from the line below to see the mask
#maskY.set_output()
It still use dfttest because i don't want to install KNLMeansCL right now but would be enough to substitute the function call
MonoS is offline   Reply With Quote
Old 3rd September 2015, 17:43   #245  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,398
Install? Sounds real complicated...
I didn't "install" knlmeanscl, just put the .dll in the plugin folder, then, it's just okay
Why u guys gotta "install" it?
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 3rd September 2015, 18:03   #246  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
@feisty2, dll is for windows. It is not easy to find binaries for Linux
Even developers usually share binaries for Windows, but only sources for Linux. But this is understandable, because each distro maintainers are responsible for putting the binaries in repositories. But for not very common applications is a bit more difficult to find them.


@MonoS, In mensje #237 in the first line I have replaced "src" by "clip=ret". Is it right?
EDIT:
otherwise I get the following error:
Code:
Failed to evaluate the script:
Python exception: name 'src' is not defined
Traceback (most recent call last):
  File "vapoursynth.pyx", line 1469, in vapoursynth.vpy_evaluateScript (src/cython/vapoursynth.c:23703)
  File "/media/TEMPORAL/scrypt.vpy", line 35, in <module>
    input = core.fmtc.bitdepth(src, flt=True).fmtc.matrix(mat="601", col_fam=vs.YUV).fmtc.bitdepth(bits=16)
NameError: name 'src' is not defined
But maybe I'm doing something wrong because I'm building the script with parts of the lines you posted on each message.

I also needed this (in case some user read this thread in the future):
https://github.com/chikuzen/GenericFilters
https://github.com/HomeOfVapourSynth...rSynth-DFTTest

Last edited by YAFU; 3rd September 2015 at 18:13.
YAFU is offline   Reply With Quote
Old 3rd September 2015, 18:17   #247  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 184
@feisty2: i hope this is enough of a reason to not "install" something XD http://abload.de/img/clipboard02wxobh.png [AKA i've other things to do]

@YAFU: I've made hack upon hack on the initial script you linked us, now mine look like this
Code:
src = core.imwri.Read("C:/Users/MonoS/Desktop/BlenderCycles-VapourSynth/images/%04d.png", firstnum=50)

input = core.fmtc.bitdepth(src, flt=True).fmtc.matrix(mat="601", col_fam=vs.YUV).fmtc.bitdepth(bits=16, dmode=7)

superF1 = DitherLumaRebuild(input, s0=1)
superF2 = core.mv.Super(superF1, pel=2, sharp=1)
super = core.mv.Super(input)
mvbw2 = core.mv.Analyse(superF2, isb=True, delta=2, overlap=4)
mvbw = core.mv.Analyse(superF2, isb=True, delta=1, overlap=4)
mvfw = core.mv.Analyse(superF2, isb=False, delta=1, overlap=4)
mvfw2 = core.mv.Analyse(superF2, isb=False, delta=2, overlap=4)
 
deno = core.mv.Degrain2(clip=input, super=super, mvbw=mvbw, mvfw=mvfw, mvbw2=mvbw2, mvfw2=mvfw2, thsad=400)
def f(x):
	if x < 12000:
		return 65535
	else:
		return 0
maskY = core.std.Lut(deno, [0,1,2], function=f).std.ShufflePlanes([0], vs.GRAY)
mask = core.std.ShufflePlanes([maskY, maskY, maskY], [0,0,0], vs.YUV)

ret = core.std.MaskedMerge(deno,core.dfttest.DFTTest(deno, sigma=2.5), mask)#.fmtc.bitdepth(bits=8, dmode=7)
now i don't know if in your script input and ret are the same clip

you don't need anymore GBlur, some testing showed me that it lower the final quality and destroy a lot of small details, so no need to use generics [and AFAIK they'll be included in the next main version of vapour]
If feisy said that dfttest is not the ideal solution, trust him, he surely made more extensive testing than me on that, so better link KNLMeansCL
MonoS is offline   Reply With Quote
Old 3rd September 2015, 19:58   #248  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 310
@YAFU: on gentoo you need to install nvidia-drivers and it's uvm kernel module, I don't know if it is included in your distro of if it is your problem at all.
Are_ is offline   Reply With Quote
Old 3rd September 2015, 22:11   #249  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
hi Are_
Using Kubuntu 64 bits.

"nvidia_uvm" seems loaded into the kernel and nVidia OpenCL in Blender 3D seems to be working properly.

I asked in the KNLMeans thread to see if they can help me.
YAFU is offline   Reply With Quote
Old 4th September 2015, 08:30   #250  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,398
@jackoneill
BlockFPS crashes mvtools on GRAY clips (I think something is wrong inside "mvblockfpsFree")

EDIT:
fixed, pulled a request on Git
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated

Last edited by feisty2; 4th September 2015 at 10:08.
feisty2 is offline   Reply With Quote
Old 5th September 2015, 13:10   #251  |  Link
mawen1250
Registered User
 
Join Date: Aug 2011
Posts: 103
For eliminating static noise, you might want to give BM3D a try, which can do an excellent job for nearly all kinds of small noise patterns.
mawen1250 is offline   Reply With Quote
Old 5th September 2015, 15:17   #252  |  Link
feisty2
I'm Siri
 
feisty2's Avatar
 
Join Date: Oct 2012
Location: Providence, RI
Posts: 2,398
Code:
xxx
sup = MSuper(last,chroma=False)
bv1 = MAnalyse(sup,isb=True,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1,chroma=False)
fv1 = MAnalyse(sup,isb=False,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1,chroma=False)
bv2 = MAnalyse(sup,isb=True,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1,chroma=False)
fv2 = MAnalyse(sup,isb=False,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1,chroma=False)
bv3 = MAnalyse(sup,isb=True,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1,chroma=False)
fv3 = MAnalyse(sup,isb=False,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1,chroma=False)
MDegrain3(last, sup, bv1, fv1, bv2, fv2, bv3, fv3, thsad=2000, thscd1=10000)
converttoy8 ()


Code:
import vapoursynth as vs
core = vs.get_core()
clp = xxx
clp = core.std.ShufflePlanes(clp, planes=0, colorfamily=vs.GRAY)
clp = core.fmtc.bitdepth(clp, fulls=False, fulld=True, bits=32, flt=True)
clp2 = core.fmtc.bitdepth(clp, fulls=False, fulld=True, bits=16)
sup = core.mvsf.Super(clp)
bv1 = core.mvsf.Analyze(sup,isb=True,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1)
fv1 = core.mvsf.Analyze(sup,isb=False,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1)
bv2 = core.mvsf.Analyze(sup,isb=True,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1)
fv2 = core.mvsf.Analyze(sup,isb=False,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1)
bv3 = core.mvsf.Analyze(sup,isb=True,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1)
fv3 = core.mvsf.Analyze(sup,isb=False,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1)
clp = core.mvsf.Degrain3(clp, sup, bv1, fv1, bv2, fv2, bv3, fv3, thsad=2000, thscd1=10000)

sup2 = core.mv.Super(clp2)
bv12 = core.mv.Analyse(sup2,isb=True,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1)
fv12 = core.mv.Analyse(sup2,isb=False,blksize=16,overlap=8,delta=1,search=3,truemotion=True,dct=1)
bv22 = core.mv.Analyse(sup2,isb=True,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1)
fv22 = core.mv.Analyse(sup2,isb=False,blksize=16,overlap=8,delta=2,search=3,truemotion=True,dct=1)
bv32 = core.mv.Analyse(sup2,isb=True,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1)
fv32 = core.mv.Analyse(sup2,isb=False,blksize=16,overlap=8,delta=3,search=3,truemotion=True,dct=1)
clp2 = core.mv.Degrain3(clp2, sup2, bv12, fv12, bv22, fv22, bv32, fv32, thsad=2000, thscd1=10000)
clp2 = core.fmtc.bitdepth(clp2, fulls=True, fulld=True, bits=32, flt=True)

fnl = core.std.StackHorizontal([clp,clp2])
fnl.set_output ()


@jackoneill
guess I just fixed dct 1-4 (fftw modes) in my floating point branch
tried to fix it on uint16_t, your original version, but failed
maybe you could try to fix it yourself
more details at https://github.com/IFeelBloated/MVTo...er/DCTFFTW.cpp
__________________
If I got new ideas, will post here: https://github.com/IFeelBloated
feisty2 is offline   Reply With Quote
Old 7th September 2015, 13:30   #253  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
Hello. I've been doing some experiments.
Apparently what mainly produces banding is this line at end in the original script:
Code:
ret = core.fft3dfilter.FFT3DFilter(ret,sigma=2.5, bt=5, bw=32, bh=32, ow=16, oh=16, sharpen=0.7)
http://www.pasteall.org/60466

I have understood that this line is to reduce fine grain noise, right?
I found a good way for those banding are not very noticeable. Basically, create a lossless video with the original script, but without that line.

Then apply the script to the resulting video, but in superF1 replacing with the values of that line that was removed:
Code:
import vapoursynth as vs
core = vs.get_core()

##
##ffmpeg with ffms2
core.std.LoadPlugin('/usr/lib/x86_64-linux-gnu/libffms2.so.3')
ret = core.ffms2.Source(source='/PATH_TO_VIDEO_HERE/encoded.mkv')
##
input = core.fmtc.bitdepth (clip=ret, bits=8)
 
superF1 = core.fft3dfilter.FFT3DFilter(input,sigma=2.5, bt=5, bw=32, bh=32, ow=16, oh=16, sharpen=0.7)
superF2 = core.mv.Super(superF1, pel=2, sharp=1)
super = core.mv.Super(input)
mvbw3 = core.mv.Analyse(superF2, isb=True, delta=3, overlap=4)
mvbw2 = core.mv.Analyse(superF2, isb=True, delta=2, overlap=4)
mvbw = core.mv.Analyse(superF2, isb=True, delta=1, overlap=4)
mvfw = core.mv.Analyse(superF2, isb=False, delta=1, overlap=4)
mvfw2 = core.mv.Analyse(superF2, isb=False, delta=2, overlap=4)
mvfw3 = core.mv.Analyse(superF2, isb=False, delta=3, overlap=4)
 
ret = core.mv.Degrain3(clip=input, super=super, mvbw=mvbw, mvfw=mvfw, mvbw2=mvbw2, mvfw2=mvfw2, mvbw3=mvbw3, mvfw3=mvfw3, thsad=400)
 
ret.set_output()
Then the noise reduction is similar to original script, but with less banding.
I guess that I've done it can be done from a single script without the intermediate step by creating these first video, but I have no idea about how to create this script. How could I do it?

The noise reduction in the kind of noise that renders from Blender 3D generate using this method/script is amazing.
It is a pity that Fft3d not support 16 bits because the result could be even better. Do you know if that filter is still under development and whether it plans to support 16-bit?

Last edited by YAFU; 7th September 2015 at 13:38.
YAFU is offline   Reply With Quote
Old 7th September 2015, 16:03   #254  |  Link
HolyWu
Registered User
 
HolyWu's Avatar
 
Join Date: Aug 2006
Location: Taiwan
Posts: 755
I don't think you must stick to FFT3DFilter. You can use DFTTest as an alternative like MonoS has suggested before. And for strong denoising you can just apply mv.Degrain twice in the same script, no need to create an intermediate lossless video. For convenience I'd suggest you using SMDegrain (contained in havsfunc) as well.

Code:
import vapoursynth as vs
import havsfunc as haf
core = vs.get_core()
core.max_cache_size = 2048

ret = core.imwri.Read('%04d.png', firstnum=1)
ret = core.fmtc.matrix(ret, mat='601', col_fam=vs.YUV)

ret = haf.SMDegrain(haf.SMDegrain(ret, tr=2, thSAD=400, pel=2, prefilter=3), tr=2, thSAD=400, pel=2, Globals=1)

#ret = core.fmtc.bitdepth(ret, bits=8)

ret.set_output()

Last edited by HolyWu; 7th September 2015 at 16:07.
HolyWu is offline   Reply With Quote
Old 7th September 2015, 16:41   #255  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
Hello HolyWu.
It seems that in the HAvsFunc thread there are no instructions for Linux. Where should I copy havsfunc.py in Linux?
Regarding suggestions of MonoS, I was able to build this script with parts of code from his different messages, I do not know if I have done well:
http://www.pasteall.org/61017
For now I get better noise reduction with the original script using FFT3DFilter.
YAFU is offline   Reply With Quote
Old 7th September 2015, 17:19   #256  |  Link
HolyWu
Registered User
 
HolyWu's Avatar
 
Join Date: Aug 2006
Location: Taiwan
Posts: 755
Quote:
Originally Posted by YAFU View Post
Hello HolyWu.
It seems that in the HAvsFunc thread there are no instructions for Linux. Where should I copy havsfunc.py in Linux?
Sorry, I'm not familiar with Linux. From what https://docs.python.org/3.4/install/...allation-works says, I guess you should copy havsfunc.py to either /usr/lib/pythonX.Y/site-packages or /usr/local/lib/pythonX.Y/site-packages, depending on you build Python yourself or not.
HolyWu is offline   Reply With Quote
Old 7th September 2015, 19:24   #257  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
Just in case this is useful to someone else, I explain:

I have installed at least three versions of python (I guess they have been left of different system updates). So I have different paths to "/pythonX.Y/site-packages" both in "/usr/local/lib" and "/usr/lib". So from linux terminal:
Code:
whereis vapoursynth
And you get "/usr/local/lib/vapoursynth" or "/usr/lib/vapoursynth" depending on where you've installed it. Generally if you have compiled without specified path, default it is installed in "/usr/local/lib/", and if you installed from a distribution package generally is installed in "/usr/lib". So depending on that copy "havsfunc.py" to "/usr/local/lib/pythonX.Y/site-packages" or "/usr/lib/pythonX.Y/site-packages". "X.Y" should be the highest version of python you had when you installed vapoursynth. In my case I have copied it to "/usr/local/lib/python3.4/site-packages". In the same path there were two files, "vapoursynth.la" and "vapoursynth.so".

I will study this little script and do some testing with these images that I have shared in previous posts in this thread.
YAFU is offline   Reply With Quote
Old 7th September 2015, 20:00   #258  |  Link
Are_
Registered User
 
Join Date: Jun 2012
Location: Ibiza, Spain
Posts: 310
If you don't want to deal with root access every time you want to update/install a new module:
Code:
# echo "/home/your-user/some-path-to-a-directory-with-all-your-modules" > /usr/local/lib/python3.4/site-packages/vapoursynth_modules.pth
Are_ is offline   Reply With Quote
Old 7th September 2015, 23:37   #259  |  Link
YAFU
Registered User
 
Join Date: Aug 2015
Posts: 40
Ok Are_, I'll try that
YAFU is offline   Reply With Quote
Old 8th September 2015, 19:03   #260  |  Link
MonoS
Registered User
 
Join Date: Aug 2012
Posts: 184
If someone don't come up with some suggestion, this is my "final suggestion"
The video outputted is this one http://www.mediafire.com/watch/mws7c9hgwwrsqjm/test.mkv
The script used this [i wrote some comments for you]

Code:
import vapoursynth as vs
import havsfunc as has

core = vs.get_core()

#Load imwri
core.std.LoadPlugin("C:/Program Files (x86)/VapourSynth/plugins64/imwri/imwri.dll")

#Read images
src = core.imwri.Read("C:/Users/MonoS/Desktop/BlenderCycles-VapourSynth/images/%04d.png", firstnum=50)

#converting input RGB images to YUV444
input = core.fmtc.bitdepth(src, flt=True).fmtc.matrix(mat="601", col_fam=vs.YUV).fmtc.bitdepth(bits=16, dmode=7)

#This should improve motion estimation for darken zones
superF1 = has.DitherLumaRebuild(input, s0=1)
superF2 = core.mv.Super(superF1, pel=2, sharp=1)

super = core.mv.Super(input)

#Do motion compesated denoising
mvbw2 = core.mv.Analyse(superF2, isb=True, delta=2, overlap=4)
mvbw = core.mv.Analyse(superF2, isb=True, delta=1, overlap=4)
mvfw = core.mv.Analyse(superF2, isb=False, delta=1, overlap=4)
mvfw2 = core.mv.Analyse(superF2, isb=False, delta=2, overlap=4)
deno = core.mv.Degrain2(clip=input, super=super, mvbw=mvbw, mvfw=mvfw, mvbw2=mvbw2, mvfw2=mvfw2, thsad=400)

#After first denoising stage the majority of the grain is on the darker zone, create a mask of only the dark zones
def f(x):
	if x < 12000:
		return 65535
	else:
		return 0
maskY = core.std.Lut(deno, [0,1,2], function=f).std.ShufflePlanes([0], vs.GRAY)
mask = core.std.ShufflePlanes([maskY, maskY, maskY], [0,0,0], vs.YUV)

#Do a second pass of spatial denoising only on the masked zones
ret = core.std.MaskedMerge(deno,core.dfttest.DFTTest(deno, sigma=2.5), mask)

#Delete # below to output a 8bit clip
#ret = core.fmtc.bitdepth(bits=8, dmode=7)

ret.set_output()

#Delete # below to output a video showing the difference between the the first and second denoise pass
#core.std.Interleave([deno, ret]).set_output()

#Delete # below to output the mask
#mask.set_output()
I also suggest a moderator to move all this discussion about removing ray tracing noise artifact into a new thread, we went a bit to OT imho


EDIT: i've thrown inside the script the jpg you sent us at the beginning, FAAAAR better result if you ask me
http://www.mediafire.com/watch/ypwrf...fy/testjpg.mkv

Last edited by MonoS; 8th September 2015 at 19:24.
MonoS 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 00:02.


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