ilia3101 / MLV-App

All in one MLV processing app.
https://mlv.app/
GNU General Public License v3.0
283 stars 29 forks source link

LUT support #50

Closed masc4ii closed 6 years ago

masc4ii commented 6 years ago

Just a reminder: It woud be nice to have a 1D & 3D LUT support. How to read .cube files can be found in the Inet easily. But to apply the LUT there is some math to implement...

bouncyball-git commented 6 years ago

I think we should take a look at DreamWoks's OpenColorIO. If we implement it, there will be all possibilities to do all kind of fancy stuff with luts too.

masc4ii commented 6 years ago

I was playing around a bit and think I could need your help @bouncyball-git , because I think you are good in file reading! In the file lut.c there is now the file scanning of a cube file. But it now works only for the numbers in such a file:

0 0 0
0.0375219 0 0
0.140475 0 0
0.246708 0 0
0.355093 0 0
0.462974 0 0
...

Normaly such a file has a header like this:

TITLE "Generate by Resolve"
LUT_3D_SIZE 33
0 0 0
0.0375219 0 0
0.140475 0 0
0.246708 0 0
0.355093 0 0
0.462974 0 0
0.568292 0 0
...

Could you please help in scanning the dimension (LUT_3D_SIZE) and ignoring all other lines?

If you want it to work, adapt the lines 507+ in raw_processing.c. You also must delete the header of the selected cube file, else you gonna have a black image. 😄

Next, between the LUT points we need a interpolation. A LUT with a size of 33 brings without interpolation 33 colors per channel (very ugly) 😄

bouncyball-git commented 6 years ago

Ok I think @ the evening I will have some time. I'll take a look.

bouncyball-git commented 6 years ago

Maybe first we should try to implement just a simple 1D Lut support?

masc4ii commented 6 years ago

Hehe, we could do the as second... 3D is mostly working already 😄 I'll do another commit this evening. The only thing what does not work yet is parsing the lut header with its keywords (dimension has to be entered in the code and cube header has to be deleted in the cube file). And maybe my interpolation is not good enough - sometimes there are some nice rainbow artefacts on the pictures 😆 I did a 3x 1d linear interpolation - maybe that is to simple (or I am doing something wrong).

Edit: we'll need 3x triliniear interpolation 😝 https://spie.org/samples/PM159.pdf

Edit2: oh no... trilinear interpolation is more ugly than linear... and now I found in the CubeLUT spec: "The reader should use linear interpolation for one dimensional tables, and tetrahedral interpolation for three dimensional tables." 😛

bouncyball-git commented 6 years ago

Yeah I remember that tetrahedral interpolation thingy from 3DLut Creator :)

masc4ii commented 6 years ago

You know this tetrahedral interpolation? Do you know how that works, or better, do you have some code? I only found that this method is existing, but nothing more... 😢

I commited a version, where LUT is selectable via GUI now. You only must enter in lut3d.c; load_lut3d(), line uint16_t dimension = 33; to the right size, delete the header from your test lut and have fun. In line 140 you can switch between linear interpolation and trilinear interpolation. First is not good enough, it is ugly. Second seems not to work right, it is very very ugly. 😄 (see the saw tooth in the histogram... ulàlà)

bildschirmfoto 2018-06-08 um 19 26 58 (Linear interpolation, FilmLUT)

bildschirmfoto 2018-06-08 um 19 24 56 (Trilinear interpolation, FilmLUT)

masc4ii commented 6 years ago

Yay... fixed my trilinear interpolation! Looks perfect now. But fps without LUT : with LUT = 2:1 😮 Seems to be very CPU consuming... bildschirmfoto 2018-06-08 um 20 37 47

bouncyball-git commented 6 years ago

Haha that introduced banding was so nice :)

I'm not familiar with tetrahedral interpolation. I just remember that 3dlut creators once updated to support it :)

I've done some changes to 3dlut.c (header parsing) but it's not finished yet. Could we name the file cube.c/cube.h? because it will be just cube 1d/3d lut lib.

masc4ii commented 6 years ago

👍 Can't await your changes! I renamed it to cube_lut.c/.h (who knows what further kinds of cubes there are in image processing 😄 ).

bouncyball-git commented 6 years ago

Sorry, I'm out of the city, will try to finish it tomorrow at the evening.

masc4ii commented 6 years ago

Take your time and enjoy the weekend!

bouncyball-git commented 6 years ago

Added full spec cube parser according to the official PDF.

Here is a PDF and 3 cube samples to test Link

For now all debug messages are printed to the console.

Enjoy :-D

masc4ii commented 6 years ago

Wow, thanks! Will try! 😄

masc4ii commented 6 years ago

So cool! That works really good for me! 👍

bouncyball-git commented 6 years ago

Yay! I'm glad to hear that! :)

bouncyball-git commented 6 years ago

The func returns 0 on success and -1,-2,-3 on errors. You can make use of it.

bouncyball-git commented 6 years ago

@masc4ii BTW very good job with interpolation and applying the LUT!!! Thank you! 😃

masc4ii commented 6 years ago

Tetrahedral Interpolation is working now! I made a define into cube_lut.c where you can switch between the Tetrahedral and Trilinear Interpolation. At least on my Core2Duo the speed is the same (but I don't understand why, because Tetrahedral Interpolation has nearly around factor 10 less operations).

masc4ii commented 6 years ago

I am impressed by the Ektar100 LUTs from ML Forum! Look at this: bildschirmfoto 2018-06-12 um 18 58 16 1st pic: No LUT, nearly all sliders were used to get the picture as it is.

bildschirmfoto 2018-06-12 um 18 59 47 2nd pic: Ektar100 LUT used, Curve was set to "Alexa Log-C", only WB sliders were used. Both pictures are very close... or not?!

bouncyball-git commented 6 years ago

Sky looks a little bit different.

You wrote the tetrahedral interpolation yourself?!!! Cool! You are good @ Math!

masc4ii commented 6 years ago

You wrote the tetrahedral interpolation yourself?!!! Cool! You are good @ Math!

Thanks for the flowers... but not really. I just typed what was written in this pdf document posted above... and I wondered myself that it was working out of the box 😄 So... more luck then knowledge 😄