Log in

View Full Version : Colour Conversion problems with Avisynth


wiseant
27th March 2008, 22:06
Hi All,

Hope I have the appropriate forum . . .

Perplexed about all the information I have seen about colour spaces and colour conversion, I decided to do a couple of tests. Using Virtual Dub I captured two 640x480 interlaced clips using HuffYUV in YUY2 color space.

Clip 1 was done with Extend luma black point and Extend luma white point both disabled. This is supposed to create a clip with a colour range of 0 to 255 for viewing on a PC. I named this clip VD-no.luma.avi

Clip 2 was done with Extend luma black point and Extend luma white point both enabled: "Compresses the luminance range of an image so that "superwhite" levels from 0-15 are scaled to within the valid luminance range of 16-235, out of 0-255." This is supposed to create a clip with a color range of 16-235 for viewing on a TV set, i.e. DVD player. I named this clip VD-luma.avi

To analyze these clips I used AvsP (a GUI for Avisynth):

The first thing I did was to use ColorYUV(Analyze=True) which shows the Luma and Chroma values:

This confirmed that the VD-no.luma.avi clip showed values of 0 (black) and 255 (white) and VD-luma.avi showed values of 16 (black) and 231 (white) - so far so good.

[see VD-no.luma.jpg and VD-luma.jpg]

The next thing I tried was ColorYUV(levels="PC->TV") on the VD-no.luma.avi clip. This is supposed to adjust a "PC" clip to a "TV" clip, i.e. change the values <16 to 16 and values >235 to 235 - in effect making the clip suitable for viewing on a TV - this function did not appear to do anything.

[see VD-no.luma-PC-TV.histo.jpg]

Then I tried Levels(0, 1, 255, 16, 235, coring=false) on the VD-no.luma.avi clip - this is supposed to do the same thing as ColorYUV(levels="PC->TV") - this appeared to work:
the lowest value is now 16 instead of 0 and the highest value is now 235 instead of 255:

Levels(0, 1, 255, 16, 235, coring=false)
used this with VD-no.luma.avi
Luma Y / ChromaU / ChromaV
Average 173.29 128.80 127.51
Minimum 16 96 87
Maximum 235 164 141
Loose Minimum 17 122 121
Loose Maximum 223 136 131

compared to VD-no.luma.avi w/o Levels
Luma Y / ChromaU / ChromaV
Average 183.14 128.56 126.83
Minimum 0 89 79
Maximum 255 170 143
Loose Minimum 1 120 119
Loose Maximum 241 137 131

Levels(0, 1, 255, 16, 235, coring=true)
used this with VD-no.luma.avi
Luma Y / ChromaU / ChromaV
Average 173.41 128.80 127.51
Minimum 30 96 87
Maximum 218 164 141
Loose Minimum 30 122 121
Loose Maximum 218 136 131

"Levels also changes the chroma of the clip."

BTW - what does coring=true actually do - the avisynth info is unclear to me . . .

[see VD-no.luma-Levels.cf.jpg]

Then I tried Limiter(16, 235, 16, 240) which is supposed to create a range of values from 16-235 (luma) and 16-240 (chroma) for viewing the clip on a TV - it appeared to do nothing at all.

[see VD-no.luma-Limiter.jpg] - and it appears that the values shown are incorrect . . .

My Observations [possibly incorrect]
If a person is using VirtualDub for captures and they want to view the clip on a TV set, i.e. DVD, MPEG-2, MPEG-4 they should enable both Extend luma black point and Extend luma white point.

If a person has a clip that has a range from 0-255 it will not look OK on a TV set, the range has to be "remapped" to 16-235 - however this appears easier said than done - unless I am missing something here, ColorYUV(levels="PC->TV") and Limiter(16, 235, 16, 240) don't appear to do what they are supposed to do.

Am I missing something here? Why does ColorYUV(levels="PC->TV") and Limiter(16, 235, 16, 240) appear to do nothing . . . and as noted on Avisynth.org: "Levels also changes the chroma of the clip."

TIA

sh0dan
27th March 2008, 22:43
ColorYUV(levels="PC->TV") and Limiter(16, 235, 16, 240) don't appear to do what they are supposed to do.
Limiter does what it advertises. Check your own image.

Coloryuv does not apply any image correction when you use analyze=true - it analyzes and returns the uncorrected image.

wiseant
27th March 2008, 23:09
Thanks sh0dan,

