Convert 3D LUT to hald image

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
Post Reply
Albert25
Posts: 19
Joined: 2010-06-19T03:57:24-07:00
Authentication code: 8675308

Convert 3D LUT to hald image

Post by Albert25 » 2012-11-11T04:01:52-07:00

I have stills extracted from Alexa LOG-C material, and would like to apply a 3D (or 1D) LUT to them. ImageMagick can take a hald image and apply that. But how do I make the hald.png image I want?

I can get various LUT file formats from the Alexa LUT Generator. I don't have any of the proprietary software these LUTs are intended for. Would someone know if any of these tools can export a hald image from the LUT?
  • Adobe After Effects
    Apple Color
    Apple Shake
    Assimilate Scratch
    Autodesk
    Autodesk Lustre
    Blackmagic HD-Link
    Cine-tal
    Codex Digital
    Colorfront
    DaVinci Resolve
    DFT Luther
    Digital Vision Nucoda
    DVS Clipster
    Eyeon Fusion
    Filmlight
    Foundry Nuke
    Iridas
    Pandora
    Pomfort Silverstack
    Quantel
    S.two
    Sony SRW-1
Also, some (most?) of these formats seem to be really text files. Is there a tool that could convert the text format to a hald image?

Thanks.

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Convert 3D LUT to hald image

Post by fmw42 » 2012-11-11T11:55:27-07:00

I have stills extracted from Alexa LOG-C material, and would like to apply a 3D (or 1D) LUT to them. ImageMagick can take a hald image and apply that. But how do I make the hald.png image I want?
create a new Hald image:
convert hald:8 hald.png

see
http://www.imagemagick.org/Usage/color_mods/#hald-clut

Take the hald.png image to some other GUI systems such as PS or GIMP. Process some image the way you want it. Keep track of the steps. Then repeat it exactly on the hald.png image. Then save that with some other name. Bring it back to IM and use -hald-clut to apply it to any image.
Repeat for any other processing with the starting hald.png image.

User avatar
anthony
Posts: 8869
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert 3D LUT to hald image

Post by anthony » 2012-11-20T04:32:51-07:00

The HALD image is straight forward 3d sequence. Just look at a hald: image that ImageMagic generated (any image file format, though not JPeg) and you should be able figure out how to convert your 3D color data cube into a HALD image.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
http://www.imagemagick.org/Usage/

Albert25
Posts: 19
Joined: 2010-06-19T03:57:24-07:00
Authentication code: 8675308

Re: Convert 3D LUT to hald image

Post by Albert25 » 2012-11-20T08:07:20-07:00

Maybe I could convert the hald image to a text representation of RGB values of each pixel? (Can IM do that? Some other tool?) So I could get the hald image in text form, modify the values using my LUT, and convert back to a hald-with-lut.png image?

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Convert 3D LUT to hald image

Post by fmw42 » 2012-11-20T11:05:18-07:00

What tools do you have to process images with your existing LUTs? Can you use them in GIMP or PS or any other tool to apply to an image? If so, use your 3D lut to modify the HALD 3D lut in that tool. Then bring back to IM?

What is the format of your lut? Is it an image or just text? Can you provide an example?

You can write out any image, including the 3D hald lut to txt format. See http://www.imagemagick.org/Usage/files/#txt or use one of the NetPBM ASCII based image formats.

I think we really need to know more about your luts!

Albert25
Posts: 19
Joined: 2010-06-19T03:57:24-07:00
Authentication code: 8675308

Re: Convert 3D LUT to hald image

Post by Albert25 » 2012-11-20T15:47:09-07:00

fmw42 wrote:What tools do you have to process images with your existing LUTs?
None. That is my problem. As far as I know, GIMP cannot import a text LUT and apply it to an image. (Or can it?)
fmw42 wrote:What is the format of your lut? Is it an image or just text?
Text files in various formats. For example "After Effects" .cube (listing 32768 (32^3) points):

Code: Select all

# Alexa conversion LUT, logc2video, itu709. Full in/legal out.
# created by alexalutconv (2.07)

LUT_3D_SIZE 32
0.062561 0.062561 0.062561
0.062561 0.062561 0.062561
0.065555 0.062561 0.062583
[...]
0.915093 0.918866 0.918839
0.917384 0.918866 0.918856
0.918866 0.918866 0.918866
0.918866 0.918866 0.918866
Or less fine-grained "Scratch" .3dl (listing 4913 (17^3) points):

Code: Select all

# created by alexalutconv (2.07)
# Alexa conversion LUT, logc2video, itu709. Full in/legal out.
0 64 128 192 256 320 384 448 512 576 640 704 768 832 896 960 1023
256 256 256
256 256 262
256 256 391
[...]
3760 3760 3740
3760 3760 3756
3760 3760 3760
fmw42 wrote:You can write out any image, including the 3D hald lut to txt format. See http://www.imagemagick.org/Usage/files/#txt
That sounds promising. I wasn't aware that IM could do that. Thank you.

I have now a 230 MB txt file of my 1727x1727 hald.png.

Now I "just" have to figure out how to convert each of these points with my 3D LUT, or how to correctly interpret and interpolate values for the new hald-with-lut.png pixels. When I find the right mathematics for that, applying it will just be a few lines of Perl...

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Convert 3D LUT to hald image

Post by fmw42 » 2012-11-20T17:26:41-07:00

I think you need to understand what the text lut format is and what is is doing? Is there any documentation? Perhaps if we understood more about these text luts we could help further. But right now they are very unintelligible. How are they normally applied --- what software or hardware?

Albert25
Posts: 19
Joined: 2010-06-19T03:57:24-07:00
Authentication code: 8675308

Re: Convert 3D LUT to hald image

