View Full Version : YCrCb to Linear 32bit RGB
diffid
19th October 2009, 11:47
I'm trying to adopt a linear workflow for 3D rendering and compositing, including using HDV, DV video as source material. I have to convert video sources to RGB. Export as .png image sequence, then reverse gamma to use.
I'd like to simplify the process.
Is it possible to go from YCrCb to Linear 32bit RGB in one AVISynth script?
I'm currently using PC.601 and PC.709 for the conversion to keep the under and over brights.
I know that a 2.2 gamma curve is baked into my video but I switch off all post processing in the camera to get as neutral a image as possible, I can't afford a RED. :-)
Is YLevels a tool for this?
As .png's can store a gamma field in the header, would AVISynth save with gamma 1.0 in that field?
Can I export the image files as 16 or 32bit. If so is there a way to interpret the 8bit data into 16bit to take out the gaps in the histogram, sorry I don't know the technical terms for this. :-) Currently i use imagemagick or pfsin for this.
I'd prefer to use OpenEXR but that is not an image seq option out of VirtualDub, does anyone know of a .dll for perhaps AVISynths image writer to .exr?
Sagekilla
19th October 2009, 17:58
Short answer: Yes you can save as linear pngs. Use Levels() with the gamma parameter to do 2.2 -> 1.0 conversion.
Long answer: No, you can't do it nicely at the moment. You can output linearized RGB, but you're going to suffer from the low precision. If you calculate the output values over the range of [0, 255], or [16, 235] technically, you'll get something like:
0 -> 0
1 -> 1
2 -> 1.37 -> 1
3 -> 1.64 -> 2
4 -> 1.87 -> 2
5 -> 2.07 -> 2
...
I'm assuming you'd like 32-bits per pixel, which avisynth has NO support for. The only solution is to write your own plugin that does YCbCr -> 32-bit R'G'B' -> 32-bit RGB -> write to file as png.
YCbCr -> 32-bit R'G'B' is a trivial operation you can look up. Likewise, the conversion to linear gamma is easy. I believe you should be able to write as png very easily, since the DevIL library is used in avisynth for png (among other things) support, and should handle 32-bit output.
diffid
19th October 2009, 23:17
Sagekilla thanks for the response, I'm no coder however I'll have a go at it.
Checked out the DevIL libraries, I have no MSVC++, so would need to use an express version, or mingw or another free compiler. What do you guys use?
And have to check out AVISynths plugins code? Are there some sort of templates to work from?
Finally I notice DevIL can also write to exr. :-)
However if there happened to be a experienced AVISynth coder interested don't mind me I may be some time, if at all. :-)
davidhorman
20th October 2009, 01:44
Take a look here if you want to try writing plugins:
Filter SDK/Compiling instructions (http://avisynth.org/mediawiki/Filter_SDK/Compiling_instructions#How_to_create_new_plugin_from_scratch_with_MS_VC.2B.2B_2005)
Other pages in the wiki say you need things like the Microsoft Platform SDK, but all I had to download was VC++ 2008 Express (the instructions work just as well on the new version).
Then take a look at simple sample (http://avisynth.org/mediawiki/Filter_SDK/Simple_sample). I still don't understand all this ++ stuff - classes and so on - but the simple_samples should show you how to manipulate RGB and YV12 video.
Conversion to linear gamma - this is raising Y to the power of 2.2? Or 1/2.2? It so happens I'm just doing some RGB<>YUV conversion for a filter of my own...
David
Sagekilla
20th October 2009, 16:25
You'll want to do:
1) YCbCr -> R'G'B' (32-bits per component)
2) R'G'B' -> RGB (R = R' ^ (1.0 / 2.2), etc)
3) Write the image
You may want to represent each pixel component as a double for maximum precision retained.
diffid
22nd October 2009, 23:02
Just wanted to say, thanks for input guys, I'm still looking at it. :-)
yesgrey
24th October 2009, 16:46
Is it possible to go from YCrCb to Linear 32bit RGB in one AVISynth script?
No, you can't do it nicely at the moment. You can output linearized RGB, but you're going to suffer from the low precision.
I agree with Sagekilla that you cannot do it nicelly, but you can try this method and see if it would be good enough for you.
You can create a 16bit output 3DLUT file with cr3dlut to convert from Y'CbCr to RGB linear, just by creating a custom linear curve for the output. Then, you could use that 3DLUT file with tritical's t3dlut filter, which will dither the 16bit output of the 3DLUT file to 8bit.
If you need help with creating the 3DLUT file, let me know.;)
diffid
26th October 2009, 14:43
I've spent some time looking at this following a video/composite project I just finished, but I've made no progress. :-(
Problem is I now have another project come in and no time to spend on this. I was hoping to try this out on the new project :-(
If this is a simple plugin to write, is there anyone who would take it on, would such a plugin be useful to anyone else in the community here to use. :-(
I'm trying to get my head round the process.
Do I:
Load a HD YCrCb video (YV12) into AVISynth with AVISource to decode the video file.
Then get Devil via the plugin I need to write, to read the pixel info and do all the processing from there on, then write the 32bit full float .exr images out + a .jpg at 50% to a seperate folder as a video proxy file for realtime playback.
I'm lost, need to read more to solve it myself, but no time for another week or more. :-(
Usual story for us all I know.
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.