I tried ColorYUV(levels="PC->TV") w/o the analyze=true
Yes - it does work - visually I can see the difference - thanks

I guess that I don't know what Limiter does - I thought that using Limiter(16, 235, 16, 240) would have more or less the same result as ColorYUV(levels="PC->TV") except for the chroma values but when I compare the two results, Limiter(16, 235, 16, 240) does not appear to change anything?

According to avisynth.org: "By default this filter clips (or "clamps") pixels under 16 to 16 and over 235 (or 240) to 235 (or 240)."

Re: the VD-no.luma-Limiter.jpg - what I was saying was that the printed out values appear to be incorrect - when I compare

ffmpegSource("F:\VD-no.luma.avi") to

to
ffmpegSource("F:\VD-no.luma.avi")
Limiter()

Visually, I see no change at all.

If you had a clip that ranged from 0 to 255 and you wanted to encode it for viewing on a TV set what avisynth tool would you use?

TIA

2Bdecided
28th March 2008, 10:59
Clip 1 was done with Extend luma black point and Extend luma white point both disabled. This is supposed to create a clip with a colour range of 0 to 255 for viewing on a PC.AFAIK this isn't right. If you have YUV data, most PC software/hardware (i.e. your media player abd graphics card), when converting it to RGB, will assume the Y range is 16-235, and expand it to an RGB range of 0-255. If the Y range is 0-255, then all the values 0-16 will become 0, and all the values 235-255 will become 255 - in other words, you will clips the blacks and highlights dramatically and horribly.

If you have RGB data, then 0-255 is expected, and 16-235 will be displayed as dull and washed out.

Of course in AVIsynth you can mess around with any range you want - I'm talking about feeding the result to standard software, players, codecs etc.

Cheers,
David.

2Bdecided
28th March 2008, 11:01
I guess that I don't know what Limiter does - I thought that using Limiter(16, 235, 16, 240) would have more or less the same result as ColorYUV(levels="PC->TV")

Levels scales it. 0>16, 1>17 (approx), 2>18 (approx) etc etc

Limiter clips it. 0>16, 1>16, 2>16, .... 14>16, 15>16, 16>16, 17>17, 18>18, ... 234>234, 235>235, 236>235, 237>235, 238>235, ..., 255>235.

Hope this helps.

Cheers,
David.

wiseant
29th March 2008, 18:51
Hi 2BDecided:

Here's some of my findings:

I created a YUV clip with a range of 0 to 255 - then put it on a DVD, then used VDub to capture it:

a) extend luma enabled
these are the values: original (1), and captured (2) for a range 0-255:
(1) 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 255

(2) 1 14 28 46 62 77 93 111 125 142 158 173 189 206 222 238 253


Edit: these values are incorrect: (2)
these are the values: original (1), and captured (2) for a range 16-235:
(1) 16 30 43 57 71 85 98 112 126 140 153 167 180 194 208 222 235

(2) 14 28 40 55 68 83 95 111 123 139 150 165 178 192 206 220 233

With extend luma black and extend luma white both enabled, the capture of a "original" 0-255 range clip resulted in 0-255 range clip

With extend luma black and extend luma white both enabled, the capture of a "original" 16-235 range clip resulted in 16-235 range clip


b) extend luma disabled
these are the values: original (1), and captured (2) for a range 0-255:
(1) 0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 255

(2) 0 14 29 45 63 78 93 111 127 142 156 175 191 208 225 240 255


Edit: these values are also incorrect: (2)
these are the values: original (1), and captured (2) for a range 16-235:

(1) 16 30 43 57 71 85 98 112 126 140 153 167 180 194 208 222 235

(2) 0 0 15 36 55 76 93 114 133 153 170 191 211 231 247 255 255

With extend luma black and extend luma white both disabled, the capture of a "original" 0-255 range clip resulted in 0-255 range clip

Edit: this is incorrect:
With extend luma black and extend luma white both disabled, the capture of a "original" 16-235 range clip resulted in 0-255 range clip BUT with values of 0 for the original values of 16 and 30; and values of 255 for the original values of 222 and 235


[Conclusion
If you are capturing a 0-255 source it does not matter whether the extend luma is enabled or disabled. If you are capturing a 16-235 source it is best to enable extend luma point] - Edit: this is incorrect


BTW this is what I found re various software re displaying a YUV 0-255 range clip:

