Selur's Little Message Board

Full Version: Method to adjust color temperature?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

Analog

Is there a method of converting between two color temperatures in Hybrid?

I have an NTSC-J (9300k) capture that I'd like to bring inline with the Rec.601/709 (D65/6504k) standard. This is a non-linear conversion so it can't be done with standard RGB adjustments.

Thanks!
Nope, don't know of any Avisynth or Vapoursynth filter for that.

Cu Selur

Analog

(08.03.2021, 05:47)Selur Wrote: [ -> ]Nope, don't know of any Avisynth or Vapoursynth filter for that.

Cu Selur

I was afraid of that... Thanks for the response!

Analog

(08.03.2021, 06:13)Selur Wrote: [ -> ]found a few threads that might give further hints:
http://forum.doom9.org/showthread.php?t=172860
http://www.digitalfaq.com/forum/video-ca...tings.html
https://forum.doom9.org/showthread.php?t=171477
https://forum.doom9.org/showthread.php?t=170309

Cu Selur

Thanks for digging up those threads!

A few of those posts are with regards to the 0-7.5IRE discrepancy which can luckily be corrected using a waveform parade & pedestal/brightness control during capture.

I'm thinking that "CheapColorTemp" script might be my best bet in the AviSynth domain although since its a bit relative & destructive, I might as well use Adobe Premiere to quickly (& arbitrarily) correct it... Without an accurate transfer function, maybe I'll just leave it alone and deal with the slightly blue whites until someone skilled with colorimetry comes along and writes a script to transfer between two known color temps with minimal losses. Smile

Once again, always appreciate your help.
Hi Selur,

Sorry for bumping an old thread.

I discovered a color temperature filter was merged into FFmpeg in Jan. 2021. It takes the input file's recorded color temperature as the parameter and outputs as standard 6500K.

See release msg: https://www.mail-archive.com/ffmpeg-deve...14846.html

Application: "ffmpeg -y -i input9300.mkv -vf colortemperature=temperature=9300 out6500.mkv"

Could this be added to the next release?

Thanks for your help as always!
Not sure if I'll add this since I can't show a preview for it.
OK, thanks for letting me know.

It would certainly be a useful feature for many of us who are capturing Japanese video so if a way to implement it without breaking the preview system would be possible someday, it would be greatly appreciated!

Thanks again!
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:
Code:
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:
Code:
/**
* 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
Send you a link to a dev version which comes with a 'Change Temperature' option.
Let me know whether that works as intended. Smile

Cu Selur
Pages: 1 2