Post by Albert25 » 2012-11-20T17:54:18-07:00

I do understand what the 1D and 3D LUTs do. The Wikipedia page is a good start. But that page then leads to trilinear interpolation, which seems to be mathematics quite beyond the level I left school with (or maybe not, but I should have listened more carefully instead of concentrating on the girls...).

(This page explains the basics nicely: http://www.lightillusion.com/luts.html . And this looks promising for the mathematics part: http://stackoverflow.com/a/1641529/111036 )

User avatar
fmw42
Posts: 22101
Joined: 2007-07-02T17:14:51-07:00
Location: Sunnyvale, California, USA

Re: Convert 3D LUT to hald image

Post by fmw42 » 2012-11-20T18:28:49-07:00

The 3x 1D lut format is just like an IM 1D image with 3 color channels. It can be converted from text into an image by using NetPBM format. At a minimum, you can create 3 1D grayscale images and use -combine to make it an RGB image. Then use -clut to apply the lut. You just need to provide the string of red values to create PGM image. Do that for each channel. Then use -combine. There may also be a more direct conversion to one of the other PBM formats.

see
http://www.imagemagick.org/Usage/color_mods/#color_lut
http://www.imagemagick.org/Usage/color_mods/#clut
http://www.imagemagick.org/Usage/color_mods/#fx_to_lut

see
http://www.imagemagick.org/Usage/formats/#pbmplus
http://netpbm.sourceforge.net/

Your 3D lut may be very similar to the HALD 3D image format. You just need to convert it to the right format. See
http://www.imagemagick.org/Usage/color_mods/#hald-clut. I do not know exactly the function that creates it, but Anthony made a very simple similar type image at http://www.imagemagick.org/Usage/quantize/#332_colormap. Any way the best resource is the hald page at http://www.quelsolaar.com/technology/clut.html


In either case you can set the interpolation to many modes using -interpolate. see
http://www.imagemagick.org/script/comma ... nterpolate


What you have not explained is how you normally apply those luts. There must be some software to apply them to an image. If so, use that software to apply the 3D lut to a Hald 3D image. That converts your lut into one that can be used directly by IM.

snibgo
Posts: 9399
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert 3D LUT to hald image

Post by snibgo » 2012-11-21T07:35:51-07:00

Albert25 wrote:As far as I know, GIMP cannot import a text LUT and apply it to an image. (Or can it?)
Yes, it can. I do it all the time, though only with 3 x 1D LUT generated by external software in the PPM text format, then applying the LUT with IM's "-clut" operator.

I generally only care about one dimension at a time, generally luminence, although I use the same technique for some colour corrections using a 3-channel LUT.

A 3D hald LUT uses 3 values to look up an entry in the table, and gets three values out. If the examples you have seen have all three values monotonically increasing, they may be equivalent to IM's CLUT files, and thus trivial to convert.

(Linear interpolation is used when the input value falls between two entries in a 1D table. Bilinear interpolation is for 2D tables, and trilinear for 3D.)
snibgo's IM pages: im.snibgo.com

wlange
Posts: 8
Joined: 2016-11-29T10:24:23-07:00
Authentication code: 1151

Re: Convert 3D LUT to hald image

Post by wlange » 2016-11-29T10:41:04-07:00

Hello,

I'd like to repeat the question in the original request:

Is there a tool that could convert the text format to a hald image? (not in Photoshop or GIMP, but via command line!)

What I'd like to achieve is: apply an existing 3D LUT (.3dl or .cube text format) to an identity hald image generated by ImageMagick, to then be able to apply that to a given image using convert. Again, without using Photoshop or GIMP to generate a hald with the LUT in question applied.

Thanks a lot!
Programmers often think, they have invented the theory of everything. In fact they usually have just incorrectly solved a tiny subproblem.

snibgo
Posts: 9399
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert 3D LUT to hald image

Post by snibgo » 2016-11-29T11:12:29-07:00

wlange wrote:Is there a tool that could convert the text format to a hald image?
Not as far as I know. IM's hald format is well documented (in the code). If the .cube or .3dl format is also documented, then writing a script or C program for the conversion wouldn't be difficult.
snibgo's IM pages: im.snibgo.com

wlange
Posts: 8
Joined: 2016-11-29T10:24:23-07:00
Authentication code: 1151

Re: Convert 3D LUT to hald image

Post by wlange » 2016-11-29T12:25:52-07:00

Shouldn't it be supported by ImageMagick directly? I mean, it makes perfect sense, doesn't it?

Can you (or s.o. else) provide some an example that shows how to do it?

Thanks for your help.
Programmers often think, they have invented the theory of everything. In fact they usually have just incorrectly solved a tiny subproblem.

snibgo
Posts: 9399
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert 3D LUT to hald image

Post by snibgo » 2016-11-29T13:00:51-07:00

There are probably any number of formats for 3D LUT files, with no common interchange format. The CIF could be simple: many records, each with 6 numbers, representing input RGB and output RGB. This would be like the IM TXT: format, but with (R,G,B) coordinates instead of (X,Y) coordinates.
snibgo's IM pages: im.snibgo.com

wlange
Posts: 8
Joined: 2016-11-29T10:24:23-07:00
Authentication code: 1151

Re: Convert 3D LUT to hald image

Post by wlange » 2016-11-29T13:14:50-07:00

I see. The most common ones seem to be Autodesk .3dl and Adobe .cube. If these don't differ in themselves, that might be a good start.

I'm not an expert in this field. But if ImageMagick was able to utilize most common standards, it might help some folks. Just my $0,02.
Programmers often think, they have invented the theory of everything. In fact they usually have just incorrectly solved a tiny subproblem.

Post Reply