Search code examples
mathgraphicsdatatablecolors

Ideas on generating 3D LUTs programmatically?


I'm trying to figure out, how to build .3d, .cube or .mga files, which contain look up table data for color correction (e.g. Adobe Lightroom, Davinci Resolve etc.), programmatically. I can't find any hints on how a .cube file is written, structured and/or compiled or which language to use (glsl, c++, python ?). Maybe some of you guys have an idea on how to approach this topic?


Solution

  • Use python colour science module. i am try to convert sip1d lut file in cube lut file simple way and use lut file in pillow and pillow_lut module.you can apply 3dlut in image

    import colour
    from pillow_lut import load_cube_file
    from PIL import Image
    
    def convertlut(Inputlutfile:str,outputlutfile:str):
        #read lut file in color modurl
        lut1d = colour.read_LUT(Inputlutfile)
        #Convert 3x1D to LUT3D
        lut3d = colour.io.LUT_to_LUT(lut1d, colour.LUT3D,
        force_conversion=True)
        # Write the cube lut file
        colour.write_LUT(Lut3d, outputlutfile) 
    
    if __name__ == '__main__':
        convertlut("cgc_luts\luts\ACEScc_to_linear.spi1d","output3dlut.cube")
        #load lut file
        lut = load_cube_file("output3dlut.cube")
        #open image file 
        im = Image.open("image.png")
        #apply lut object in image and save image
        im.filter(lut).save("image-with-lut-applied.png")
    

    i hope this helps. fix your problem