View Full Version : Histogram as array
jmac698
7th August 2014, 05:20
Is there any plugin that makes a histogram by plotting the count along the x-axis like, x=0 has the count for all pixels in the source of luma=0?
I'd like the source to be the full frame area, and yes it will overflow so bonus if it can scale (normalized to min/max count).
jmac698
7th August 2014, 17:51
ok, I can't seem to spot the problem here, expecting a white pixel at x=32
gscript("""
source=blankclip(pixel_type="YV12",color_yuv=$208080,width=64,height=64).trim(0,-1)
result=blankclip(pixel_type="YV12",color_yuv=$028080,width=256,height=8).trim(0,-1)
w=source.width
h=source.height
source
for (i=0,255,1){
n=int(RT_YInRange(source,lo=i,n=0)*255)
putpixel(result,i,0,n)
}
""")
result
putpixel(128,2,200)
Function PutPixel(clip clip, int x, int y, int luma) {
#Plot a pixel
clip
ClipIsYV12=IsYV12
ClipIsYV12 ? ConvertToYUY2 : last
pointresize(width*2, height)
u=128
v=128
luma >255?255:luma
pixel=blankclip(last, color_yuv=luma*65536+u*256+v, width=2, height=1)
layer(last, pixel, "add", 256, x*2, y)#Layer only works with YUY2
pointresize(width/2, height)
ClipIsYV12 ? ConvertToYV12 : last
}
Thanks to rt_stats and gscript.
hmm do I need a scriptclip?
jmac698
7th August 2014, 18:38
ok, got it to work like this:
source=blankclip(pixel_type="YV12",color_yuv=$208080,width=64,height=64).trim(0,-1)
blankclip(pixel_type="YV12",color_yuv=$028080,width=256,height=40).trim(0,9)
scriptclip("""
GImport("C:\Users\user\Videos\comets6\gscript.avs")
""")
gscript.avs:
#Plot histogram array
for (i=0,255,1){
n=int(RT_YInRange(source,lo=i)*255)
putpixel(i,0,n)
}
Function PutPixel(clip clip, int x, int y, int luma) {
#Plot a pixel
clip
ClipIsYV12=IsYV12
ClipIsYV12 ? ConvertToYUY2 : last
pointresize(width*2, height)
u=128
v=128
luma >255?255:luma
pixel=blankclip(last, color_yuv=luma*65536+u*256+v, width=2, height=1)
layer(last, pixel, "add", 256, x*2, y)#Layer only works with YUY2
pointresize(width/2, height)
ClipIsYV12 ? ConvertToYV12 : last
}
But I had some problems using ScriptClip(""" """)
jmac698
8th August 2014, 01:58
This is several times faster:
source=blankclip(pixel_type="YUY2",color_yuv=$208080,width=64,height=64).trim(0,9)
blankclip(pixel_type="YUY2",color_yuv=$028080,width=256,height=40).trim(0,9)
scriptclip("""
GImport("C:\Users\user\Videos\comets6\gscript.avs")
""")
gscript.avs:
#Plot histogram array
#this is a speed optimization for plot, also because you can't create 1 pixel clips to layer
pointresize(width*2, height)
u=128#colour of pixel
v=128
uv=u*256+v
for (y=0,3,1){
for (i=0,255,1){
n=int(RT_YInRange(source,lo=i,y=y,h=1)*255)
pixel=blankclip(last, color_yuv=n*65536+uv, width=2, height=1)
layer(last, pixel, "add", 256, i*2, y)
}
}
So if you ever wanted to make your own histogram display, here ya go!
TheFluff
8th August 2014, 04:44
uv=u*256+v
color_yuv=n*65536+uv
not that it matters, but those constants should almost certainly be 255 and 65535 respectively
it's particularly confusing since you correctly use 255 in some other places
jmac698
8th August 2014, 04:50
Most definitely not, I'm doing the equivalent of a bit shift.
It turns out to be too slow for a full frame anyhow. A lot of time is spent in layer, but if I had a real plot it might be usable. Oh well, back to my other language (best tool for the job, yep.. but a lot more work do do the visualization).
Gavino
8th August 2014, 08:56
This is several times faster:
source=blankclip(pixel_type="YUY2",color_yuv=$208080,width=64,height=64).trim(0,9)
blankclip(pixel_type="YUY2",color_yuv=$028080,width=256,height=40).trim(0,9)
scriptclip("""
GImport("C:\Users\user\Videos\comets6\gscript.avs")
""")
gscript.avs:
#Plot histogram array
#this is a speed optimization for plot, also because you can't create 1 pixel clips to layer
pointresize(width*2, height)
u=128#colour of pixel
v=128
uv=u*256+v
for (y=0,3,1){
for (i=0,255,1){
n=int(RT_YInRange(source,lo=i,y=y,h=1)*255)
pixel=blankclip(last, color_yuv=n*65536+uv, width=2, height=1)
layer(last, pixel, "add", 256, i*2, y)
}
}
Putting GImport() inside ScriptClip() means the file must be opened and read again for every frame. The following should be faster (though since most of the time is spent in the inner loop anyway, the relative improvement might be small):
GImport("C:\Users\user\Videos\comets6\gscript.avs") # or just put code in-line, with GScript
source=blankclip(pixel_type="YUY2",color_yuv=$208080,width=64,height=64).trim(0,9)
blankclip(pixel_type="YUY2",color_yuv=$028080,width=256,height=40).trim(0,9)
scriptclip("Plot(source, current_frame)")
gscript.avs:
function Plot(clip c, clip source, int current_frame) {
#Plot histogram array
#this is a speed optimization for plot, also because you can't create 1 pixel clips to layer
c
pointresize(width*2, height)
u=128#colour of pixel
v=128
uv=u*256+v
for (y=0,3,1){
for (i=0,255,1){
n=int(RT_YInRange(source,lo=i,y=y,h=1)*255)
pixel=blankclip(last, color_yuv=n*65536+uv, width=2, height=1)
layer(last, pixel, "add", 256, i*2, y)
}
}
}
jmac698
8th August 2014, 09:04
Thanks for the tip but, I only need to see one or two frames in this case, not exactly encoding it just looking at it. I think a quotes issue was affecting me before, but I think I like the two files because it's all colour coded in the editor.
Which do you think is faster, blankclip+stack or layer?
StainlessS
8th August 2014, 12:30
When I get around to it, I'll do a DB utility to read a Histogram (for Y only) into a 256xDB, and another to plot a 256xDB
(you can fiddle with the YtoUV stuff).
I've already done something a bit like that for myself.
PS, give stack a try.
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.