View Full Version : Test Pattern
Frank62
6th February 2022, 13:39
Hi all, I have a simple(?) question:
How to generate a test picture with as many as possible different gradations of red, green, and blue? I'd love to do some research with it.
StainlessS
6th February 2022, 18:32
any good ?
#Return Clip_GRB256() # 256 Frame clip, G increases with frame number
Return Frame_4Kx4K_RGB8(false,false) # 4096 x 4096 frame. (All 16777216 colors of 8 bit RGB, 256x256x256)
###################
Function Frame_4Kx4K_RGB8(Bool "Cartesian",Bool "ShowG") { # 4096 x 4096 frame.
Cartesian = Default(Cartesian,True) # True, Origin @ Bottom Left, False @ Top Left
ShowG = Default(ShowG,True) # Show Grn at Origin
R = YRamp256_H(True) # Red H
B = YRamp256_V(TopZero = !Cartesian) # Blue V
Row = 0
for(y=0,15) {
Column = 0
For(x=0,15) {
Gix = y * 16 + x
G = YFrame256(Gix)
C = CombinePlanes(R,G,B, planes="RGB", source_planes="YYY", pixel_type="RGBP8")
C = (!ShowG) ? C : C.Subtitle("G="+String(Gix),Align=(Cartesian) ? 1 : 7)
Column = (!Column.IsClip) ? C : Column.StackHorizontal(C)
}
Row = (!Row.IsClip) ? Column : Row.StackVertical(Column)
}
Return Row
}
Function Clip_GRB256(Bool "Cartesian",Bool "ShowG") { # 256 Frame clip, G increases with frame number
Cartesian = Default(Cartesian,True) # True, Origin @ Bottom Left, False @ Top Left
ShowG = Default(ShowG,True) # Show Grn at Origin
R = YRamp256_H(True) # Red H
B = YRamp256_V(TopZero = !Cartesian) # Blue V
Result = BlankClip(length=0,width=256,height=256,Pixel_type="RGBP8").Killaudio
for(z=0,255) {
G = YFrame256(z) # Green plane z
C = CombinePlanes(R,G,B, planes="RGB", source_planes="YYY", pixel_type="RGBP8")
C = (!ShowG) ? C : C.Subtitle("G="+String(z),Align=(Cartesian) ? 1 : 7)
Result = Result ++ C
}
return Result
}
##### SubRoutine
Function YRamp256_H(Bool "LeftZero") {
LeftZero = Default(LeftZero,true)
Left = (LeftZero) ? 0 : 255
Right = (LeftZero) ? 255 : 0
LC=BlankClip(length=1,width=1,height=256,pixel_type="Y8",Color_YUV=(Left*256+128)*256+128).KillAudio
RC=LC.BlankClip(Color_YUV=(Right*256+128)*256+128)
StackHorizontal(LC,RC)
Return BilinearResize(512,256).Crop(128,0,-128,-0)
}
Function YRamp256_V(Bool "TopZero") {
TopZero = Default(TopZero,true)
Top = (TopZero) ? 0 : 255
Bot = (TopZero) ? 255 : 0
TC=BlankClip(length=1,width=256,height=1,Pixel_type="Y8",Color_YUV=(Top *256+128)*256+128).KillAudio
BC=TC.BlankClip(Color_YUV=(Bot*256+128)*256+128)
StackVertical(TC,BC)
Return BilinearResize(256,512).Crop(0,128,-0,-128)
}
Function YFrame256(int "Y") { Y=Default(Y,128).Max(0).Min(255) Return BlankClip(length=1,width=256,height=256,Pixel_type="Y8",Color_YUV=(Y *256+128)*256+128).KillAudio }
Frank62
6th February 2022, 20:09
:goodpost: !
What could be better than EVERY possible color. I will try to look into this. Thanks a lot, @StainlessS!
poisondeathray
6th February 2022, 20:59
very cool SS !
But the blue channel does not reach 0 .
eg. @pos 0,0 , the value is RGB 0,0,1
Another confirmation, RGBAdjust(analyze=true) reports min = 1 in the blue chanel
wonkey_monkey
6th February 2022, 23:17
I think it's time for StainlessS to learn Expr... better than putting your faith in a resizer, and somewhat more compact!
function Frame_4Kx4K_RGB8() {
BlankClip(length = 1, width = 4096, height = 4096, pixel_type = "RGBP")
Expr("sx 256 %", "sy 256 / floor 16 * sx 256 / floor +", "sy 256 %")
}
function Clip_GRB256() {
BlankClip(length = 256, width = 256, height = 256, pixel_type = "RGBP")
Expr("sx", "frameno", "sy")
}
poisondeathray
6th February 2022, 23:28
Those expr changes from w_m fix it
#unique colors as per imagemagick
identify -format "%k" allrgbcolors2.png
16777216
With the blue channel missing "0" it was 16711680
StainlessS
7th February 2022, 00:49
Drat !
EDIT:
Added back Cartesian and ShowG to Clip_GRB256() as Wonkey Donkey was too lazy to do it.
Function Clip_GRB256(Bool "Cartesian",Bool "ShowG") {
Cartesian = Default(Cartesian,True) # True, Origin @ Bottom Left, False @ Top Left
ShowG = Default(ShowG,True) # Show Grn at Origin
BlankClip(length = 256, width = 256, height = 256, pixel_type = "RGBP")
Expr("sx", "frameno", (Cartesian) ? "255 sy -" : "sy")
(!ShowG) ? Last : Last.ScriptClip("""Subtitle(String(current_frame,"G=%.0f"),Align="""+((Cartesian) ? "1" : "7")+")")
return last
}
I have not done it for Frame_4Kx4K_RGB8() # Dont think really necessary.
EDIT: I guess a post vertical flip would have sufficed for Cartesian.
poisondeathray
7th February 2022, 01:35
Some fun observations:
1) ~14M unique colors for typical 8bit RGB=>YUV=>RGB round trip (no subsampling) are lost !!)
ConvertToYV24(matrix="rec709")
ConvertToRGB24(matrix="rec709")
"identify" -format "%k" 8bitroundtrip.png
2760365
ffmpeg psnr
[Parsed_psnr_4 @ 0000009bbb8f5d80] PSNR r:51.531297 g:55.092088 b:50.735818 average:52.084023 min:52.084023 max:52.084023
2) 10bit YUV is confirmed lossless for round trip for all colors, when done properly
ConvertToPlanarRGB()
z_ConvertFormat(pixel_type="YUV444P10", resample_filter="point", colorspace_op="rgb:709:709:f=>709:709:709:l")
z_ConvertFormat(pixel_type="RGBP", resample_filter="point", colorspace_op="709:709:709:l=>rgb:709:709:f")
"identify" -format "%k" 10bitroundtrip.png
16777216
ffmpeg psnr
[Parsed_psnr_4 @ 000000ea3a524980] PSNR r:inf g:inf b:inf average:inf min:inf max:inf
wonkey_monkey
7th February 2022, 01:47
1) ~14M unique colors for typical 8bit RGB=>YUV=>RGB round trip (no subsampling) are lost !!)
Wow, I would not have thought it could be that much of a loss. Makes me even more glad that I recently moved some colour boosting functions from 8-bit to 32-bit.
poisondeathray
7th February 2022, 02:04
Wow, I would not have thought it could be that much of a loss. Makes me even more glad that I recently moved some colour boosting functions from 8-bit to 32-bit.
I thought it was a mistake... but I triple checked and also with avsresize , the magnitude is similar
ConvertToPlanarRGB()
z_ConvertFormat(pixel_type="YUV444P8", resample_filter="point", colorspace_op="rgb:709:709:f=>709:709:709:l")
z_ConvertFormat(pixel_type="RGBP", resample_filter="point", colorspace_op="709:709:709:l=>rgb:709:709:f")
"identify" -format "%k" 8bitroundtrip_avsresize.png
2760476
[Parsed_psnr_4 @ 0000006eb7394ac0] PSNR r:51.532180 g:55.093609 b:50.743061 average:52.087903 min:52.087903 max:52.087903
wonkey_monkey
7th February 2022, 10:57
Yeah, I checked too, you're not crazy. Well not about this, anyway.
wonkey_monkey
7th February 2022, 10:59
Wonkey Donkey was too lazy to do it.
Lazy! How d- oh I can't be bothered, I'm going back to sleep.
Emulgator
8th February 2022, 01:25
1) ~14M unique colors for typical 8bit RGB=>YUV=>RGB round trip (no subsampling) are lost !!)
Only 16,5% values left...that is much bleaker than I had assumed too...
StainlessS
8th February 2022, 02:35
As RGB blue makes up for about 11% of YUV Y,
I assume that its the RGB blue channel where 'round-trip' errors mostly live. [I can see WM and PDR dashing to get some results here :) ]
poisondeathray
8th February 2022, 04:29
As RGB blue makes up for about 11% of YUV Y,
I assume that its the RGB blue channel where 'round-trip' errors mostly live. [I can see WM and PDR dashing to get some results here :) ]
Yes, I'm quite "dashing..." :D
Blue is the error "winner"
Count the number of pixels that differ between two images, for each specified channel, and generate the difference mask
"magick" compare -channel Red -metric AE allrgbcolors2.png 8bitroundtrip.png reddiff.png
7667790
"magick" compare -channel Green -metric AE allrgbcolors2.png 8bitroundtrip.png greendiff.png
3377470
"magick" compare -channel Blue -metric AE allrgbcolors2.png 8bitroundtrip.png bluediff.png
8808780
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.