Log in

View Full Version : removing color cast using white point and gray point?


lansing
7th September 2017, 18:33
I want make a function to implement this technique from photoshop, that to remove a color cast, you simply find a white point in the image and adjust the highs for each individual RGB channel curve so they match up. For example, if a white point has a RGB value (227, 200, 180), I want to adjust the highs to rgb(227,227,227). Furthermore, I can set a custom white point like rgb(240,240,240) and have the original adjust to it. This technique is very useful for removing color cast in old anime.

And for removing color cast with just the gray point, you simply find the gray point in the image and select it with gray point eye dropper and then photoshop will adjust the curve for you.

However I have no idea how all these calculation works behind, where do I get start using vapoursynth? Like how do I find a gray point in an image?

poisondeathray
8th September 2017, 14:10
You'd need a pixel sampler wouldn't you? The PS / various other similar programs method - typically use a black, grey and white point but that requires user input . ie. YOU have to make the subjective call what is "black", what is "white", what is "grey" for a given image. If middle grey is supposed to be 128,128,128 , but your pixel sampler reads 138,128,128, the red channel is offset +10. So the red midtone range in the curve is shifted -10 .

But that sounds an lot like a GUI based program to me. VSEdit has a pixel sampler, maybe it's input from mouse hover can be "read" with a hotkey or something?

lansing
8th September 2017, 16:26
Yes I'm thinking on using the pixel sampler from the vsedit, no auto "read" needed, just hover on the spot in the preview and type out the number for input. The function format would be something like this


cast_remover(clip=clip, mode="white" input=[227,200,180], target=[240,240,240])

cast_remover(clip=clip, mode="gray" input=[100,110,120], target=[128,128,128])

cast_remover(clip=clip, show_gray=True, gray_thr = 10)

The first two changes mode, one for removing cast using white point, one using gray point

The last one turns the frame into something that's showing the gray point, and the threshold is use to declare the range that's consider gray in the frame. 10 is like within 10% from rgb(128,128,128).

poisondeathray
8th September 2017, 16:44
But it's more elegant if you can sample the pixel and it automatically enters the value ; because less room for user error (eg. mouse slips, or typo) . Also if you want fast feedback, than change pixel sample, it's a lot faster when you have to go back & forth to redo (sometimes you pick the wrong pixel, or don't like the cc result)

eg. avspmod macro getpixelcolor.py might be "translatable" into vpy function or be able to be integrated into vsedit . In avspmod you can map a hotkey/keyboard shortcut to run the macro and it gives you the value I think in hex, but it should be possible in R,G,B
https://gist.github.com/line0/11328940

kai0n7
11th November 2017, 22:54
I use the script "Gray_Balance" (https://forum.doom9.org/showthread.php?t=167027#post1629321) in avisynth alot for what you're describing, but I don't think there's a vapoursynth equivalent. I think it uses the SmoothAdjust plugin.

Any chance someone can adapt it or do it better?