jmac698
5th August 2011, 17:38
I'm stuck in a processing operation. I need to find the running difference along a line of pixels.
new_pixel0=old_pixel0-c
new_pixel1=old_pixel1-newpixel0
new_pixel2=old_pixel2-newpixel1
...
also I need to start at a different pixel on each line. If not the very left, it spreads both ways. And it can't be ridiculously slow.
Thanks.
jmac698
5th August 2011, 18:11
I have most of it now, first I noticed luts with negative weights didn't work and switched to lutsx. Then I noticed that offx=1 didn't work so I switched to "fat" pixels. Is this a bug? I also noticed there is replication beyond the borders, which isn't documented. I should be able to use a horizontal flip to process both halfs of the line. All that remains is to do processing a different offset per line and extension to x,y offset.
I love lutsx, now I realize I can do flexible per pixel processing for the whole image!
pat="5A 64 78 80"#90, 100, 120, 128
drawpat(pat,true)#returns fat pixels (2x horizontally)
stride=1#pixel(x+stride,y)-pixel(x,y)
startx=1#where in the line to start processing
mt_lutsx(last,last,last,mode="1 0",mode2="0 1",pixels="0 0 "+string(stride*2)+" 0",expr="z y -",offx=startx*2)
pointresize(last.width/2,last.height)#undo fat mode
#mt_luts(last,last,mode="-1 1",pixels="0 0 1 0",expr="y")#this gives 0's, but mode="1 1" works as a running average
function drawpat(string pat,bool mono){
#make a line with 2x2 pixels using the colors in pat
#e.g. "108080 208080" with mono=false, "10 20" with mono=true
drawpat2(pat+" ",pixel("108080"),mono)
}
function drawpat2(string pat, clip v, bool mono){
vl=mono?2:6#length of value string
vl2=vl+1#length of value string + separator
p=leftstr(pat,vl)#the current pixel as color string
p=mono?p+"8080":p#add color if mono
pat=strlen(pat)<vl2*2?"":rightstr(pat,strlen(pat)-vl2)#the remaining pixels
#If there's no more pixels return the last pixel, otherwise stack current pixel with next pixel
pat==""?pixel(p):stackhorizontal(pixel(p),drawpat2(pat,pixel(p),mono))
}
function pixel(string c){
#make a 2x2 image of color c in yv12
blankclip(length=1,width=2,height=2,pixel_type="YV12",color_yuv=hexvalue(c))
}
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.