Log in

View Full Version : How to do 3D Lut color correction (.3DL .Cube) with avisynth(+) ?


Pages : [1] 2 3 4

K.i.N.G
25th June 2018, 16:44
I wasn't too happy with the current HDR -> SDR filters available so I decided to create some luts but I can't find anything online on how to use them in avisynth?

Surely this must be possible? Since luts are such commonly used files for this kind of thing.

videoh
25th June 2018, 17:58
I wasn't too happy with the current HDR -> SDR filters available Which ones did you try and why were you unhappy with them?

TheFluff
26th June 2018, 14:08
There is a VapourSynth filter (https://github.com/sekrit-twc/timecube/) that can apply 3D LUT's in .cube format (some Adobe thing I believe), FWIW.

K.i.N.G
29th June 2018, 12:48
Which ones did you try and why were you unhappy with them?

DGHable and DGReinhard ... i get the impression some tones are problematic.
With my current test im having problems with orange reds (getting too orange yellow). Making skin tones not as good as i'd like.
Maybe its just me? I've only tested 2 discs for now.

Also, I'm not a big fan of exaggerated tinting of a whole movie (there are exceptions) or remasters ruined by bad grading.
Good examples are "the good, the bad and the ugly remastered" or the lord of the rings trilogy extended edition... where the grading looks much worse than the original.

So also in those cases it would be sweet if I could just use/load a lut with corrections I did (to my personal taste).

K.i.N.G
29th June 2018, 12:54
There is a VapourSynth filter (https://github.com/sekrit-twc/timecube/) that can apply 3D LUT's in .cube format (some Adobe thing I believe), FWIW.

Nice, I'll have to try that out later...
Im using DGhable & DGreinhard in avisynth (through StaxRip) though so I'd be more usefull for me if there was a solution using avisynth

FranceBB
9th August 2018, 20:51
I came across this topic looking for a LUT plugin in Avisynth/Avisynth+.
I'm actually using ffmpeg to apply my LUTs, but it would be really useful to have the VapourSynth filter ported to Avisynth.

Yanak
10th August 2018, 06:58
I once asked here if somehow possible to port this into avisynth http://forum.doom9.org/showthread.php?p=1837229#post1837229

Seems like it's something that will be difficult... it's really something i miss to make avisynth complete for my use, like you i use ffmpeg to do this task for now when i need it.

TheFluff
11th August 2018, 00:50
I doubt it would be hard to port, the plugin interface is separated from the actual processing.

videoh
11th August 2018, 00:51
I've started working on it. :)

Yanak
11th August 2018, 07:24
You cannot imagine how sweet those words sound to my hears :)

If you manage to get this working on avisynth it will be a game changer for me and i imagine many others.

Thank you very much.

videoh
11th August 2018, 14:52
What formats do you need, in order of priority?

Yanak
11th August 2018, 16:05
For me I use mostly .cube files, not sure what others use the most, .3dl it's very rare to use those for me, i use more haldclut files than .3dl to say :p

Thank you.

videoh
11th August 2018, 16:17
I was referring to the input and output pixel formats of the filter itself. Can you specify those please?

Assuming the filter exists, what would your script look like?

FranceBB
11th August 2018, 16:51
Definitely .cube as cube LUT format.
As to the color space and bit-depth, I would say 4:2:0 8bit / 4:2:0 10bit input and output.
LUTs are generally used to apply a specific type of color correction in post-production, but in a 2018-Avisynth scenario, I would say that they would be mainly use them for HDR.
In other words, I think people would use them to tone-map HDR to SDR, HLG to HDR10 and so on.
So I would say that Rec.709 and Rec.2020 should be supported as well.

Is it possible?

If you wanna test out two .cubes, you can find mine here:



BT709_to_PQ_400: https://mega.nz/#!3N0TSSLT!KkhslQPudhXBZMW0yKBGzhwm6lS5AYxUcIV2BZzxuw0
BT709_to_PQ_800: https://mega.nz/#!DdMhUCgC!djQpewXxZr8YXQoeBhz-KnBRAhnZ-T7FbHnVoYKV2l0

Output limited to 1000nit.


https://i.imgur.com/YFjToim.png

Yanak
11th August 2018, 18:08
^ What he said 420p8 mostly as input, I guess some use it on 422 too, and mostly 420p8/10 as output i think.

Also used on raw footage ( slog from drones for example) to correct colors, or to apply some effects like with CineStyle_S_Curve lut, or Kodachrome (https://frankglencairn.wordpress.com/2014/01/15/everything-looks-better-on-kodachrome-k-tone-lut/) effect, can be used to turn stuff recorded in summer with loads or greens into autumn colors (https://www.smallhd.com/community/free-lut-arapaho) etc etc

videoh
11th August 2018, 18:15
OK, guys, thank you.

WorBry
11th August 2018, 19:02
i use more haldclut files than .3dl to say :p


Easy to convert HaldCLUT to CUBE with IWLTBAP_LUT_Generator. Did that with Pat David's G'MIC Film Emulations:

https://gmic.eu/film_emulation/negative_new_sample_1.shtml#browse

Would be nice to use those in AVISynth(+).

Yanak
12th August 2018, 06:51
Thanks for the link, i'll give it a try soon, G'mic plugin for Gimp is what i often use to create and generate custom haldcluts from static images i modify, then later apply them on videos via FFmpeg, this will certainly help a lot if videoh manage to get this working on avs+ it will be very nice indeed.

Thank you :)

WorBry
13th August 2018, 15:13
You're welcome.

...videoh manage to get this working on avs+ it will be very nice indeed

Yes, it would open up many possibilities.

StainlessS
13th August 2018, 16:27
I have no idea if these couple of files are of any interest to anyone (had them for years, never really looked at them much).

Adobe Cube Lut Specs, v1.0(~228KB):- http://www.mediafire.com/file/ptd2lt3xludabbo/cube-lut-specification-1.0.pdf.7z/file

yCMS_x86, excerpt from manual, (maybe there is an x64 version somewhere)
yCMS - Color Management System
v1.12 2012/11/07

________________________________________________________________________________

INTRODUCTION
________________________________________________________________________________


yCMS is a Color Management System (CMS) that uses 3-dimensional lookup
tables ("3D LUTs") to perform the conversion between the input and output
color representations. You can read a little more about CMS here:
http://en.wikipedia.org/wiki/Color_management

The idea of using 3D LUTs was due to the intensive computing that needs to
be performed when converting video data between different color spaces. When
using 3D LUTs all computing is performed offline during its creation. The
computed 3D LUTs (three, one for each component) are then written to a file
which can later be used, when playing videos or viewing photos, simply by
mapping the input data through the 3D LUTs. This way, the conversion can be
performed at runtime using lower computational power and leaving more CPU
available for other tasks. Since all the computing is performed offline its
precision can be increased by using 64bit floating point (per component)
through out all the conversion chain.

(~239KB):- http://www.mediafire.com/file/8ppce1j87qj6f2c/yCMS_x86.rar/file
EDIT: Above yCMS_x86 (home site is now dead) and thread here on D9 not active since 2013.
https://forum.doom9.org/showthread.php?t=154719&highlight=ycms


EDIT:
Apply two 3x3 matrices to each pixel? :- https://forum.doom9.org/showthread.php?p=1706626

RGB/XYZ Matrices:- http://www.brucelindbloom.com/index.html?Eqn_RGB_XYZ_Matrix.html

videoh
15th August 2018, 17:22
I have vscube ported to Avisynth+ and have successfully applied a 3D LUT using an Avisynth+ script. I have to properly implement the parameters and test thoroughly before I can give it to y'all. Meanwhile, I have a few questions:

1. In Vapoursynth, this gives me a red clip:

clip = core.std.BlankClip(width=640,height=480,format=vs.RGB24, length=1000, keep=True, color=[255, 0, 0])

but this gives me a black clip:

clip = core.std.BlankClip(width=640,height=480,format=vs.RGB48, length=1000, keep=True, color=[255, 0, 0])

So is it a bug or am I missing something?

2. Can anyone give me a HDR10 PQ->SDR 3D LUT that I can test with?

Thank you.

poisondeathray
15th August 2018, 17:27
1. In Vapoursynth, this gives me a red clip:

clip = core.std.BlankClip(width=640,height=480,format=vs.RGB24, length=1000, keep=True, color=[255, 0, 0])

but this gives me a black clip:

clip = core.std.BlankClip(width=640,height=480,format=vs.RGB48, length=1000, keep=True, color=[255, 0, 0])

So is it a bug or am I missing something?


In 16bit, 100% red would be 65535

videoh
15th August 2018, 17:35
Duh, thank you, poisondeathray!

StainlessS
16th August 2018, 01:32
In 16bit, 100% red would be 65535

Yep, that is a little bit of a nasty, its pretty horrible that one has to cater to differing ranges dependant upon
bit depth, cant suggest anything better, but is still horrible.

huhn
16th August 2018, 02:55
2. Can anyone give me a HDR10 PQ->SDR 3D LUT that I can test with?

https://displaycal.net

you can create 3D lut from what ever source profile with what ever target nit you want with this tool.

WorBry
16th August 2018, 06:22
DaVinci Resolve 15 (including free version) has a series of HDR ST 2084 (300 - 4000 nits) <-> Gamma (2.4, 2.6, 2.8) conversion LUT's (cube). I've not tested any of them outside of Resolve though.

With the program installed, the folder location is C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\LUT\HDR ST 2084.

wonkey_monkey
16th August 2018, 08:57
Yep, that is a little bit of a nasty, its pretty horrible that one has to cater to differing ranges dependant upon
bit depth, cant suggest anything better, but is still horrible.

One solution is to allow a different way of specifying colour like fcolor={1.0, 0.0, 0.0}

videoh
16th August 2018, 11:23
DaVinci Resolve 15 (including free version) has a series of HDR ST 2084 (300 - 4000 nits) <-> Gamma (2.4, 2.6, 2.8) conversion LUT's (cube). I've not tested any of them outside of Resolve though.

With the program installed, the folder location is C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support\LUT\HDR ST 2084. That's great, WorBry, thank you!

videoh
16th August 2018, 15:49
Here is a test version of 3D LUT support for Avisynth+. I will provide source code when it is tested OK. Please refer to the user document for usage details. Your feedback will be appreciated.

http://rationalqm.us/misc/avscube_1.0.rar

WorBry
17th August 2018, 03:11
Done a few quick tests - applied a few color grade 3D cube LUT's (created in Resolve) with avscube to some (linear) Rec709 HD test footage and greyscale ramps - and it looks to be working as expected. Excellent.

FranceBB
17th August 2018, 13:59
It works as expected.
By the way, you wrote to use avsresize to convert to RGB 16bit, but you can convert without using it like so:

video3=DGDecode_MPEG2Source("I:\Production\RAW\424-430\427.d2v")
audio3=FFAudioSource("I:\Production\RAW\424-430\427 T81 2_0ch 224Kbps DELAY -134ms.ac3")
AudioDub(video3, audio3)

tfm(mode=1,pp=5,slow=2,micmatching=2,clip2=tdeint(mode=2,type=3))
tdecimate()
ConvertFPS(23.976)

trim(0, 500)

Crop(4, 0, -4, -0)

Spline64Resize(848, 480)

ConvertBits(16)

ConvertToPlanarRGB()

Cube("BT601_to_BT709.cube")

Converttoyuv420()

I tested it with a simple BT601 to BT709.
I don't really do BT601 to BT709 conversion using a LUT 'cause I generally use ColorMatrix for 8bit and Dither_Tools for 16bit, but in order to test your new plugin, I did and it was fine.

Thank you very much indeed.

WorBry
17th August 2018, 18:23
Quick question for ye high bit-depth AVS processing experts (me not being one).

I have some 10-bit 422 DNxHD.mov clips with 'full range' (0-1023 in 10-bit) luma. I want to test a 3D LUT.cube (created with DaVinci Resolve) that applies a 'soft clip' i.e. clips 'Full' to 'Limited' range (64 - 940) but with a soft roll-off - offers an alternative to 'hard-clipping' (clamping) or compression when constraining full range material to 'broadcast safe' range.

Came up with this basic script, but I'm not sure what 'colorspace_op' string expressions to apply in z_ConvertFormat so that 'Full' (PC.709) range coefficients are applied in the conversion to RGBP16 and then 'Limited' (Rec.709) range coefficients are applied in the output conversion to YV16:

LSMASHVideoSource("{Path}:\Test_DNxHD_10bit_422_Full_Range.mov", format="YUV422P10")
ConvertFromDoubleWidth(bits=10)
z_ConvertFormat(pixel_type="RGBP16",colorspace_op ="?????")
Cube("{Path}:\Soft_Clip_64_940_20.cube")
z_ConvertFormat(pixel_type="YV16",colorspace_op ="?????")

Could anyone point me to a reference that gives a full description of the 'colorspace_op' parameter terms and definitions.

Thanks.

videoh
17th August 2018, 19:13
https://forum.doom9.org/showthread.php?p=1784247#post1784247

One thing I am not clear on is whether the 3D LUT expects linear RGB. If so, then maybe something like:

z_ConvertFormat(pixel_type="RGBP16",colorspace_op="709:709:709:l=>rgb:linear:709:f")
Cube("{Path}:\Soft_Clip_64_940_20.cube")
z_ConvertFormat(pixel_type="YV16",colorspace_op="rgb:linear:709:f=>709:709:709:l")

But the cube name suggests it is for limited range, so wouldn't you want to keep it limited and set fullrange=false for Cube()? Just a thought, I'm probably more clueless than you about this stuff. ;)

