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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 4th December 2012, 19:14   #61  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
StainlessS,
I wondered if RT_[R,G,B,A]Plane... functions would be useful for RGB32 clips.


Especially for this advanced challenge: BlankClip(color=...) allows to create a 1x1 RGB32 clip with color being a 32bit variable.
Code:
ColorBars(pixel_type="RGB32")
Layer(BlankClip(pixel_type="RGB32",color=$60101010))
I.e. the 4 [A,R,G,B] bytes could be used to store one frame specific value with a reasonable resolution for many integer or float applications.

As an alternative and opposed to a ConditionalReader or RT_ReadTxtFromFile file, the clip benefits from AviSynth's frame cache, does not suffer from file system overhead, and should to my expectation not slow down too much with very high frame numbers.

With a function like RT_AverageARGB() or RT_ARGBPlanesMin() or whatever, the full 32bit value could hopefully be retrieved and used.

With StackHorizontal(), multiple 1x1 clips could be assembled to one and be read out with RT_AverageRGBA(x=..., w=1,h=1).

Too weird?
martin53 is offline   Reply With Quote
Old 5th December 2012, 09:35   #62  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
Hi,
I've finally had an opportunity to use your plugin! But I'm having problems.
I have an rgb clip and I want to autocrop all the way around, per frame. In other words, this is a kind of tracking object thing.
Even worse, I need to scan all frames, find the max size, then render all frames at this max size and center each frame inside it.
Think of it this way, it's a video of a planet that's moving across the frame. The entire frame is black except one object. I need to show only this object centered on each frame. The frame size has to be consistent.
Think you could come up with something like that?
jmac698 is offline   Reply With Quote
Old 5th December 2012, 09:52   #63  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
I haven't been able to get it to crop at all. If I set samples too high it takes several minutes. Maybe this can't be done without a plugin?
Here's my files:
http://www.sendspace.com/file/wlcoa8

And my script:
Code:
dir="C:\Users\StainlessS\Pictures\moon\"
#IMG_5245 IMG_5288
s=5245
e=5288
imagereader(dir+"IMG_%04d.jpg",s,e,24,true)
#~ Function QueryBorderCrop(clip c,int "Samples",Float "Thresh",bool "Laced",int "XMod",int "YMod",int "WMod",int "HMod", \
    #~ bool "Relative", String "Prefix",int "RLBT",bool "DEBUG",float "Ignore",int "Matrix")
v=QueryBorderCrop(samples=1,laced=false,xmod=1,ymod=1,wmod=1,hmod=1)
#messageclip(v)
eval(v)
#QBCropX=8 QBCropY=8 QBCropW=640 QBCropH=480
Crop(QBCropX,QBCropY,QBCropW,QBCropH)
jmac698 is offline   Reply With Quote
Old 5th December 2012, 10:39   #64  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Jmac, see here: http://forum.doom9.org/showthread.ph...22#post1589022

I modded QueryBorderCrop for that script and made it super sensitive for single frames. Give it a whirl.
(by the way, QueryBorderCrop is way better than AutoCrop).

Quote:
Originally Posted by martin53 View Post
StainlessS,
could you extend RT_TxtWriteFile(String,String,bool "append") to be able to append to an existing file?
Good as done. (thinking about other suggestions).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 5th December 2012, 11:09   #65  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
It's sort of working, fails after frame 17 though. Maybe there's some bright pixel entering the frame. But for the frames that it works, it's jumping around a lot.
jmac698 is offline   Reply With Quote
Old 5th December 2012, 12:09   #66  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Try the update just posted, not any great improvement, just allows using exact crop coords (RGB).
I'll keep playing with it for a bit.

EDIT: The main problem is, the autocrop is intended to remove real borders, and there aint any.
You would need to find a good Thresh setting.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th December 2012 at 12:13.
StainlessS is offline   Reply With Quote
Old 5th December 2012, 12:38   #67  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Jmac, you have white edges left and bottom, crop them off in scripts and perhaps try an explicit rather than auto Thresh.

EDIT: Forget above, I forgot there is protection against just a very thin line at edges.
We are getting somewhere, I shall post a slight amendment to the QueryBorderCrop
script soon that should ONLY be used on this as a one off.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th December 2012 at 13:31.
StainlessS is offline   Reply With Quote
Old 5th December 2012, 13:51   #68  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Jmac, make this temporary mod to QueryBorderCrop

