Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum New Plugin: MinMax
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 15th October 2011, 13:21 #1  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,865 New Plugin: MinMax 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? Last edited by jmac698; 15th October 2011 at 22:02.
 15th October 2011, 19:33 #2  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,865 I came up with this but it's quite slow, but faster than the alternative: Code: ```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: Code: ```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) Last edited by jmac698; 15th October 2011 at 20:00.
 15th October 2011, 21:19 #3  |  Link LaTo LaTo INV.     Join Date: Jun 2007 Location: France Posts: 701 Yes, or write a very small plugin in 5 minutes chrono: here (videos in deus ex are sometime lengthy and painful, so 'voila'... ) edit: not tested, but should work __________________ AutoAdjust SmoothAdjust MCTemporalDenoise LSFmod GradFun2DBmod Last edited by LaTo; 15th October 2011 at 21:23.
 15th October 2011, 22:01 #4  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,865 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
 15th October 2011, 23:32 #5  |  Link johnmeyer Registered User   Join Date: Feb 2002 Location: California Posts: 2,437 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.
 15th October 2011, 23:37 #6  |  Link jmac698 Registered User   Join Date: Jan 2006 Posts: 1,865 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.