View Full Version : How to adjust RGB saturation?
fccHandler
31st December 2004, 04:04
I seem to have run into a brick wall here. I want to adjust the saturation of an RGB clip to 83% in Avisynth, and there doesn't seem to be any way to do it without converting to YUY2. I prefer not to do that because I'm trying to fit Avisynth into a larger processing chain and I don't want to downsample the chroma information at this stage in the chain. (It's a long story...)
The documentation mentions a function called "HSIAdjust" which existed in earlier versions, but was removed in favor of a newer "Tweak" function which only supports YUV. Did the "HSIAdjust" function support RGB? And if so, which was the last version of Avisynth to include it?
Is there any other way (besides Tweak) to adjust saturation in Avisynth, and keep the full RGB image?
ObiKenobi
31st December 2004, 04:21
There is a virtualdub filter you could import to do this, http://neuron2.net/hue.html
fccHandler
31st December 2004, 05:28
Thank you. Actually I tried doing that but I couldn't figure out the parameter list for the filter in Avisynth. Can you help?
FWIW, here is an example of what I tried:
LoadVirtualDubPlugin("Hue.vdf","Hue",0)
AVISource("Video1.avi")
Hue(0,0.85,1,"rgbycm")
This reflects the parameters I see displayed in VirtualDub's filter list. I've tried many combinations, but I always get the error "Invalid arguments to function 'Hue'".
stickboy
31st December 2004, 05:41
It's easier if you use the VirtualDub filter import script (http://neuron2.net/vdub_filters_v15.zip).
If you look at the VD_Hue function, you will see that the last argument isn't a string; it's a bitmask.
fccHandler
31st December 2004, 06:05
Thanks, hopefully that will get me going again. :)
Forgive me for a little rant, but I consider it a gross oversight if the current Avisynth can't perform such a simple, basic task internally. Furthermore, I think it's an embarrassment if the "HSIAdjust" filter was removed unnecessarily without a suitable replacement filter in place. (To be fair though, I still don't know for certain that "HSIAdjust" supported RGB...)
A humble plea to the developers: Any chance the "Tweak" filter will support RGB in the future?
ObiKenobi
31st December 2004, 06:10
Originally posted by fccHandler
A humble plea to the developers: Any chance the "Tweak" filter will support RGB in the future?
It already does...
From the Avisynth page:
http://img150.exs.cx/img150/6281/untitled0ig.png
fccHandler
31st December 2004, 06:28
Hmm... What page is that from? The reference I'm accustomed to is http://www.avisynth.org/Tweak but it doesn't mention colorspace support.
The Avisynth version I'm currently using is 2.54 (January 26, 2004). Can you confirm that upgrading to the latest version will enable RGB in Tweak? (I tend to loathe upgrading my trusted software...) :rolleyes:
ObiKenobi
31st December 2004, 06:32
I got that snapshot from: http://www.avisynth.org/FiltersByCategory which lists the filters and the colorspaces they support.
fccHandler
31st December 2004, 06:41
It doesn't work in my version. I get the error "Tweak: YUV data only (no RGB)." Have you actually tried it yourself? If the newest version will work then I'll certainly upgrade, but it would be nice to have some confirmation first.
fccHandler
31st December 2004, 06:47
You edited your post! No fair. :devil:
To address your edit, I'm not at all confident that the information on your linked page is correct. So to say that "HSIAdjust" supported the same colorspaces as "Tweak" is worthless if we can't confirm that Tweak supports the colorspaces listed.
ObiKenobi
31st December 2004, 06:47
Just tried it now and it doesn't seem to work with RGB. I had never used it before with RGB input but I remember that that page has always listed Tweak as having RGB support.
fccHandler
31st December 2004, 06:54
Just to ease my mind, what version are you using?
ObiKenobi
31st December 2004, 06:56
Right now 2.56, but I just installed that about 5 minutes ago. Before that I was using 2.55 and it had the same error message.
fccHandler
31st December 2004, 07:13
You edited your (already edited) post again! :devil:
You realize this disrupts the flow of the conversation? Anyway, I guess I'll wait a while and see if Wilbert has any thoughts to contribute. It seems to me a bit of a hassle to have to import an external VirtualDub filter to perform what (I believe) should be an inherent task.
But thanks ObiKenobi for your quick responses! I much appreciate it. :)
ObiKenobi
31st December 2004, 07:14
Originally posted by fccHandler
You edited your (already edited) post again! :devil:
Sorry, but it wasn't anything significant that I edited out, just the quote that wasn't really necessary. :)
Originally posted by fccHandler
It seems to me a bit of a hassle to have to import an external VirtualDub filter to perform what (I believe) should be an inherent task.
Definitely. It is odd that the filter doesn't support RGB input.
stickboy
31st December 2004, 08:11
HSIAdjust was removed in 2.5.2 (this is described in the changelist that comes with AviSynth).
HSIAdjust did not support RGB either (I checked with 2.5.0).
fccHandler
31st December 2004, 08:59
You are right again, stickboy.
But don't you think "described" is too strong a word? My copy of changelist.htm just says, "Removed HSIAdjust()." Two words, plain and simple. Hardly what I would call a "description". Really just a "notification." And not even close to an "explanation". :p
Anyway my problem has been solved for the moment, with your help, and I'm encoding my video right now. Your suggestion to use the VirtualDub filter import script did the trick.
Thanks also for checking the HSIAdjust function. So are we to conclude that control of RGB saturation has never been supported in any version of Avisynth? (I'm shocked.)
ARDA
31st December 2004, 09:20
Maybe this :)
http://www.avisynth.org/RGBAdjust
another thread with same subjetc
http://forum.doom9.org/showthread.php?s=&threadid=86061&highlight=RGBAdjust
I hope this can be usefull
ARDA
stickboy
31st December 2004, 09:36
Originally posted by fccHandler
Thanks also for checking the HSIAdjust function. So are we to conclude that control of RGB saturation has never been supported in any version of Avisynth? (I'm shocked.)It's not really that shocking.
Adjusting saturation doesn't make a lot of sense in RGB. It'd probably have to convert to YUV internally anyway.
It's too bad that AviSynth supports only YUY2 and YV12, though, which downsample the chroma.
Two words, plain and simple. Hardly what I would call a "description". Really just a "notification." And not even close to an "explanation".Well, I meant in response to your questions about what the last version was that had it.
If you want a fuller explanation:
Adjusts colors in HSI space. Tweak works better except it doesn't have gamma. Since Tweak is technologically leaps and bounds ahead of HSI, they should be merged (just add gamma to tweak) or HSI should simply be dropped before someone gets dependant on it. HSI behavior is unpredictable at anything more than very minor corrections.From http://www.avisynth.org/HSIAdjust
Wilbert
31st December 2004, 14:12
Hi guys :)
You realize this disrupts the flow of the conversation? Anyway, I guess I'll wait a while and see if Wilbert has any thoughts to contribute. It seems to me a bit of a hassle to have to import an external VirtualDub filter to perform what (I believe) should be an inherent task.
Some random comments.
1) Tweak requires YUV (I corrected the info at www.avisynth.org).
2) HSIAdjust also required YUV (I corrected the info at www.avisynth.org).
Thanks also for checking the HSIAdjust function. So are we to conclude that control of RGB saturation has never been supported in any version of Avisynth? (I'm shocked.)
Yup. A while ago I started porting Graft's hue filter to AviSynth. I will finish it one day. But, I'm not sure it will be faster than
clip.ConvertToYUY2.Tweak(hue=...)
The main difference is that with Tweak you have to rotate the entire range of colors, while in VD_Hue you can rotate just a few colors. I think TweakColor (by Trevlac) can do the latter though.
The problem with Graft's hue filter is that I don't understand where the hue transformation is coming from. Perhaps someone can explain it to me? The relation between hue and (r,g,b) is nonlinear, but it is linearized in some way. I guess I have to ask Donald about this when he comes back.
It's too bad that AviSynth supports only YUY2 and YV12, though, which downsample the chroma.
AviSynth v3 will support YUV 4:4:4 as you probably know :)
rfmmars
31st December 2004, 16:23
Take a look at this one.
http://neuron2.net/ipw-web/bulletin/bb/viewtopic.php?t=593
richard
photorecall.net
Wilbert
31st December 2004, 17:21
One thing I noticed with Graft's hue filter (Fdump's filter is based on it, since it used the same transformations) is the following:
Start with pure yellow (avs->blankclip). If you open the script in VDub, use Graft's hue filter and set the saturation to zero, you should get pure white. But you get R=G=B=234 instead. Perhaps it's because of the approximate transformations, perhaps there's an error in it. I really want to know how those transformations are derived.
fccHandler
1st January 2005, 03:13
Thank you for your work! It will be great having DG's Hue (with RGB support) ported to Avisynth.
BTW, I don't think removing the saturation from yellow makes it white. I'm thinking of a black and white TV show for instance. All the colors reduce to various shades of gray when the color is removed, but I would expect only pure white to actually stay white.
Wilbert
1st January 2005, 03:52
BTW, I don't think removing the saturation from yellow makes it white. I'm thinking of a black and white TV show for instance. All the colors reduce to various shades of gray when the color is removed,
Have a look at the diagram in
http://www2.ncsu.edu/scivis/lessons/colormodels/color_models2.html#hue.
Pure yellow (or green, blue, red, etc ...) has an value (lightness) of 1. This implies that reducing the saturation turns it into white.
Now, if the value is less than 1 (r=200,g=200,b=0 for example), then reducing the saturation turns it into grey.
some formulas:
http://en.wikipedia.org/wiki/HSV_color_space
http://www.easyrgb.com/math.php?MATH=M21#text21
fccHandler
1st January 2005, 04:58
Originally posted by Wilbert
Pure yellow (or green, blue, red, etc ...) has an value (lightness) of 1. This implies that reducing the saturation turns it into white.
Ah, I see. Based solely on the diagram I must agree with you. But those diagrams and links are all about computer graphics. Maybe it works differently in the video world?
Honestly, "Hue" and "Value" (or "Intensity") I couldn't care less about. I only want the "Saturation" control. :D In my mind (not getting too technical), I've always thought about it like the "Color" knob on a TV set. You turn it up and colors bloom and people's faces turn red. You turn it down and it's just like watching a B&W set. The "saturation" slider in Donald Graft's filter seems to accomplish a similar effect for digital video, but is "saturation" really the proper term for it?
Just to confuse you more, here's something I noticed: Try desaturating the same BlankClip in VirtualDub, first using Donald's "H/S/I" filter, and then using VirtualDub's internal "HSV adjust" filter. The results are quite different.
Since DG is currently unavailable, perhaps you can ask Avery Lee if he has any thoughts on this.
EDIT:
Just thought of something else. IIRC in video there is the concept of colors being "NTSC safe." (There may also be a similar concept in PAL video.) A vectorscope is a device used to measure the color saturation of broadcast video, and determine if it is "safe" or not. The colors must fall within certain fixed boundaries. Therefore it may not be possible to represent "pure yellow" (or any other pure color) in the video world, i.e., it's always less than Value=1. Perhaps the VirtualDub filters are using formulas customized to reflect this concept...
Leak
1st January 2005, 12:13
Originally posted by fccHandler
Since DG is currently unavailable,
This may be a bit offtopic, but is anybody else finding Donald's website (http://www.neuron2.net/) to be AWOL? :(
Not Found
The requested URL / was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Apache/1.3.31 Server at neuron2.net Port 80
np: Autechre - Maphive 6.1 (EP7)
BruceL
1st January 2005, 14:32
@Leak
I am getting the same as you at all my neuron2 links. Sure hope he is OK and his site is just experiencing a short term technical problem. :(
State of Mind
2nd January 2005, 10:26
Fcchandler, would it be too much trouble for you to post some screenshots of unfiltered DV and enhanced DV in your case? I am interested in seeing the difference in color levels.
Wilbert
2nd January 2005, 15:40
I'm so confused :confused:
Regarding Graft's hue filter. The saturation setting does the following. Setting it to one leaves the rgb clip untouched, and setting it to zero sets the rgb clip to (r,g,b)=(y,y,y) where y is the luminance (as in yuv). In [0,1] it just performs a linear interpolation (and linear extrapolation outside [0,1]).
Normally we have y = 0.299*r + 0.587*g + 0.114*b, but they use a gamma-corrected version: y = 0.3086*r + 0.6094*g + 0.0820*b (don't know yet where these numbers are coming from ...).
http://www.sgi.com/misc/grafica/matrix/index.html
What I don't understand is, how is this related to the saturation in the hsv color format? I guess there's no relation? Setting the saturation to zero results in (r,g,b) = (V,V,V) with V = max(r,g,b) and setting it to one the (r,g,b) may or may not change.
Wilbert
2nd January 2005, 19:40
@fccHandler,
First test version:
http://www.wilbertdijkhof.com/Hue_v10.zip
It should produce identical results.
I also want to look at the hue implementation of the internal vdub hsi filter. Adjusting hue is implemented correctly here.
fccHandler
2nd January 2005, 21:19
Originally posted by State of Mind
Fcchandler, would it be too much trouble for you to post some screenshots of unfiltered DV and enhanced DV in your case? I am interested in seeing the difference in color levels.
If you have VirtualDub and Donald Graft's Hue/Saturation/Intensity filter, you can make your own screenshots. The only parameter I'm changing is the saturation. Even at 83% the difference is visually subtle, but it can be objectively measured with trevlac's excellent "Color Tools" filter (in vectorscope mode).
fccHandler
2nd January 2005, 21:33
Originally posted by Wilbert
First test version:
http://www.geocities.com/wilbertdijkhof/Hue_v10.zip
It should produce identical results.
Great work! I'm sure I'll be testing this later today.
Just to be complete, I noticed that the original H/S/I filter GUI has a checkbox "Preserve luma on hue change," but I don't see that option in the docs of your version.
I also want to look at the hue implementation of the internal vdub hsi filter.
I looked at it. But typical of Avery, it's so heavily optimized as to be incomprehensible to mere mortals. :scared:
Wilbert
2nd January 2005, 22:02
Just to be complete, I noticed that the original H/S/I filter GUI has a checkbox "Preserve luma on hue change," but I don't see that option in the docs of your version.
I still have to add this option :)
Overdrive80
2nd February 2019, 18:39
I resurrected the thread to request that the last option of the filter be finished. Thanks.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.