Code:
        #Rgt=w/2 Bot=h/2 Lft=Rgt-1 Top=Bot-1
        Rgt=Int(w*0.1) Bot=Int(h*0.1) Lft=Int(w*0.9) Top=Int(h*0.9)		# Mod For JMAC698
Normally searches only left half of image for left border, mod allows search 90% of width instead for your ODD requirement,
same for other sides.

Make this mod
Code:
AUTOCROP_THRESH = -3.0													# Default -32
CROPMODE        = 0
To this script: http://forum.doom9.org/showthread.ph...43#post1604043

Not prefect BUT, works pretty damn good [better than I might have expected]
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 5th December 2012 at 14:01.
StainlessS is offline   Reply With Quote
Old 5th December 2012, 15:07   #69  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Jmac, Use This Version

Code:
# EDIT To Suit (Requires QueryBorderCrop v1.09 & QueryLumaMinMax v1.01 & RT_Stats v1.06)

VID = False                                                                 # True == Video : False == Pics, see IN_FILES directories/wildcards

IN_FILES = (VID) ? "D:\VID\*.AVI|MPG|MPEG" : "D:\MOON\*.BMP|JPG|JPEG|PNG"   # Added '|' Pipe separator for multiple Wildcard in Extensions ONLY.
AUTOCROP            = True                                                  # Crop off black borders.
AUTOCROP_THRESH     = 0.6   # Default 0.0 allows QueryBorderCop to auto set super sensitive mode for single images, use default 0.0 normally
SHOWBORDER          = True                                                  # True Show replaced border in Red, else Black. (Test AUTOCROP)
AUTOLEVEL_STRENGTH  = 1.0                                                   # AutoLevel Strength 0.0 -> 1.0
SHOWAUTOLEVEL       = False                                                 # Right Hand Side Only AutoLeveled
#
#FAR                 = 4/3.0                                                # Required Frame Aspect Ratio
FAR                 = 1.0                                                   # Required Frame Aspect Ratio
SzLimit             = 0                                                     # Limit shorter size (usually height, see FAR). 0 Does NOT Resize.
DEBUG               = True                                                  # Debug
CROPMODE            = 0                                                     # 0=CropExact(RGB Only), 1=CropLess, 2=CropMore, 3=CropPlus
WMOD                = 2
HMOD                = 2
# ---------------------
# Lesser changed settings
BORDER      = (SHOWBORDER) ? $FF0000: (VID) ? $101010 : $000000             # Color for replaced borders.
SUBS        = False          # Subtitles on clips/images
DEBUG_QBC   = False                                                         # Debug QueryBorderCrop
DEBUG_QLMM  = False                                                         # Debug QueryLumaMinMax
FPS         = (VID) ? 30000.0/1001.0 : 1.0                                  # Whatever.
OUT_FILE    = "FILE.List"   # Dont need to change really, just a name.
SCANPERC    = 90.0                                                          # Percentage of each side to scan in AutoCrop, see below link for reason.
#                                                                           # http://forum.doom9.org/showthread.php?p=1604004#post1604004
#--------------------------------------------------------------------------------
GScript("""
    picclip = 0                                                                 # Dummy for now
    result=RT_WriteFileList(IN_FILES,OUT_FILE)                                  # Create a listing file of Pic files
    Assert((result!=0), "No files found")
    FILELIST=RT_ReadTxtFromFile(OUT_FILE)                                       # Get list of files
    FILES=RT_TxtQueryLines(FILELIST)                                            # Query Number of lines in String ie number of files.
    (DEBUG) ? RT_Debug("Found files = " + String(FILES)) :NOP
    # Prescan to ascertain max wid/hit of all files, also Autocrop & Auto Levels
    MAXH=0 MAXW=0                                                               # init max wid and hit
    CROPCOORDS=""                                                               # Clear results array (string)
    AUTOLEVELS=""                                                               # Clear AutoLevels array (string)
    AUTOLEVEL=(AUTOLEVEL_STRENGTH>0.0)                                          # Adjust using Levels.
    QBCTrailer=Select(CROPMODE,"=","L=","M=","P=")
    For(i=0,FILES-1) {
        FN=RT_TxtGetLine(FILELIST,i)                                            # Filename of pic/vid file i
        (DEBUG)?RT_Debug(String(i+1)+"/"+String(FILES)+") Getting File dimensions",FN):NOP
        if(VID) {
            k=DirectshowSource(FN)
            k=k.ConvertToYUY2().Trim(0,0)
        } else {
            k=ImageReader(FN,end=0).ConvertToRGB32()                            # With Bmap, some come up as RGB24 bit some RGB32.
        }
        OrgW=k.width    OrgH=k.height
        W=OrgW          H=OrgH                                                  # Pre-Duplicate in case of no AUTOCROP
        if (AUTOCROP) {
            if(AUTOCROP_THRESH == 0.0) { # Call without Thresh arg, allows use of auto super sensitive setting for single frame images
                QBC = k.QueryBorderCrop(samples=24,laced=VID,debug=(DEBUG&&DEBUG_QBC),ScanPerc=ScanPerc)
            } else { # Will prevent auto super sensitive from working, use on images with real borders
                QBC = k.QueryBorderCrop(samples=24,Thresh=AUTOCROP_THRESH,laced=VID,debug=(DEBUG&&DEBUG_QBC),ScanPerc=ScanPerc)
            }
            Eval(QBC)                                               # Set Avisynth vars
            k=k.Crop(QBCropXM,QBCropYM,QBCropWM,QBCropHM)           # OVERCROP using CropMore
            QBC = RT_TxtGetLine(QBC,CROPMODE)                       # Extract REQUIRED mode, CropLess, CropMore etc
            QBC1=StrReplace(QBC,QBCTrailer,"=")                     # Change all to style without a trailer eg QBCropXM to QBCropX.
            QBC2=StrReplace(QBC1,"QBC","C")                         # Change all style QBCropX to CropX  
            Eval(QBC2)                                              # Get the required cropmode into CropX,CropY,CropW,CropH
            W=CropW    H=CropH                                      # The actual required crop mode dimensions.
            CROPCOORDS=RT_TxtAddStr(CROPCOORDS,QBC2)                # Avisynth Bugfix, same as CROPCOORDS = CROPCOORDS + QBC + Chr(10)
        }
        if (AUTOLEVEL) {
            QLMM = k.QueryLumaMinMax(debug=(DEBUG&&DEBUG_QLMM))     # Query luma levels (on overcropped clip if AUTOCROP)
            Eval(QLMM)                                              # Set Avisynth vars
            AUTOLEVELS=RT_TxtAddStr(AUTOLEVELS,QLMM)                # Avisynth Bugfix, same as AUTOLEVELS = AUTOLEVELS + QLMM + Chr(10)
        }
        If(MAXW<W) {MAXW=W}        
        If(MAXH<H) {MAXH=H}
        if (DEBUG) {                                                # KEEP main debug messages together
            RT_Debug ("Orig Width =",String(orgW),"Orig Height =",String(OrgH))
            if((W != OrgW) || (H != OrgH)) {                        # Was Caused by AUTOCROP
                RT_Debug("AutoCrop Width =",String(W),"AutoCrop Height =",String(H))
                (AUTOLEVEL) ? RT_Debug("AutoLevel On Cropped : Min=",String(QLMMMin)," Max =",String(QLMMMax)) : NOP
            } else {
                (AUTOCROP) ? RT_Debug("AutoCrop Found no borders") : NOP
                (AUTOLEVEL)? RT_Debug("AutoLevel NonCropped : MinLuma=",String(QLMMMin)," MaxLuma =",String(QLMMMax)) : NOP
            }
            RT_Debug("MAX Width So Far =",String(MAXW),"MAX Height So Far =",String(MAXH))
            RT_Debug(" ----------------------------- ")            # line separator
        }
    }
    maxFAR = Float(MAXW) / MAXH
    if(FAR >= maxFAR) {
        # Required Frame Aspect Ratio greater or same as maximum accumulated dimensions. Need to pad horizontal
        if(SzLimit == 0) {  # NO SIZE LIMITING, Pad Only
            canvasheight    = Int((MAXH  + (HMOD/2)) / HMOD) * HMOD
            canvaswidth     = Int((canvasheight * FAR + (WMOD/2)) / WMOD) * WMOD
        } else {            # Resize with SIZE LIMITING
            canvasheight    = (MAXH < SzLimit) ? Int((MAXH  + (HMOD/2)) / HMOD) * HMOD : MAXH
            canvasheight    = (canvasheight > SzLimit) ? SzLimit : canvasheight                 # enforce SzLimit max
            canvaswidth     = Int((canvasheight * FAR + (WMOD/2)) / WMOD) * WMOD
        }
    } else {                                                                                    # Need to pad vertical
        if(SzLimit == 0) {  # NO SIZE LIMITING, Pad Only
            canvaswidth     = Int((MAXW  + (WMOD/2)) / WMOD) * WMOD
            canvasheight    = Int((canvaswidth / FAR + (HMOD/2)) / HMOD) * HMOD
        } else {            # Resize with SIZE LIMITING
            canvaswidth     = (MAXW < SzLimit) ? Int((MAXW  + (WMOD/2)) / WMOD) * WMOD : MAXW
            canvaswidth     = (canvaswidth > SzLimit) ? SzLimit : canvaswidth                   # enforce SzLimit max
            canvasheight    = Int((canvaswidth / FAR + (HMOD/2)) / HMOD) * HMOD
        }
    }    
    if(DEBUG){RT_Debug("SETTING CanvasWidth =",String(canvaswidth)," CanvasHeight =",String(canvasheight))}
    if(DEBUG){RT_Debug(" ----------------------------- ")}       # line separator
    For(i=0,FILES-1) {
        FN=RT_TxtGetLine(FILELIST,i)         # Filename of pic/vid file i
        if(DEBUG){RT_Debug(string(i+1)+"/"+String(FILES)+")","Processing File",FN)}
        if(VID) {
            k=DirectshowSource(FN).ConvertToYUY2().Trim(0,0)
        } else {
            k=ImageReader(FN,end=0).ConvertToRGB32()                                    # RGB24 problems with addborders
        }
        OrgH=k.height    OrgW=k.width

        if (AUTOLEVEL) {
            # We do AUTOLEVELS before crop, because of SHOWAUTOLEVEL
            QAT = RT_TxtGetLine(AUTOLEVELS,i)
            Eval(QAT)
            if(k.IsYUV()) {
                CSMin = 16
                CSMax = 235
            } else {        
                CSMin = 0
                CSMax = 255
            }
            TMP_K=k         
            ALMin = Int(CSMin - ((CSMin - QLMMMin) * AUTOLEVEL_STRENGTH) + 0.5) # Round Up
            ALMax = Int(CSMax - ((CSMax - QLMMMax) * AUTOLEVEL_STRENGTH))       # Round down
            k = k.Levels(ALMin,1.0,ALMax,CSMin,CSMax,Coring=False)              # DONT EVER USE Coring 
            (DEBUG) ? RT_Debug("Levels("+String(ALMin)+",1.0,"+String(AlMax)+","+String(CSMin)+","+String(CSMax)+",Coring=False)") : NOP

            if(SHOWAUTOLEVEL) {
                tmpw=int((k.width/4)*2)
                Left = TMP_K.Crop(0,0,tmpw,-0)
                Right= k.Crop(tmpw,0,-0,-0)
                k=StackHorizontal(Left,Right)               
            }
        }
        if (AUTOCROP) {
            QBC = RT_TxtGetLine(CROPCOORDS,i)                                   # Get required coords from first pass
            Eval(QBC)                                                           # Set variables in Avisynth, ie CropX etc
            k=k.Crop(CropX,CropY,CropW,CropH)       
            (DEBUG)? RT_Debug("Crop("+String(CropX)+","+String(CropY)+","+String(CropW)+","+String(CropH)+")") : NOP
        }
        iWidth=k.Width()        iHeight=k.Height()        
        cFAR    = Float(canvaswidth) / canvasheight
        iFar    = Float(iWidth) / iHeight
        Left=0 Top=0 Right=0 Bot=0

        if(SzLimit==0) {
            Left    =   (canvaswidth-iWidth) / 2
            Right   =   canvaswidth-iWidth - Left
            Top     =   (canvasheight-iHeight) / 2
            Bot     =   canvasheight-iHeight-Top
            owid    =   iWidth
            oHit    =   iHeight
            (DEBUG) ? RT_Debug("AddBorders("+String(Left)+","+String(Top)+","+String(Right)+","+String(Bot)+")") : NOP
            k = k.Addborders(Left,Top,Right,Bot,BORDER)
        } else {
            if(cFAR >= iFAR) {  # Canvas Aspect ratio greater (proportionally wider), resize to vertical and pad horizontal
                oHit    =   canvasheight
                oWid    =   Int(oHit*iFAR/4)*4
                Left    =   (canvaswidth-oWid) / 2
                Right   =   canvaswidth - oWid - Left           
            } else {            # Canvas Aspect ratio smaller (proportionally taller), resize to horizontal and pad vertical
                oWid    =   canvaswidth
                oHit    =   Int(oWid/iFAR/4)*4
                Top     =   (canvasheight-oHit) / 2
                Bot     =   canvasheight - oHit - Top
            }
            if(DEBUG) {
                RT_Debug("Spline36Resize("+String(oWid)+","+String(oHit)+")")
                RT_Debug("AddBorders("+String(Left)+","+String(Top)+","+String(Right)+","+String(Bot)+")")
            }
            k = k.Spline36Resize(oWid,oHit).Addborders(Left,Top,Right,Bot,BORDER)
        }
        k=k.assumefps(fps)
        if(SUBS) {
            k=k.subtitle(String(i) + "/"+String(FILES-1) +" " + FN)
            k=k.subtitle("Orig  width=" + string(orgW) +" "  + "Orig  height=" + string(orgH) +" FAR="+String(Float(orgW) /orgH, "%.2f"),20,20)
            if (AUTOCROP) {k=k.subtitle("Crop width=" + string(iWidth) +" "  + "Crop  height=" + string(iHeight) +" FAR="+String(Float(iWidth) /iHeight, "%.2f"),20,40)
            } else {k=k.subtitle("NO AUTOCROP",20,40)}
            k=k.subtitle("New width=" + string(oWid) +" " + "New height=" + string(oHit)+" FAR="+String(Float(oWid)/oHit,"%.2f"),20,60)         
            k=k.subtitle("Out width=" + string(k.Width) +" " + "Out height=" + string(k.Height)+" FAR="+String(Float(k.Width)/k.Height,"%.2f"),20,80)         
            if(AUTOLEVEL) {
                k=k.subtitle("QLMMMin = " + String(QLMMMin) + " QLMMMax = " +String(QLMMMAx),20,120)
                k=k.subtitle("AUTOLEVEL @ " + String(AUTOLEVEL_STRENGTH*100.0,"%.0f") + "%",20,140)
                k=k.subtitle("Auto Levels(" + String(ALMin) + ",1.0," + String(ALMAx) + "," + String(CSMin) + "," + String(CSMax) + ")",20,100)
            } else {k=k.subtitle("NO AUTOLEVEL",20,100)}
        }
        picclip = (IsClip(picclip)) ? picclip ++ k : k              # Append to  clip so far
        if(!VID){k=k.ConvertToRGB24()}
        if(DEBUG){RT_Debug(" ") RT_Debug(" ----------------------------- ")}        # line separator

    }
""")