Thanks, guys, for your testing and feedback.

WorBry
17th August 2018, 20:37
Thanks for reference link. It's clear now. Works as expected. Example:

LSMASHVideoSource("{Path}:\GSRamp_DNxHD_10bit_422_Full_Range.mov", format="YUV422P10")
ConvertFromDoubleWidth(bits=10)
z_ConvertFormat(pixel_type="RGBP16",colorspace_op ="709:709:709:f=>rgb:709:709:f")
Cube("{Path}:\Soft_Clip_64_940_20.cube")
z_ConvertFormat(pixel_type="YV16",colorspace_op ="rgb:709:709:l=>709:709:709:l")
#
LanczosResize(720,720)
TurnRight()
Histogram(mode="classic")

http://i.imgur.com/K9nDlqPm.png (https://imgur.com/K9nDlqP)

Resolve actually has a dedicated tool for creating custom Soft-Clip LUT's but they are 1D LUT's with a proprietary file extension (.olut) for in-program use only - as far as I know they cannot be converted externally. Only workaround is to apply the Soft-Clip LUT to a clip (full range greyscale ramp) on the timeline and generate an exportable 3D Cube LUT from that. But it works. Cool.

videoh
17th August 2018, 21:42
Thanks for the feedback, WorBry. And FranceBB. Great to hear it is working as expected.

