PDA

View Full Version : Levels luma output values


mg262
24th October 2005, 21:36
I think I'm doing something silly here, but it won't come to me...
Blankclip().converttoyuy2
reduceby2
levels( 16, 1, 200, 128, 128)
converttoyuy2.showpixelvalues()I get out luma values of 126, not 128. :confused:

(Someone is bound to point this out so... I know Blankclip() has colourspace, etc. arguments. Similarly about brackets on functions.)

Someone please put me out of my misery...

foxyshadis
24th October 2005, 22:09
coring=false ;)

It's supposed to just be a clip, not a full remap, though, so I might be wrong.

mg262
24th October 2005, 23:46
You are right. Don't understand quite why, but you are! Thank you.

gzarkadas
25th October 2005, 16:45
You are right. Don't understand quite why, but you are! Thank you.
I believe it is the last call to ConvertToYUY2. Since (at least so the documentation says) all yuv filters clip their output to CCIR range, calling ConvertToYUY2 after Levels clips the result and thus you get 126 instead of 128 (apparently it does not clip but applies internally a levels-like processing).

I have added ColorYUV after the call to ConvertToYUY2 and it works (see the script below).

LoadPlugin("ShowPixelValues.dll")
BlankClip().ConvertToYUY2
ReduceBy2
Levels( 16, 1, 200, 128, 128)
ConvertToYUY2.ColorYUV(levels="tv->pc").ShowPixelValues()

Hope have been helpful (for the future) ;) .

Wilbert
25th October 2005, 17:27
I believe it is the last call to ConvertToYUY2.
No, because it is already YUY2 before Levels is applied. Just try

Levels( 16, 1, 200, 128, 128)
ColorYUV(analyze=true)

Besides ...
Since (at least so the documentation says) all yuv filters clip their output to CCIR range
Well, many (certainly not all) filters clip (= round) to CCIR range, but they don't scale to it. ConvertToYUY2 doesn't do anything (no scaling, no clipping) if the source is already YUY2 or YV12.

Quite frankly, i don't understand why you get 126 instead of the expected 128. (Yes i do understand that you will get luma=126 when applying pc->tv to luma=128. But I don't understand why that conversion is done, if it is done.)

I kinda hoped Sh0dan or IanB would chimp in. I guess we will have to read through the code to see what's going on.

Wilbert
27th October 2005, 23:48
Ok, apperently it is doing something else as stated in the docs. What i think it does (for YUV clips):

1) coring = true (default): input is *scaled* from [16,235] to [0,255], conversion takes place according to the formula in the docs, output is *scaled* back from [0,255] to [16,235].

2) coring = false: conversion takes place according to the formula.

Example (luma of clip = 200; coring = true):

luma_in = 200 => input = (200-16)*255/219 = 214
output = [(input - 16) / (200 - 16)] * (128 - 128) + 128 = 128
luma_out = (ouput*219/255)+16 = 126

IanB
28th October 2005, 04:33
Yes Wilbert is correct1) coring = true (default): input is *scaled* from [16,235] to [0,255], conversion takes place according to the formula in the docs, output is *scaled* back from [0,255] to [16,235].And NO the filter does not do this in 3 steps, it does it all in 1 pass, so the coring option does not effect the speed.