PicClip
return Last

Function StrReplace(string s,string find,string replace) # Repeated, string replacements
# Original:- http://forum.doom9.org/showthread.php?p=1540504#post1540504           By Vampiredom, Gavino, IanB
#{i=s.FindStr(find)return(i==0?s: s.LeftStr(i-1)+replace+s.MidStr(Strlen(find)+i).StrReplace(find,replace))}
# Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:-
{i=s.FindStr(find) return(i==0?s:RT_StrAddStr(s.LeftStr(i-1),replace,s.MidStr(Strlen(find)+i).StrReplace(find,replace)))}

Function StrReplaceDeep(string s,string find,string replace) # DEEP Repeated, string replacements
# When replacing eg pairs of SPACE characters by single SPACE, StrReplace can leave some pairs non replaced.
# Assumes that you want to rescan where replaced string could constitute part of a new find substring,
# Length of replace must be shorter than length of find, else will call StrReplace instead.
# Based On:- http://forum.doom9.org/showthread.php?p=1540504#post1540504           By Vampiredom, Gavino, IanB
# {i=s.FindStr(find)return i==0?s:s.LeftStr(i-1)+( strlen(replace)<strlen(find)? \
# StrReplaceDeep(replace+s.MidStr(Strlen(find)+i),find,replace) : replace+StrReplace(s.MidStr(Strlen(find)+i),find,replace))}
# Converted to use RT_Stats RT_StrAddStr() to avoid 2.58/2.6a3 string concatenation bug:-
{i=s.FindStr(find)return i==0?s:RT_StrAddStr(s.LeftStr(i-1),( strlen(replace)<strlen(find)? \
StrReplaceDeep(RT_StrAddStr(replace,s.MidStr(Strlen(find)+i)),find,replace) : \
RT_StrAddStr(replace,StrReplace(s.MidStr(Strlen(find)+i),find,replace))))}