@all

I added the source code to the linked file. It's just one new file and the Avs+ headers added to the vscube directory. Maybe sekrit-twc can absorb it. Otherwise I will link it at my website.

Revan654
27th August 2018, 18:58
Do any of the 3D Lut Filters Support iluts, cube_shaperlut or olut? These are mainly generated through Blackmagic.

WorBry
27th August 2018, 19:55
As mentioned earlier:


Resolve actually has a dedicated tool for creating custom Soft-Clip LUT's but they are 1D LUT's with a proprietary file extension (.olut) for in-program use only - as far as I know they cannot be converted externally. Only workaround is to apply the Soft-Clip LUT to a clip (full range greyscale ramp) on the timeline and generate an exportable 3D Cube LUT from that. But it works. Cool.

That's the only workaround I know. I use the Grey Scale generator (Edit Page>Effects Library> Generators) to create the Grey Scale clip on the timeline (convert to New Compound Clip). On the Color Page, I then apply the 1D LUT to the clip (Node Graph) and right click the clip thumbnail (Timeline) to select Generate 3DLUT (cube).

WorBry
30th August 2018, 03:32
..cube_shaperlut..

I think a .cube_shaperlut is just some internal system intermediary. If you look in:

C:\ProgramData\Blackmagic Design\DaVinci Resolve\Support

