jmac698
4th November 2006, 23:28
Finally, something I've always wanted, a script to read pixelvalues. I have a question, can you think of anyway to extract just one pixel from a frame? Resize/crop have edge blending and also size limits.
Eventually I want to write an automatic colorbars calibrator, that can Tweak() your video to perfection. I can also match colors in clips by calculating Tweak() settings (similar to colorlike, but with standard tweak controls).
colorbars(pixel_type="YV12")
pget()
Function pget(clip video, int "x1", int "y1", int "x2", int "y2",
int "x3", int "y3", \
int "x4", int "y4", int "x5", int "y5", int "x6", int "y6", int
"x7", int "y7", \
int "x8", int "y8") {
#this script displays up to 8 pixel values measured in YUV.
The pixels measured
#are actually the nearest 4x2 area, as I don't know how to
extract a single pixel
#the default values neatly measure colorbars
#Requires: PlaneMinMax plugin by barts, place in plugins
directory of Avisynth
# also needs yv12 input
#version: 0.5b, 2007-11-04
#status: it works, defaults require a video about 70x440 at
least, haven't verified that it gets the right colors/pixels
#but in default with 640x480 it should be ok
w=video.width()/7
w2=4
#I can't get scriptclip to see variables unless they are global
global _pgetx1=Default(x1,w2/2*2)
global _pgety1=Default(y1,0)
global _pgetx2=Default(x2,(w+w2)/2*2)
global _pgety2=Default(y2,16)
global _pgetx3=Default(x3,(2*w+w2)/2*2)
global _pgety3=Default(y3,0)
global _pgetx4=Default(x4,(3*w+w2)/2*2)
global _pgety4=Default(y4,16)
global _pgetx5=Default(x5,(4*w+w2)/2*2)
global _pgety5=Default(y5,0)
global _pgetx6=Default(x6,(5*w+w2)/2*2)
global _pgety6=Default(y6,16)
global _pgetx7=Default(x7,(6*w+w2)/2*2)
global _pgety7=Default(y7,0)
global _pgetx8=Default(x8,(video.width()/5+w2)/2*2)
global _pgety8=Default(y8,440)
#extract a 'pixel' from the source video at x,y
pixel1=video.pointresize(4,2,_pgetx1,_pgety1,4,2)
pixel2=video.pointresize(4,2,_pgetx2,_pgety2,4,2)
pixel3=video.pointresize(4,2,_pgetx3,_pgety3,4,2)
pixel4=video.pointresize(4,2,_pgetx4,_pgety4,4,2)
pixel5=video.pointresize(4,2,_pgetx5,_pgety5,4,2)
pixel6=video.pointresize(4,2,_pgetx6,_pgety6,4,2)
pixel7=video.pointresize(4,2,_pgetx7,_pgety7,4,2)
pixel8=video.pointresize(4,2,_pgetx8,_pgety8,4,2)
#put the pixel values into frame variables
scriptclip(pixel1, """PlaneYUVAvg("Y1","U1","V1")""",
after_frame = True)
#copy the frame variables but no video
Overlay(video,last,opacity=0)
scriptclip("""subtitle(string(Y1,"%3.0f")+ "," + \
string(U1,"%3.0f") + "," + string(V1,"%3.0f"), \
_pgetx1,_pgety1)""")
s1=last
scriptclip(pixel2, """PlaneYUVAvg("Y2","U2","V2")""",
after_frame = True)
Overlay(s1,last,opacity=0)
scriptclip("""subtitle(string(Y2,"%3.0f")+ "," + \
string(U2,"%3.0f") + "," + string(V2,"%3.0f"), \
_pgetx2,_pgety2)""")
s2=last
scriptclip(pixel3, """PlaneYUVAvg("Y3","U3","V3")""",
after_frame = True)
Overlay(s2,last,opacity=0)
scriptclip("""subtitle(string(Y3,"%3.0f")+ "," + \
string(U3,"%3.0f") + "," + string(V3,"%3.0f"), \
_pgetx3,_pgety3)""")
s3=last
scriptclip(pixel4, """PlaneYUVAvg("Y4","U4","V4")""",
after_frame = True)
Overlay(s3,last,opacity=0)
scriptclip("""subtitle(string(Y4,"%3.0f")+ "," + \
string(U4,"%3.0f") + "," + string(V4,"%3.0f"), \
_pgetx4,_pgety4)""")
s4=last
scriptclip(pixel5, """PlaneYUVAvg("Y5","U5","V5")""",
after_frame = True)
Overlay(s4,last,opacity=0)
scriptclip("""subtitle(string(Y5,"%3.0f")+ "," + \
string(U5,"%3.0f") + "," + string(V5,"%3.0f"), \
_pgetx5,_pgety5)""")
s5=last
scriptclip(pixel6, """PlaneYUVAvg("Y6","U6","V6")""",
after_frame = True)
Overlay(s5,last,opacity=0)
scriptclip("""subtitle(string(Y6,"%3.0f")+ "," + \
string(U6,"%3.0f") + "," + string(V6,"%3.0f"), \
_pgetx6,_pgety6)""")
s6=last
scriptclip(pixel7, """PlaneYUVAvg("Y7","U7","V7")""",
after_frame = True)
Overlay(s6,last,opacity=0)
scriptclip("""subtitle(string(Y7,"%3.0f")+ "," + \
string(U7,"%3.0f") + "," + string(V7,"%3.0f"), \
_pgetx7,_pgety7)""")
s7=last
scriptclip(pixel8, """PlaneYUVAvg("Y8","U8","V8")""",
after_frame = True)
Overlay(s7,last,opacity=0)
scriptclip("""subtitle(string(Y8,"%3.0f")+ "," + \
string(U8,"%3.0f") + "," + string(V8,"%3.0f"), \
_pgetx8,_pgety8)""")
}
Eventually I want to write an automatic colorbars calibrator, that can Tweak() your video to perfection. I can also match colors in clips by calculating Tweak() settings (similar to colorlike, but with standard tweak controls).
colorbars(pixel_type="YV12")
pget()
Function pget(clip video, int "x1", int "y1", int "x2", int "y2",
int "x3", int "y3", \
int "x4", int "y4", int "x5", int "y5", int "x6", int "y6", int
"x7", int "y7", \
int "x8", int "y8") {
#this script displays up to 8 pixel values measured in YUV.
The pixels measured
#are actually the nearest 4x2 area, as I don't know how to
extract a single pixel
#the default values neatly measure colorbars
#Requires: PlaneMinMax plugin by barts, place in plugins
directory of Avisynth
# also needs yv12 input
#version: 0.5b, 2007-11-04
#status: it works, defaults require a video about 70x440 at
least, haven't verified that it gets the right colors/pixels
#but in default with 640x480 it should be ok
w=video.width()/7
w2=4
#I can't get scriptclip to see variables unless they are global
global _pgetx1=Default(x1,w2/2*2)
global _pgety1=Default(y1,0)
global _pgetx2=Default(x2,(w+w2)/2*2)
global _pgety2=Default(y2,16)
global _pgetx3=Default(x3,(2*w+w2)/2*2)
global _pgety3=Default(y3,0)
global _pgetx4=Default(x4,(3*w+w2)/2*2)
global _pgety4=Default(y4,16)
global _pgetx5=Default(x5,(4*w+w2)/2*2)
global _pgety5=Default(y5,0)
global _pgetx6=Default(x6,(5*w+w2)/2*2)
global _pgety6=Default(y6,16)
global _pgetx7=Default(x7,(6*w+w2)/2*2)
global _pgety7=Default(y7,0)
global _pgetx8=Default(x8,(video.width()/5+w2)/2*2)
global _pgety8=Default(y8,440)
#extract a 'pixel' from the source video at x,y
pixel1=video.pointresize(4,2,_pgetx1,_pgety1,4,2)
pixel2=video.pointresize(4,2,_pgetx2,_pgety2,4,2)
pixel3=video.pointresize(4,2,_pgetx3,_pgety3,4,2)
pixel4=video.pointresize(4,2,_pgetx4,_pgety4,4,2)
pixel5=video.pointresize(4,2,_pgetx5,_pgety5,4,2)
pixel6=video.pointresize(4,2,_pgetx6,_pgety6,4,2)
pixel7=video.pointresize(4,2,_pgetx7,_pgety7,4,2)
pixel8=video.pointresize(4,2,_pgetx8,_pgety8,4,2)
#put the pixel values into frame variables
scriptclip(pixel1, """PlaneYUVAvg("Y1","U1","V1")""",
after_frame = True)
#copy the frame variables but no video
Overlay(video,last,opacity=0)
scriptclip("""subtitle(string(Y1,"%3.0f")+ "," + \
string(U1,"%3.0f") + "," + string(V1,"%3.0f"), \
_pgetx1,_pgety1)""")
s1=last
scriptclip(pixel2, """PlaneYUVAvg("Y2","U2","V2")""",
after_frame = True)
Overlay(s1,last,opacity=0)
scriptclip("""subtitle(string(Y2,"%3.0f")+ "," + \
string(U2,"%3.0f") + "," + string(V2,"%3.0f"), \
_pgetx2,_pgety2)""")
s2=last
scriptclip(pixel3, """PlaneYUVAvg("Y3","U3","V3")""",
after_frame = True)
Overlay(s2,last,opacity=0)
scriptclip("""subtitle(string(Y3,"%3.0f")+ "," + \
string(U3,"%3.0f") + "," + string(V3,"%3.0f"), \
_pgetx3,_pgety3)""")
s3=last
scriptclip(pixel4, """PlaneYUVAvg("Y4","U4","V4")""",
after_frame = True)
Overlay(s3,last,opacity=0)
scriptclip("""subtitle(string(Y4,"%3.0f")+ "," + \
string(U4,"%3.0f") + "," + string(V4,"%3.0f"), \
_pgetx4,_pgety4)""")
s4=last
scriptclip(pixel5, """PlaneYUVAvg("Y5","U5","V5")""",
after_frame = True)
Overlay(s4,last,opacity=0)
scriptclip("""subtitle(string(Y5,"%3.0f")+ "," + \
string(U5,"%3.0f") + "," + string(V5,"%3.0f"), \
_pgetx5,_pgety5)""")
s5=last
scriptclip(pixel6, """PlaneYUVAvg("Y6","U6","V6")""",
after_frame = True)
Overlay(s5,last,opacity=0)
scriptclip("""subtitle(string(Y6,"%3.0f")+ "," + \
string(U6,"%3.0f") + "," + string(V6,"%3.0f"), \
_pgetx6,_pgety6)""")
s6=last
scriptclip(pixel7, """PlaneYUVAvg("Y7","U7","V7")""",
after_frame = True)
Overlay(s6,last,opacity=0)
scriptclip("""subtitle(string(Y7,"%3.0f")+ "," + \
string(U7,"%3.0f") + "," + string(V7,"%3.0f"), \
_pgetx7,_pgety7)""")
s7=last
scriptclip(pixel8, """PlaneYUVAvg("Y8","U8","V8")""",
after_frame = True)
Overlay(s7,last,opacity=0)
scriptclip("""subtitle(string(Y8,"%3.0f")+ "," + \
string(U8,"%3.0f") + "," + string(V8,"%3.0f"), \
_pgetx8,_pgety8)""")
}