Updated, needs RT_Stats 1.06

EDIT: See PlanetCrop() available in RT_Stats zip (much better for this purpose).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 9th January 2013 at 16:31.
StainlessS is offline   Reply With Quote
Old 5th December 2012, 16:35   #70  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Modified previous post.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 5th December 2012, 17:05   #71  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
You're amazing, thanks for the effort! I really think that is a useful script though, there is a need in astrophotography sometimes to crop out and track planets. That's because our software, like any other, has to search the entire image to align frames, and it's very slow, and can be beyond the search radius for matching. So this type of "pre-alignment" really speeds up the programs.

I can also see me making use of this in moviemaking, to keep the frame centered on an object just by mounting a light on it. It can be used to deshake in certain situations.
jmac698 is offline   Reply With Quote
Old 5th December 2012, 17:12   #72  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
The Video Joining capability of the script is pretty handy too.

I'll implement the QueryBorderCrop mod today and do the Martin53 requested mod to RT_Stats and up within a couple of hours.

(And you said that QueryBorderCrop() would never work, hehehehe)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 5th December 2012, 18:30   #73  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
Ok, I've tried it now, and it fails on frame 13. It also seems like it's being resized.
jmac698 is offline   Reply With Quote
Old 5th December 2012, 21:12   #74  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Quote:
Originally Posted by StainlessS View Post
... and do the Martin53 requested mod to RT_Stats ...
don't hurry! Btw., I was able to write a 'proof of concept':