....you'll see that there are two folders, LUT and .LUT

The LUT folder is where the actual 3D.cube and ID (.ilut/.olut) files reside and where externally created 3D cube LUT's should be placed for import.

The .LUT folder is a private system folder. In it you'll see there is a corresponding .cube_shaperlut extension file and a .cube_shaperlut.png for each 3D.cube LUT found in the LUT folder. For each ID (.ilut/.olut) LUT in the LUT folder however there is a like-named file (but with no extension) and .png file.

Looks like these files are generated automatically when the LUT Listing is updated.

Edit: There was some suggestion that other programs (Nuke) are able to read these .cube_shaperlut files, when the extension is changed to .cube.

https://www.liftgammagain.com/forum/index.php?threads/lut-export-in-rcm-linear-timeline-colorspace.5644/

Out of curiosity, I put that to the test. Copied the .cube_shaperlut file corresponding to one of the 3D.cube LUT's that I had tested earlier, changed the extension to .cube and tried it with AVSCube. No chance - 'Unhandled C ++ Exception'. The file size was also smaller (421kb) than the bone-fide .cube LUT (971 kb).

Also tried placing the .cube_shaperlut file (with extension changed to .cube) in the Support> LUT folder. After updating the LUT listing, the file did appear in the 3D LUT drop down menu and LUT gallery, but applying it to a clip had absolutely no effect.

I don't think these .cube_shaperlut files hold any value outside of Resolve.

Incidentally, the .png file that is created in the .LUT folder is the stock thumbnail image that is presented in the LUT Gallery with the LUT effect applied. Maybe these .cube_shaperlut files are operators for that.

TomArrow
23rd November 2018, 21:06
This plugin is amazing, works very fine. Thank you.