Avidemux 2.4, AvsP, Cut_Assistant, VirtualDub, VirtualDubMPEG-2 - display full range from 0 to 255
0 16 32 48 64 80 96 112 128 144 160 176 192 208 224 240 255

ffplay, Mplayer, MPlayerC, WMPlayer - display 16 to 235 range
16 30 43 57 71 85 98 112 126 140 153 167 181 195 208 222 235

Regards,
wiseant

P.S. The next thing that I am going to do is to copy the clips from the DVD I made to a VHS tape and then capture from tape . . .

2Bdecided
31st March 2008, 12:00
I don't think your results make sense.

Firstly, let's assume you encoded the DVD correctly.

Then, let's assume your DVD player correctly reproduces blacker-than-black and whiter-than-white, which means all values from 0-255 are linearly mapped to a suitable voltage range.

These are both big assumptions, but if either is wrong, then the test is pointless.


Now, in section b, all you change between parts 1 and 2 is the signal on the disc. Nothing else. Yet magically, in b 1, the voltage generated by "224" is digitised as "225", while in b 2, the voltage generated by "222" is digitised as "255".

What caused the change? You said that you didn't change the settings in the capture software, and I assume you changed nothing on the DVD player.

All else being equal, a given voltage relative to sync and blanking will give a consistent digitised value (+/- a bit of noise). The fact there are other different voltages around should not make a difference, yet here it appears to.

This doesn't make any sense - either something is intervening, or your results are contradictory.

Cheers,
David.

wiseant
1st April 2008, 17:45
Hi 2Bdecided

Looks like I should have been clearer ...

First of all, there were two test clips. "bar graphs" approx 35 pixels wide and 480 pixels high. These test clips are totally different from the attached jpegs . . .

The first clip has a range of 0-255, the second clip a range of 16-235. The values that I show come from a ColorPicker . . .

Hopefully this makes more sense

Cheers

2Bdecided
1st April 2008, 18:33
No, it doesn't. I understood you had two different clips.

The point is, the few values that are the same in both clips should give the same values when captured. They don't.

I know there are other values within the clips which are different. This is (nearly) irrelevant.

Cheers,
David.

wiseant
2nd April 2008, 02:01
Hi again 2Bdecided,

I'm glad you responded to my last reply . . .
Yes, I made a mistake - don't know where it was - but it looks like I got things reversed - so I redid my test.

I made a 16-240 bmp then used VDub to make an uncompressed YCbCr clip - then I made an .avs file and added ConvertToYV12() - then used HCEnc021 to encode to .m2v file (I used a Quant value of 1.0) - then I used muxman to create the DVD files - then I used ImgBurn to burn the DVD - then I used VDub to capture from the DVD player (I used YUY2 - No Recompression)

I did 2 captures:

1. with both extend luma white and extend luma black ENabled

2. with both extend luma white and extend luma black DISabled

The result:

With this 16-240 clip the most accurate result was obtained by 2.

So, if one is capturing a 16-235 source it is best to DISable the extend luma points . . .

BTW the range was 16-240, vis:
16, 32, 48, 64, 80, 96, 112, 128, 144, 160, 176, 192, 208, 224, 240

whwhwhwh9
7th April 2008, 16:56
I also got confused lately with the YUV color conversion across different machines.
First, I created a YUYV frame of 4 stripes, in which YUV=(0, 80, 80), (16, 80, 80), (235, 80, 80), (255, 80, 80).
Then I saved it as an uncompressed AVI, and played it on different machines, such as PC (Dell 4600), notebook (Dell D620, Dell D610), with various software, such as Windows Media Player 9, KMPlayer 2.9.3.1428, VirtualDub 1.6.10, all on LCD screen.
Surprisingly, some combinations give me 4 stripes, while some only give me 2 bigger stripes with 235 and 255 being rendered as the same brightness.
Since it is uncompressed YUYV, I assume that it has nothing to do with codecs such as Xvid, Divx, etc.
Could someone give me a hint? Thanks!

2Bdecided
7th April 2008, 17:14
If you have YUV data, most PC software/hardware (i.e. your media player abd graphics card), when converting it to RGB, will assume the Y range is 16-235, and expand it to an RGB range of 0-255. If the Y range is 0-255, then all the values 0-16 will become 0, and all the values 235-255 will become 255 - in other words, you will clip the blacks and highlights dramatically and horribly.

What he said. ;)

Cheers,
David.