This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

Method to adjust color temperature?
#9
I posted over at doom9, but so far no real solution was found.
One idea there was to open the source with ffmpeg and pipe into vsrawsource, but that would not allow jumping inside the preview and is rather complicated to integrate into Hybrid.

I also found this, which uses OpenCV and using:
import cv2
import muvsfunc_numpy as mufnp
import numpy as np
from PIL import Image

kelvin_table = {
    1000: (255,56,0),
    1500: (255,109,0),
    2000: (255,137,18),
    2500: (255,161,72),
    3000: (255,180,107),
    3500: (255,196,137),
    4000: (255,209,163),
    4500: (255,219,186),
    5000: (255,228,206),
    5500: (255,236,224),
    6000: (255,243,239),
    6500: (255,249,253),
    7000: (245,243,255),
    7500: (235,238,255),
    8000: (227,233,255),
    8500: (220,229,255),
    9000: (214,225,255),
    9500: (208,222,255),
    10000: (204,219,255)}

def numpy2pil(np_array: np.ndarray) -> Image:
    """
    Convert an HxWx3 numpy array into an RGB Image
    """

    assert_msg = 'Input shall be a HxWx3 ndarray'
    assert isinstance(np_array, np.ndarray), assert_msg
    assert len(np_array.shape) == 3, assert_msg
    assert np_array.shape[2] == 3, assert_msg

    img = Image.fromarray(np_array, 'RGB')
    return img

def pil2numpy(img: Image = None) -> np.ndarray:
    """
    Convert an HxW pixels RGB Image into an HxWx3 numpy ndarray
    """
    np_array = np.asarray(img)
    return np_array

def convert_temp(image, temp):
    r, g, b = kelvin_table[temp]
    matrix = ( r / 255.0, 0.0, 0.0, 0.0,
               0.0, g / 255.0, 0.0, 0.0,
               0.0, 0.0, b / 255.0, 0.0 )
    img = numpy2pil(image)
    return  pil2numpy(img.convert('RGB', matrix))

range = "full"
if core.text.FrameProps(clip,'_ColorRange'):
  range = "limited"

clip = core.resize.Bicubic(clip=clip, format=vs.RGB24, range_s=range)
clip = mufnp.numpy_process(clip, convert_temp, temp=6500, input_per_plane=False, output_per_plane=False)
it seems to work, but the problem with that is:
a. Hybrid atm. only supports this when the torch-Addon is used.
b. I'm not really sure how 'good' this is.
Instead of using the kelvin_table one could probably use something similar to: https://academo.org/demos/colour-tempera...ationship/ which uses:
/**
* http://www.tannerhelland.com/4435/convert-temperature-rgb-algorithm-code/
* */
function KToRGB(Temperature){

    Temperature = Temperature / 100;

    if (Temperature <= 66){
        Red = 255;
    } else {
        Red = Temperature - 60;
        Red = 329.698727466 * Math.pow(Red, -0.1332047592);
        if (Red < 0){
            Red = 0;
        }
        if (Red > 255){
            Red = 255;
        }
    }

    if (Temperature <= 66){
        Green = Temperature;
        Green = 99.4708025861 * Math.log(Green) - 161.1195681661;
        if (Green < 0 ) {
            Green = 0;
        }
        if (Green > 255) {
            Green = 255;
        }
    } else {
        Green = Temperature - 60;
        Green = 288.1221695283 * Math.pow(Green, -0.0755148492);
        if (Green < 0 ) {
            Green = 0;
        }
        if (Green > 255) {
            Green = 255;
        }
    }

    if (Temperature >= 66){
        Blue = 255;
    } else {
        if (Temperature <= 19){
            Blue = 0;
        } else {
            Blue = Temperature - 10;
            Blue = 138.5177312231 * Math.log(Blue) - 305.0447927307;
            if (Blue < 0){
                Blue = 0;
            }
            if (Blue > 255){
                Blue = 255;
            }
        }
    }

    rgb = new Array(Math.round(Red),Math.round(Green),Math.round(Blue));
    return rgb;

}

=> there is still hope Smile

Cu Selur
------
offline 02.-07. July, https://www.rockharz-festival.com/ Big Grin
Reply


Messages In This Thread
Method to adjust color temperature? - by Analog - 08.03.2021, 05:41
RE: Method to adjust color temperature? - by Analog - 08.03.2021, 05:50
RE: Method to adjust color temperature? - by Analog - 08.03.2021, 07:44
RE: Method to adjust color temperature? - by Selur - 13.11.2023, 19:02

Forum Jump:


Users browsing this thread: 1 Guest(s)