Log in

View Full Version : Colorcorrection in red only


Inc
29th March 2004, 14:21
Hi!

Very often in YUY2 captures/mjpeg I still got some "red" clipping, means red coats of women for example seem to be a bit too red and also the faces, they don't come out that natural color balanced (a bit too orange).

So, which filter/command should I use to get the same effect like when using Photoshops Gradations Curves on high values on the RED channel only (just to explain my purpose). Would ColorYUV() be my choice ... but as it doesn't handle "red" separately but U and V, Im still a bit lost.

Thanks in advance! :)
Inc.

Wilbert
29th March 2004, 14:45
Did you try RGBAdjust?

Inc
29th March 2004, 15:03
Ahhh! :cool:
RGBAdjust(clip clip, float red, float green, float blue, float alpha)

Means:


Levels(0, 1, 255, 0, 128).RGBAdjust(1, 2, 2, 1)


Quoted from avisynth.org but modified to LOWER the red instead of doubling. Do I see that right?

Mug Funky
29th March 2004, 15:07
RGBadjust would work much better if you dropped the levels command

RGBadjust(.5,1,1,0) will give the same result without losing 1 bit of precision

[edit]
by the way... isn't there something you can adjust during capture that will allow these reds to not be clipped? usually oversaturated colours come from decoders converting the colour range from ccir-601 to PC, and clipping off any values outside these ranges. most DV cameras i've used actually record outside the CCIR-601 range, so i have to use a codec that decompresses the full range. it may be similar with your capture card/choice of mjpg codec.

Inc
29th March 2004, 15:12
Thanks!

Makes sense as values are float

Well I do capture in YUY2 mjpeg via PicVideo Codec using a 7134 philips card and the cinergy 1.4 driver via Vdub or VirtualPC. The Device settings I do leave untouched as many broadcastings do come different and so I do not tweak the Contrast/Colors etc. as pre settings in the devixe settings.

The thing is, that the pic is not generally oversaturated but a bit in red areas. If you would see a sample (im at work right now) you would say,"WHAT, man be happy with your captures" but as I like to tweak where I can and where it makes sense, ... so I try it and watch the result.

trevlac
29th March 2004, 15:48
Originally posted by incredible

So, which filter/command should I use to get the same effect like when using Photoshops Gradations Curves on high values on the RED channel only (just to explain my purpose).

I believe you want to adjust the red saturation, only for the high values if possible.

RGBAdjust is a good option because it pulls down the red in a way (multiplication) that reduces the high range more than the low. For example, 10Red * .95 = 9.5Red and 255Red * .95 = 242Red. This will also reduce the overall luma a bit, and change the colors. For example, yellows will darken and become more green. This may not be too bad for a Red number close to 1 RGBAdjust(.97, 1, 1, 1).

Below are some other options. I'm afraid none are perfect.

Graft has a vdub 'hue/sat/intensity' filter that lets you easily adjust individual channels. This should be basically the same as RGBAdjust, so you could play with it under preview to see what different values give you. Pick only red and pull down the saturation. To get rid of the orange, you can also adjust the red hue just a tad towards magenta. Unfortunately, I have not found a good way to only effect certain ranges of values (like high/mid/low). Emiliano Ferrari has a vdub 'colorbalance' filter that allows access to certain ranges, but it does not allow access to seperate channels. Also, he does not provide source, so I'm not sure what the filter really adjusts. You'd have to test. Buggs Bunny created a VDub 'Gradation Curves' filter a few months ago (search the vdub forum). I would have brought this up 1st, but personally, I can't get it to really work. You need to save a Photoshop curves file and then import it into the filter. I havn't tried too hard, but I can't get the correct type of photoshop file.


PS:

To adjust just Red, you must use an RGB filter. Although RGBAdjust doc says it accepts YUY2, either this is not true, or it internally converts to RGB and then back.

Mug Funky
29th March 2004, 15:53
hmm. a lookup table filter for avisynth would be very cool indeed.

i believe manao included YV12LUT in masktools. i haven't played with it yet.

