View Full Version : New Plugin: MinMax
jmac698
15th October 2011, 13:21
I'd like to use masktools to find the minimum luma on each line. Manao made the suggestion to recursively use a small list of relative coordinates.
I am using mt_luts(last, last, mode="min", pixels="-1 0 0 0", expr="y")
So we have a line like
6 5 4 3 2 1 255 255
But the filter is processed from right to left, after luts:
6 5 4 3 2 1 255 255
Then he suggests resizing in half to save work, but the right half is deleted in YUV modes, so we have to do it specially with
pointresize(last.width/2,last.height,1,0,last.width,last.height):
5 3 1 255
After further iterations:
5 3 1 1
3 1 255 255
3 1 1 255
1 255
A couple problems, you can't keep halving the size unless you padded it out to the nearest power of 2, or typically abou 1024. The padding should be luma=255.
The final answer is the first pixel. I need to expand that back to the original width.
I guess I could do one more luts then pointresize.
Is that going to work?
jmac698
15th October 2011, 19:33
I came up with this but it's quite slow, but faster than the alternative:
colorbars(pixel_type="YV12",width=64)
findmin_h(last, last.width, 0)
function findmin_h(clip m, int w, int i){
#make the luma of each line the minimum luma of that line, w and width of clip should be power of maxconv
maxconv=2#maximum width of relative coordinates line, operation count is approx (searchwidth-(maxconv-1))*maxconv
n=ceil(log(w)/log(maxconv))-1
linecoord=mt_freerectangle(1-maxconv, 0, 0, 0)#Create a line starting with (0,0) (right line)
#this is slow part
i==n?mt_luts(m, m, mode="min", pixels=linecoord, expr="y").pointresize(w,m.height):findmin_h(mt_luts(m, m, mode="min", pixels=linecoord, expr="y").pointresize(m.width/2,m.height,1,0,m.width,m.height), w, i+1)
Which is better than:
function findmin_h(clip m, int off, int searchwidth){
#make the luma of each line the minimum luma of that line
linecoord=mt_freerectangle(1-searchwidth,0,searchwidth-1,0)#Create a line covering +- whole width
#this is slow part
mt_luts(m, m, mode="min", pixels=linecoord, expr="y", w=searchwidth, offX=off)
}
Which is searching for the minimum searchwidth times (about searchwidth^2 operations)
LaTo
15th October 2011, 21:19
Yes, or write a very small plugin in 5 minutes chrono: here (http://latoninf.free.fr/div/minmax.7z)
(videos in deus ex are sometime lengthy and painful, so 'voila'... ;))
edit: not tested, but should work
jmac698
15th October 2011, 22:01
wow! Thanks - that just saved hours of work :)
It works. Surprising however, it's still fairly slow for real C code.
The template will allow me to make my own, once I get the environment set up I should be going plugin crazy :)
johnmeyer
15th October 2011, 23:32
I may not be understanding what you are trying to do, but if the goal is to find the maximum (or minimum) pixel luma value, don't the YPlaneMax and YPlaneMin AVISynth functions provide this?
If the goal is to find the min or max on a particular single scan line, can't you use the Crop function to create a clip that is just one pixel high, and then use these two functions to find the min and/or max?
Finally, if you want to know the actual pixel location, then you have to do some sort of recursion, which is difficult, but I think there are some external AVISynth functions that help you do things that are near-impossible using ScriptClip.
jmac698
15th October 2011, 23:37
Yep, I can crop and find YPlaneMin, but I need to do it for every line. I could have done it using my splitbylines script, but that's slow.
The next step is to color the entire line the min value. I don't know any easy way to do this. Now we have a plugin that does all these steps. There is an easy way to find a pixel location, just merge with a luma ramp, which I've done in my fast line shifter script.
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.