View Single Post
Old 19th February 2004, 19:02   #68  |  Link
trevlac
budala
 
Join Date: Oct 2003
Location: U.S.
Posts: 545
@Wilbert

Some more tests

I used the following 75% colorbars script, ColorYUV(Analyze) and my RGB histograms in VDub to test various ways to convert YUV to RGB. Ideally, a conversion (all rgb channels) would exactly match the luma range in YUV. This is hard to test if mapping occurs, but you can start with RGB and see what you get back.

Code:
#LoadPlugin("YUY2toRGB219.dll")

black = BlankClip(width=10,height=240,length=300, color=$000000)
white = BlankClip(width=90,height=240,length=300, color=$BFBFBF)
yellow = BlankClip(width=90,height=240,length=300, color=$BFBF00)
cyan = BlankClip(width=90,height=240,length=300, color=$00BFBF)
green = BlankClip(width=90,height=240,length=300, color=$00BF00)
magenta = BlankClip(width=90,height=240,length=300, color=$BF00BF)
red = BlankClip(width=90,height=240,length=300, color=$BF0000)
blue = BlankClip(width=90,height=240,length=300, color=$0000BF)
set1 = StackHorizontal(black,white,yellow,cyan,green,magenta,red,blue)
set2 = StackHorizontal(black,blue,red, magenta,green, cyan, yellow,white)
stackVertical(set1,set2)
#1 -- No Conversions

#2 -- ConvertToYUY2 
#ConvertToYUY2()
#ColorYUV(Analyze=true)

#3 -- ConvertToRGB 
#ConvertToYUY2()
#ConvertToRGB()

#4 -- Default OS
#ConvertToYUY2()

#5 -- ConvertToRGB(709) 
#ConvertToYUY2()
#ConvertToRGB(matrix="rec709")

#6 -- YUY2toRGB219 
#ConvertToYUY2()
#YUY2toRGB219()

#7 -- Overlay 
#ConvertToYUY2()
#ovr = blankclip(width=1,height=1,color=$000000)
#overlay(ovr,mode="Add",output="RGB24",pc_range=true)


# --------- Results --------------
# R(min/max) G(min/max) B(min/max) Luma(min/max)

#1 -- RGB Colorbars   R(0/191) G(0/191) B(0/191) Luma(0/191)
#2 -- ConvertToYUY2   U(44/212) V(44/212) Luma(16/180)

#3 -- ConvertToRGB()  R(0/191) G(0/191) B(0/192) Luma(0/191)
#4 -- default OS      R(0/191) G(0/190) B(0/191) Luma(0/190) 
#5 -- ConToRGB(709)   R(0/208) G(0/191) B(0/200) Luma(0/191)  
#6 -- YUY2toRGB219    R(16/180) G(16/180) B(16/180) Luma(15/181) 
#7 -- Overlay         R(14/184) G(14/181) B(14/185) Luma(15/179)
Conclusions
ConvertToYUY2 changes the range from 0-191 to 16-180. Any Conversion that goes back to 0-191 is stretching back out. Matrix="rec709" still changes the range. #6 and #7 are the only ones that do not change the range.

#3, #4, #6 all have very small errors. I believe all of these errors are due to the 8bit conversion to YUV. If I run the numbers thru a calculator and 'store' 9bit YUV numbers, the errors go away. The differences between #3 & #4 are probably due to the truncation/rounding in the calculations used.

#7 had worse results than I expected. I'm not sure of the process inside. Overlay was clearly not intended for this use, it just seemed a work around.

#5 is interesting because it clearly changes the colors, but it also appears to map the colors differently.

Interpolation - This is easy to see on the waveform monitor. If there are dots around the color change, the threshold pixels moved due to interpolation. The default OS #3 and Overlay #7 do not interpolate. #3,#5,#6 do interpolate. For viewing, interpoplation is clearly a good thing. If you are going to convert back to YUV, I'm not sure.

Opinion
Changing the range gains no processing advantages. It may however clip your range. Processing in YUV may also have some disadvantages over RGB. There is less range to work with in YUV. However, since most of our source comes from YUV, I'm not sure how you create that xtra range, or if it's worth it.

trevlac is offline   Reply With Quote