Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 11th April 2025, 10:05   #1  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
Levels(0,1,128,0,255) - why does it work like that with U and V?

This is the original YUV range without modification (histogram="levels"):



I wanted to cut out only the left half (ranges 0-127 in each planes) and I did it like this:
Code:
levels(0,1,128,0,255,coring=false)
And the graph looks like this:


And while the luma graph is as expected, U and V have only expanded proportionally to both sides.
These graphs don't represent values ​​from 0 to 255? (like luma)

When I do:
Code:
levels(128,1,255,0,255,coring=false)
the U and V graphs look the same.


What don't I understand?

And why am I doing this -- a captured miniDV cassette has a Y range 16-255. I wanted to check if the chroma also exceeds 16-240 range.
rgr is offline   Reply With Quote
Old 11th April 2025, 10:16   #2  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
At least I found out that chroma does exceed the 0-240 range.

rgr is offline   Reply With Quote
Old 11th April 2025, 11:34   #3  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,614
iirc. Levels in Avisynth is meant or 'brightness, contrast, and gamma', so it does not change the chroma.
(different story in Vapoursynth, which is why at the beginning folks were confused that is didn't work like Avisynth unless you only process the luma or rgb.)
hmm, on the wiki it states:
Quote:
For adjusting brightness or contrast in YUV mode, it may be better (depending on the effect you are looking for) to use Tweak or ColorYUV, because Levels changes the chroma of the clip.
__________________
Hybrid here in the forum, homepage, its own forum

Last edited by Selur; 11th April 2025 at 11:37.
Selur is offline   Reply With Quote
Old 11th April 2025, 11:52   #4  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
"because Levels changes the chroma of the clip"

And that's exactly what I was looking for. But this change of chrome is not known by what rules.
rgr is offline   Reply With Quote
Old 11th April 2025, 13:23   #5  |  Link
Emulgator
Big Bit Savings Now !
 
Emulgator's Avatar
 
Join Date: Feb 2007
Location: close to the wall
Posts: 1,906
Quote:
At least I found out that chroma does exceed the 0-240 range.
I would be interested to see the script that outputs such histogram.
With DV and HDV cam chipsets Y going 16..255 is encountered often, but U,V ?
Canopus ADVC-300: Analog Device's Video DAC's ADV7172, ADV7173 implemented modulation range for U,V values is 128±112
__________________
"To bypass shortcuts and find suffering...is called QUALity" (Die toten Augen von Friedrichshain)
"Data reduction ? Yep, Sir. We're that issue working on. Synce invntoin uf lingöage..."

Last edited by Emulgator; 14th April 2025 at 18:23.
Emulgator is offline   Reply With Quote
Old 11th April 2025, 16:54   #6  |  Link
lollo2
Registered User
 
lollo2's Avatar
 
Join Date: Aug 2017
Location: Italy
Posts: 144
Quote:
Originally Posted by Selur View Post
iirc. Levels in Avisynth is meant or 'brightness, contrast, and gamma', so it does not change the chroma.
Levels in AviSynth affects the chroma. The simple functions LevelsLumaOnly does not: https://forum.doom9.org/showthread.p...606#post536606

AFAIK Chroma manipulations with Levels is undetermined and not suggested. Use ColorYUV to act on U and V channels.
__________________
A channel on S-VHS / VHS capture and AviSynth restoration https://www.youtube.com/channel/UCMs...h1MmNAs7I8nu4g
lollo2 is offline   Reply With Quote
Old 11th April 2025, 19:30   #7  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,318
For YUV if you want to tweak U and V - try to separate planes of planar YUV and apply Levels() to each plane as Y-only (single plane) clip. And merge YUV back after.
DTL is offline   Reply With Quote
Old 11th April 2025, 23:00   #8  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 4,048
Avisynth's Levels() was designed to emulate VirtualDub's Levels filter working in RGB mode. The transform that calculated from the values given to Levels() is applied equally to each RGB channel. The result is that the U and V channels change along with the Y channel. It increases saturation when one increases the contrast.
If you want Y to be affected only use YLevels() which preserves color saturation better.
http://avisynth.nl/index.php/Ylevels
https://forum.doom9.org/showpost.php...2&postcount=41
Or use Levels() with chroma copyback from the original chroma.

Edit:
@rgr. The screenshot with histogram of post#2 doesn't make much sense to me. (How) did you manipulate the source?

Last edited by Sharc; 12th April 2025 at 09:10. Reason: Link added
Sharc is offline   Reply With Quote
Old 14th April 2025, 14:09   #9  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
Quote:
Originally Posted by Emulgator View Post
I would be interested to see the script that outputs such histogram.
The whole script is just the above mentioned "levels(0,1,128,0,255,coring=false)".

Quote:
With DV and HDV cam chipsets Y going 16..255 is encountered often, but U,V ?
I was also surprised, but that is clear from the histogeram.
rgr is offline   Reply With Quote
Old 14th April 2025, 14:16   #10  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
Quote:
Originally Posted by Sharc View Post
ses saturation when one increases the contrast.
If you want Y to be affected only use YLevels() which preserves color saturation better.
http://avisynth.nl/index.php/Ylevels
https://forum.doom9.org/showpost.php...2&postcount=41
Or use Levels() with chroma copyback from the original chroma.
No, I also want to change the value of all planes.
Y - from 16-255 to 0-255 (or 16-235)
U,V - from 16-255 to 0-255 (or 16-235)
I expected a simple "Levels (16,1,255,0,255)" to do just that.


Quote:
Edit:
@rgr. The screenshot with histogram of post#2 doesn't make much sense to me. (How) did you manipulate the source?
No, this is what the histogram looks like after applying "levels(0,1,128,0,255,coring=false)" -- theoretically converting the range 0-128 to 0-255.
rgr is offline   Reply With Quote
Old 14th April 2025, 14:48   #11  |  Link
StvG
Registered User
 
Join Date: Jul 2018
Posts: 569
Quote:
Originally Posted by rgr View Post
And why am I doing this -- a captured miniDV cassette has a Y range 16-255. I wanted to check if the chroma also exceeds 16-240 range.
There is Limiter() function to check/display if planes have outside range pixels.

Quote:
Originally Posted by rgr View Post
No, I also want to change the value of all planes.
Y - from 16-255 to 0-255 (or 16-235)
U,V - from 16-255 to 0-255 (or 16-235)
Separate planes, apply Ylevels for every plane, combine planes.
StvG is offline   Reply With Quote
Old 14th April 2025, 15:36   #12  |  Link
Sharc
Registered User
 
Join Date: May 2006
Posts: 4,048
Quote:
Originally Posted by rgr View Post
And why am I doing this -- a captured miniDV cassette has a Y range 16-255. I wanted to check if the chroma also exceeds 16-240 range.
You don't have to tamper the levels for this test.
The standard histogram("levels") provides this information. See your very first screenshot. U and V are well within the limits (as usual). It is only Y which exceeds 235 and clips at 255.

or use
Code:
ColorYUV(analyze=true)
http://avisynth.nl/index.php/ColorYUV
Scroll down to the bottom of that page.

or use to see the Y,U,V waveforms and Vectorscope:
Code:
VideoScope(DrawMode="both",HistoTypeBottom="UV",HistoTypeSide="Y",FrameType="UV")
http://avisynth.nl/index.php/VideoScope

Edit:
And if you want to modify YUV data use
Code:
ColorYUV(...........)
http://avisynth.nl/index.php/ColorYUV

Last edited by Sharc; 14th April 2025 at 16:39.
Sharc is offline   Reply With Quote
Old 14th April 2025, 18:18   #13  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,318
Quote:
Originally Posted by rgr View Post
No, I also want to change the value of all planes.
Y - from 16-255 to 0-255 (or 16-235)
U,V - from 16-255 to 0-255 (or 16-235)
I expected a simple "Levels (16,1,255,0,255)" to do just that.
UVs are completely different from Y. They are zeroed at 128 code level and bi-polar. If you really execute U,V - from 16-255 to 0-255 (or 16-235) it mostly probably will shift coded zero level from 128 to lower and it will cause some constant colour tone and saturation shift.
So Levels for YUV in good case simply do not change anything with UVs (copy).

Last edited by DTL; 15th April 2025 at 05:03.
DTL is offline   Reply With Quote
Old 14th April 2025, 20:13   #14  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,652
Quote:
They are zeroed at 127
Isn't it 128/0x80?
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 14th April 2025, 21:39   #15  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,135
"Isn't it 128/0x80?"

+1.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 14th April 2025 at 21:41.
StainlessS is offline   Reply With Quote
Old 14th April 2025, 23:35   #16  |  Link
wonkey_monkey
Formerly davidh*****
 
wonkey_monkey's Avatar
 
Join Date: Jan 2004
Posts: 2,652
Quote:
Originally Posted by StainlessS View Post
"Isn't it 128/0x80?"

+1.
No, it's definitely not 129
__________________
My AviSynth filters / I'm the Doctor
wonkey_monkey is offline   Reply With Quote
Old 15th April 2025, 05:02   #17  |  Link
DTL
Registered User
 
Join Date: Jul 2018
Posts: 1,318
Yes - Cb Cr are (colour difference)+128 in ITU BT.601 equations. So its zeroes are at 128 in 8 bit. I fixed that post. I typically make +-1 errors and it cause bugs in software too.

"it's definitely not 129"

But 128 is also 129th code value counted as integer from 0. The digital 8bit range of 0..255 (counted/mapped as 0..255 not 1..256) is centered at 255/2=127.5 . And ITU select to round it to 128. So UVs are also +0.5 offsetted from real 255/2 mid value of 8 bit.

Last edited by DTL; 15th April 2025 at 05:20.
DTL is offline   Reply With Quote
Old 15th April 2025, 14:40   #18  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 11,135
Quote:
Originally Posted by wonkey_monkey View Post
No, it's definitely not 129
I was agreeing with you, and not providing an alternative answer [and I think you know that ]

and, for 8 bit TV Y levels mid point is,
(16 + 235) / 2 = 125.5 # Rounded to 126.

and for 8 bit U/V,
(16 + 239) / 2 = 127.5 # Rounded to 128.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 16th April 2025, 13:28   #19  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
Quote:
Originally Posted by Sharc View Post
You don't have to tamper the levels for this test.
The standard histogram("levels") provides this information. See your very first screenshot. U and V are well within the limits (as usual). It is only Y which exceeds 235 and clips at 255.
Look post #2.
rgr is offline   Reply With Quote
Old 16th April 2025, 13:31   #20  |  Link
rgr
Registered User
 
Join Date: Jun 2022
Posts: 161
Quote:
Originally Posted by DTL View Post
UVs are completely different from Y. They are zeroed at 128 code level and bi-polar. If you really execute U,V - from 16-255 to 0-255 (or 16-235) it mostly probably will shift coded zero level from 128 to lower and it will cause some constant colour tone and saturation shift.
So Levels for YUV in good case simply do not change anything with UVs (copy).
Yes, I noticed that it doesn't work. White (YUV 255,127,127) stops being white (UV -> ~120). The image becomes greenish overall.
rgr is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:16.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.