Log in

View Full Version : New Script: pget 0.5b


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)""")
}

Didée
5th November 2006, 02:01
I have a question, can you think of anyway to extract just one pixel from a frame?

Sure, it's almost trivial: get pixel at location (x,y) and blow it up to a 32x32 clip:

bilinearresize(32,32, x,y, 1,1)

Getting the pixel value then can be done by getting the "frame average" or "maximum" (doesn't matter in this case). Least typing is needed with Y/U/V/PlaneMax().

jmac698
5th November 2006, 07:20
When cropping less than 4x2 there's green pixels. Mmx/sse needs some minimum size.
One workaround, pointresize x4 then crop to 4x4.
Also I couldn't get the built-in max functions to work. Can you?
This script was really hard. The global vars are tied to the clip they were created in. I had to use a trick to copy them to another clip. I can't get local vars to be passed to the function either. The docs don't tell you a lot of advanced stuff you need to know. Without a good theory it's hard to proceed except trial and error.

Wilbert
5th November 2006, 13:35
Why don't you write a plugin for it (input a clip and a coordinate and output a number)?

jmac698
5th November 2006, 16:52
Yes, we've all been waiting for this, but no one can figure out how to do it.
http://forum.doom9.org/showthread.php?t=108602&highlight=pixelinfo

Reading that thread again, it's funny but the first thing I thought of as well, is making a fractal plotter where frames are iterations :)

From what I know now, if you want some advanced per pixel processing, it all has to be written in scriptclip strings. It's one of the things that bug me about avisynth, perhaps if we could have some kind of Startframe { .... code .. } endframe where we can write huge functions.

update: resize worked, but I'm worried about "The resize functions optionally allow fractional cropping of the input frame, this results in a weighting being applied to the edge pixels being resized. These options may be used if the mod-n format dimension restriction of crop are inconvienient." (http://72.14.203.104/search?q=cache:DODSQyz-YR0J:www.avisynth.org/mediawiki/wiki/Crop+avisynth+crop&hl=en&gl=ca&ct=clnk&cd=7)

IanB
7th November 2006, 03:20
@jmac698,

What are you worried about? Play with this scriptBlankClip(21, 14, 14, pixel_type="RGB32", color=$808080)
AddBorders(1,1,1,1,$000000)
AddBorders(1,1,1,1,$FFFFFF)
Animate(0, 20, "TestIt", -10, 10)
Function TestIt(Clip C, int T) {
Return C.PointResize(512, 512, T/5.0, T/5.0)
}

And oops there is a boundary error in the BilinearResize doing this :(

jmac698
7th November 2006, 03:47
I hope you posted a bug report to yourself :)
And I learned something about Animate, maybe now I'll make that fractal plotter :)