Code:
#==========================================
# Luma2argb puts the average luma of clip 'cMeasured' into the ARGB bytes of container clip
#
function Luma2argb(clip cMeasured) {
	cContainer = blankclip(cMeasured, pixel_type="RGB32", width=1, height=1)
	return cContainer.GScriptClip("""
		longVal = round($1000000*cMeasured.RT_AverageLuma(Matrix=2))	#longVal is supposed to be 4 bytes long: $aa,rr,gg,bb.
		return Blankclip(last, color=longVal)	#Put high byte to alpha, next bytes to red,gren,blue: easy because color parameter of function BlankClip does just this!)
	""", args="cMeasured")
}

#==============================================
# Argb2float returns a float value from ordered alpha, red, green and blue channels in the range 0...255.99999999
# inputs: clip, frame delta and current frame numbers
# output: quality
#
function Argb2float(clip c, int delta, int currentframe) {
	a = c.ShowAlpha().RT_AverageLuma(n=currentframe, delta=delta, Matrix=2)
	r = c.ShowRed().RT_AverageLuma(n=currentframe, delta=delta, Matrix=2)
	g = c.ShowGreen().RT_AverageLuma(n=currentframe, delta=delta, Matrix=2)
	b = c.ShowBlue().RT_AverageLuma(n=currentframe, delta=delta, Matrix=2)
	return a + r/$100 + g/$10000 + b/$1000000
}