Any way you could implement an alternate function that, instead of a path to a .cube file, accepts a HALD CLUT?

For reference, it's this: http://www.quelsolaar.com/technology/clut.html

Now, I know I can just convert a CLUT to a CUBE file, but what I would really wanna do is be able to load a non-static CLUT.

Imagine this: Your friend is working on the same project as you and has done a color correction on an entire movie. You wanna continue his work, but dont want to send terabytes of data around. So your friend simply renders his corrections into a Lagarith RGB HALD CLUT AVI and you simply load it over the source material and BAM, you have all his corrections, no matter what software he used.

Could also play around with that a lot and create funny effects I'm sure. Shouldn't be too difficult to implement, right? It would just have to accept a 16bit RGB 4096x4096 clip. That could come from an Image (ImageSource) or from a video, it wouldn't matter.

Stereodude
24th January 2019, 01:36
Thanks for the plugin videoh I got a black screen when I set fullrange=false. It works okay with fullrange=true.

LoadPlugin("C:\HDTV Tools\DGDecNV\DGDecodeNV.dll")
LoadPlugin("C:\HDTV Tools\avscube\x64\vscube.dll")

DGSource("00005.dgi").crop(0,114,-0,-114).ConvertBits(16)

ConvertToPlanarRGB(matrix="PC.709").crop(0,1,0,-1)

Cube("C:\HDTV Tools\avscube\U-CANON-C-LOG-V1-LTR.cube", fullrange=true)

ConvertToYUV420(matrix="PC.709").ConvertBits(8, dither = 0)

videoh
24th January 2019, 03:30
I'll look into it, Stereodude. Thanks for pointing it out. Can you please give me your cube file? Thank you.

Stereodude
24th January 2019, 21:26
I'll look into it, Stereodude. Thanks for pointing it out. Can you please give me your cube file? Thank you.
It's in this zip file.

http://stereodude.net/LUT.zip

videoh
24th January 2019, 23:11
Got it, thank you.

Can you give me a mediainfo dump on your source file, please? Is it HDR, etc?

videoh
24th January 2019, 23:40
Seems that this was fixed in timecube at some point:

https://forum.doom9.org/showthread.php?p=1850130#post1850130

The code link there is broken so I'll try to hunt down the r2 changes.

videoh
24th January 2019, 23:48
Latest code is here:

https://github.com/sekrit-twc/timecube

I'll do a re-port to Avisynth+ starting with this latest code.

Stereodude
24th January 2019, 23:59
Got it, thank you.

Can you give me a mediainfo dump on your source file, please? Is it HDR, etc?
General
Complete name : E:\TempBD\TIM\05\00005.h264
Format : AVC
Format/Info : Advanced Video Codec
File size : 618 MiB
Overall bit rate mode : Variable

Video
Format : AVC
Format/Info : Advanced Video Codec
Format profile : High@L4.1
Format settings : CABAC / 4 Ref Frames
Format settings, CABAC : Yes
Format settings, RefFrames : 4 frames
Bit rate mode : Variable
Maximum bit rate : 38.0 Mb/s
Width : 1 920 pixels
Height : 1 080 pixels
Display aspect ratio : 16:9
Frame rate : 23.976 (24000/1001) FPS
Color space : YUV
Chroma subsampling : 4:2:0
Bit depth : 8 bits
It is FHD directly from a Blu-ray. It is not HDR. It looks very flat. I believe that they shot the footage in C-Log (Canon Log) and didn't bother to grade it. Hence my interest in applying a C-Log to Rec709 3D LUT to it. I'm not sure if it should be fullrange=false or true. I wanted to try both and look at the output visually when I noticed that fullrange=false gave black screen output.

videoh
25th January 2019, 00:10
OK, thanks. As I mentioned, I'll re-port the latest code.

videoh
25th January 2019, 21:24
Rather than upgrade to r2a I ported the fullrange fix only. Here is the revised version:

http://rationalqm.us/hdr/avscube_1.1.rar

Stereodude
26th January 2019, 02:23
Rather than upgrade to r2a I ported the fullrange fix only. Here is the revised version:

http://rationalqm.us/hdr/avscube_1.1.rar
I get an error on both the x86 and x64 versions.

x64:
'C:/HDTV Tools/avscube/x64/vscube.dll' cannot be used as a plugin for AviSynth.

x86:
'C:/HDTV Tools/avscube/x86/vscube.dll' cannot be used as a plugin for AviSynth.

videoh
26th January 2019, 02:42
Hmm, that's strange. I will look into it. This doesn't happen with my version 1.0 DLL? What version of Avisynth+ are you using?