an RGB version would be cool (even better one that could read photoshop curves files, which after all are just a bunch of 8 bit numbers)

trevlac
29th March 2004, 16:00
Originally posted by Mug Funky
usually oversaturated colours come from decoders converting the colour range from ccir-601 to PC, and clipping off any values outside these ranges.

This should only happen if you are converting from YUY2 to RGB. Some times it is impossible to avoid this, like if you are using TMPGEnc.

Personally I see this over saturated red from DishNetwork DVB. It really becomes more appearent on a TV because TVs tend to lean towards red. (I guess that's because the general public likes rosey cheeks and red tans ;)

scharfis_brain
30th March 2004, 00:12
@incredible:
you should really, really tweak your contrast/brightness/saturation-settings before capturing using the histogram builtin in VDub.
I always do my VHS-Caps with slight too low saturation and well defined contrast/brightness settings filling up the whole histogram without touching its borders. this gives the perfect lumarange without loosing precision and without oversaturating white nor black.

trevlac
30th March 2004, 14:34
Originally posted by scharfis_brain
you should really, really tweak your contrast/brightness/saturation-settings before capturing using the histogram builtin in VDub.
..... this gives the perfect luma range without loosing precision

On my BT878a the settings take effect after the signal is digitized. To me, this means the BT is doing the same thing as I would do in post, but with less control on my part. Am I wrong in my understanding?


PS: Maybe a 10 bit card would do the adjustments in 10 bits, before it output 8.

scharfis_brain
30th March 2004, 15:16
I do not know the bt-interna, but do you have a source (link) to prove your statement?

even with high overcontrastening I do not have gaps in my histogram....
so I assume, the bt is correcting the video amplitude (contrast) and offset (brightness) on the analogue side before digitizing ?!?

is Bt 8bit or 9bit?
if it is 9bit, even leveling after digitizing (into the bt) within the capturing would be better than leveling within avisynth afterwards.

Arachnotron
30th March 2004, 16:09
even with high overcontrastening I do not have gaps in my histogram....
so I assume, the bt is correcting the video amplitude (contrast) and offset (brightness) on the analogue side before digitizing ?!?

There is a third option:
The BT878 (and any other cap device I suspect) starts out by digitizing the analogue signal. That would mean the raw 8 bit VBI data (BT878 has a 8 bit ADC, that is in the datasheet) includes the whole range from Hsync (-40 IRE) to peak white + chroma (130 IRE ???) and stuff like colorburst etc. assuming a composite signal.

There actually exist programs for the BT and the SAA713x chips that let you plot this raw data. I'll try to hunt down the link again, I posted it before in this forum.

From this data the card proceeds to calculate/interpolate/combfilter/whatever :) the YUV data needed for the pixels, and maps the YUV data in an 8 bit CCIR compliant range.

The crucial question is at which step the brightness adjustment takes place: during this step, or afterwards on the final YUV data.

If during, I would expect the histo to be continuous and perhaps (though cannot prove this) the result to be more accurate
If afterwards, I would expect the histo to have gaps, and I would expect better results with more control doing this post.

For SAA71xx(9 bit ADC), CX2388x(10 bits ADC) and ATI Theater 200 (12 bit ADC?) I would expect the hardware to do a better job (though the 9 bits SAA71xx is borderline I expect)

[edit] found the link back for the VBI viewer.
http://tuner.ixbt.com/soft/soft_tv_test_001.html
[edit2] the term raw 8 bit VBI data is perhaps not so fortunate. Better perhaps is raw 8 bit voltage data.

trevlac
30th March 2004, 16:21
@scharfis

I'm really asking what you think. I think it is a good point that you see no gaps in the histo. I will have to do an RGB cap and see if there are any gaps in an RGB histo after contrast adjustment.

My comments are based upon reading the BT data sheet ...

http://www.conexant.com/servlets/DownloadServlet/100119a.pdf?FileId=542

The diagram on page 3 clearly shows the signal is digitized before any gain/brightness type adjustments takes place. The doc is also sprinkled with statements like:

"This bit controls the Chroma AGC function. When enabled, Chroma AGC will compensate for non-standard chroma levels. The compensation is achieved by multiplying the incoming chroma signal by a value in the range of 0.5 to 2.0."

This really sounds like digital.

Also, it is my understanding that the BT is 8 bit all the way thru. I'm not sure of a source to tell me that.


So ... in the end, I prefer post because it is easy to see the whole video and take your time if you want. But I have been assuming that the card gave no advantage.

trevlac
30th March 2004, 17:03
@Arachno,

VBI stuff Page 35.

The number of DWORDs of VBI data is selected by the user. Each DWORD contains 4 VBI bytes, and each VBI pixel consists of two VBI samples. For example, for a given 800 pixel line in the VBI region, there exist 1600 VBI samples, which are equivalent to 400 DWORDs of VBI data.


I read this as DWORDs = 32 bits, samples = 8 bits, pixels = 16 bits. But ... do the 16 bits contain 8 luma and 8 color? Don't know.

It may be that there are no gaps in the histo because you start with 922 PAL pixels. The gain may be applied here and then when you scale to say 768, the averaging smooths the histo back out.

--------------
In the end ... I find being able to look at a Waveform monitor in post a more precise process (vs a pre-cap histogram). But I would have to say that the cards adjustments have more data to work with.


BTW: I'm a bit of a novice and consider other peoples practical experience very enlightening. :)

Arachnotron
30th March 2004, 17:23
I read this as DWORDs = 32 bits, samples = 8 bits, pixels = 16 bits. But ... do the 16 bits contain 8 luma and 8 color? Don't know.

You probably missed the last edit in my post. I was a bit careless in using the term VBI. :) VBI seems to have become synonymous for raw data, while it actually only describes a small part of the complete frame. Your quote seems to be about decoding true VBI data, i.e. things like teletext.

What I mean is that the initial raw 8 bit cap contains samples describing the complete waveform, and that those first have to be decoded to YUV values and pixels. The figure on page 3 indicates the same to me. First Y/C separation and chroma demodulation, brightness and colour adjust next and the scalers last. I Assume this last step is also the point where the actual mapping to pixels takes place. AGC is directly coupled with a feedback loop to the raw ADC output, I assume using Hsync as level reference and switching of during the active part of a line. At this stage there is no separate chroma value yet, so I again assume the chroma AGC is part of the adjustment block, and not a true AGC in amplifying the incoming signal.

I have found from other HW manuals you have to be carefull with taking these diagrams to far though, since they sometimes put things in separate blocks for clarity that are part of the same dsp filter or leave steps out.

mf
30th March 2004, 19:04
input = last
redmask = input.VToY().Levels(128, 1, 255, 0, 255).LanczosResize(input.width, input.height)
grey = input.Greyscale()
Overlay(input, grey, mask=redmask)


Doesn't that do what you want? (In exaggerated form of course, if you want a more slight desaturation use Tweak() instead of Greyscale() to not make "grey" completely greyscale)

trevlac
14th April 2004, 15:12
I wanted to say, mf's approach is very creative. It isolates positive V values and then reduces them. (Unlike Tweak and ColorYUV, which reduce all of V or all of V&U). You can even target high red by adjusting the levels parms, and not really effect magenta.

But honestly, figuring out how to do this is a bit of a pain.

Prompted by this, and my own problem of oversaturated reds, I used Tweak as a starting point and made a plugin with the added ability to target a specifice hue range and/or a specific saturation range. This is all done in the YUV colorspace.

For example, on unscaled U&V, exact red is at 109 degrees. To cover the a range from one of the 6 primary and complimentary colors, go out +/- 30 degrees. So 'red' hue goes from about 140 to 80 degrees. YUV can go beyond then nominal range of 16-240. 0-255 actually covers a 113.5% range. Anything above 75% red is probably too high. So target red from 115% to 75% and reduce its saturation from 1.00 to 0.75.

This is the syntax to do the above and reduce the saturation of red highs.

TweakColor(sat=0.75,startHue=80,endHue=140,maxSat=115,minSat=75)


Here is the thread with the plugin link

http://forum.doom9.org/showthread.php?s=&threadid=74334