c = something...
cAL = c.Luma2argb()	#cAL holds the AverageLuma of C with 32bit res.
c.GScriptClip("""
	subtitle(string(cAL.Argb2float(1, current_frame)))	#displays AverageLuma of following frame :) :) :)
""", args="cAL")

Last edited by martin53; 7th December 2012 at 21:27. Reason: supplement
martin53 is offline   Reply With Quote
Old 5th December 2012, 22:31   #75  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
RT_Stats v1.06, see 1st post.

Jmac, Post #70 updated, still playing with it, converting to CropExact has some other probs that dont quite work.

I'll try to mod for your purpose in addition to current usage.

The original script is intended to do resizing, its function is to join dissimilar pics/vids together and resizing/addborders to a required
aspect ratio and size limit. Going to the pub now, and as I have been up since about 2:00AM, probably not do anything else today.

Martin53, have updated RT_stats with append update, the RGB stuff was what I was pondering.

Dont think a good idea as suggested, AverageLuma is float return and your suggested func would not be precise enough for
uses that it may be put to. Anyways, take a look at Showchannels updated today, easily used with scriptclip.

Cheers.

EDIT: The pubs shut way too early.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 6th December 2012 at 01:56.
StainlessS is offline   Reply With Quote
Old 7th December 2012, 20:11   #76  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Jmac, post #70 updated, added No Resize functionality by setting SzLimit=0

notes here (too big for post 70, overflows limit) :
Code:
# Single Frame Super Sensitive, switched on when samples == 1 or single frame, intention to make as sensitive as possible hopefully without overcrop.
# Single frame Super Sensitive AutoThresh (arg Thresh = -ve), internally sets AutoThresh to -0.5, ie relative to YPlaneMin, == YPlaneMin + 0.5.
# Single frame Super Sensitive AutoThresh would have worked fine, was the halfway scan (ie SCANPERC==50.0%) that inhibited detection.
# YPlaneMin=0 All images, so AutoThresh of Little Use, Equivalent to Thresh = 0.5 on all frames.
# With SzLimit == 0 (NO RESIZING, Crop & AddBorders Only, and FAR == 1.0 [Frame Aspect Ratio 1:1])
#   0.5 keeps good margin all around without coming close to chopping off any Moon (954x954).
#   0.6 Close but clear margin Top, rest, bigger margin (922x922)
#   0.75 Just about touches top of moon, other sides good margin (862x862)
Still working on it but is pretty good right now, try with AUTOCROP_THRESH = 0.6

Going to try to implement keeping some of the margins instead of adding synthetic borders, to fit the
required aspect ratio (ie partially ignoring the crop coords where possible) to keep as much of the original
image as we can.

There is a problem (only with your type task). You will see that it detects very close to top/bottom of
the moon, but quite a margin left/right. This is due to the fact that we scan top and bot to find borders,
and then left and right, BUT, left/right scan only scans between the already established top and bottom
borders. With the top/bot scan a small number of lighter pixels in a vast expanse of black line requires
a very low threshold, but when we scan a much reduced vertical line length in the lft/rgt scan
(due to limiting to top/bot borders), so any approx same number or lighter pixels in the much reduced
sample line length does not require such a small thresh.
I shall try to rectify this, perhaps by adding some kind of threshold scaler based on scanline length
compared with perhaps full image width to try and achieve a comparable thresh.

Give it a whirl, works great and getting better.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 8th December 2012 at 21:02.
StainlessS is offline   Reply With Quote
Old 7th December 2012, 21:23   #77  |  Link
martin53
Registered User
 
Join Date: Mar 2007
Posts: 407
Quote:
Originally Posted by StainlessS View Post
the RGB stuff ... Dont think a good idea as suggested
StainlessS,
never mind. I think similar - it would be not generic as suggested. The 'proof of concept' works excellent. We could still get back to it and maybe handle exponent and signs of mantissa and exponent in a way that would really allow a floating point number, and maybe use 2 pixels to store 64 bits - if it fulfills a certain need better than other solutions.

for the 'append'. Cheers - enjoy the pub!
martin53 is offline   Reply With Quote
Old 7th December 2012, 21:45   #78  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Can always implement an eg RGB_AverageR etc, returning all three at once possible in string but would not really want to encourage scanning every pixel of a clip especially as strings are never released until close. Guess RGB24 could be returned in int, but not RGB32 which I'm guessing might produce some kind of overflow error when trying to extract alpha in script (maybe not, vb would overflow).

Might even be possible to take some args and manufacture a float.
(assume for your hinting thing).

Quote:
Originally Posted by martin53 View Post
Cheers - enjoy the pub!
and Cheers to you sir, I always enjoy the pub, on my way presently.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 8th December 2012 at 13:52.
StainlessS is offline   Reply With Quote
Old 8th December 2012, 21:29   #79  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
@Martin53,
Hows about this. Func to return combined rgb data (as for single clip Luma funcs, excluding comparison funcs), for all channels,
eg ave, max, min, YInRange, YPlaneMedian, YPlaneMinMaxDifference, all as Global Variables, with a user supplied Prefix.

Should be reasonably fast and no string accumulation probs. A Similar luma func could also be of use, and avoid multiple
func calls in some situations. Implemented as for RT_ luma funcs with eg laced arg and x,y,w,h.

EDIT:
@Jmac, got both "keep margin" and "thresh scaling" done, works brilliant, just a bit of tidying up to do.
Here's something to try.
EDIT: Link Removed.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 3rd January 2013 at 12:28.
StainlessS is offline   Reply With Quote
Old 9th December 2012, 11:55   #80  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,867
Tried it, working great! Wonder why it jumps a little though, did you see something in the background to mess it up?
jmac698 is offline   Reply With Quote
Reply

Tags
averageluma, correlation, lumadifference, runtime

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:20.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.