Recensubs HQ

Diffmask e Shift, ennesime funzioni che faccio perché sono scemo

« Older   Newer »
  Share  
view post Posted on 26/9/2016, 20:05     +1   +1   -1
Avatar

Bimbosp

Group:
Administrator
Posts:
9,780
Reputation:
+929
Location:
Gallarate (VA)

Status:


Mi ritrovo a encodare dopo mesi e TAAAC mi ritrovo a fare una funzione.

Solita situazione, mi serviva fare una cosa, ho riflettuto che è una cosa che faccio abbastanza spesso, per cui ho deciso di pulire il codice e renderlo generico per eventuali necessità future (e per condividerlo con altri sciagurati, sai mai che possa tornare utile).

A questo giro mi serviva un mask basato sulla differenza col frame precedente, nulla di particolare. È una cosa che ho fatto spesso, e a 'sto giro mi ero stancato di riscrivere da capo qualche lut e roba varia, per cui eccovi serviti:

CODICE
#diffmask v1.0 by mirkosp
#compares clip c and d
#thr is the threshold value
#values equal or higher than it will become 255 for the mask
#values lower will be 0 if bin is true, otherwise they will be scaled so that thr would equal 255
#requires masktools2

function diffmask (clip c, clip d, int "thr", bool "bin", int "u", int "v") {
thr = default(thr,6)
bin = default(bin,false)
u = default(u,1)
v = default(v,1)
mt_makediff(c,d,u=u,v=v).mt_lut("x 128 - abs "+string(thr)+" < x 128 - abs "+string((bin ? 0 : round(255.0/thr)))+" * 255 ?")
}


Diffmask è un semplice filtro che genera una maschera basandosi sulla differenza. La comodità è prevalentemente per i valori intermedi di thr che vengono scalati automaticamente.

CODICE
#shift v1.0 by mirkosp
#gives out a shifted clip by the amount of frames specified
#for instance 1 will make it so that the next frame is shown where the current frame is
#likewise, -1 will show the previous frame compared to the current

function shift(clip c, int shift) {
assert(shift != 0, "just use last, bro")
(shift < 0) ? blankclip(c,abs(shift))+c.trim(0,c.framecount-(abs(shift)+1)) : c.trim(shift,0)+blankclip(c,shift)
}


Shift invece shifta il clip dei frame richiesti. Con valori negativi si va ai frame precedenti, con quelli positivi ai frame successivi. Ovviamente con 0 dà errore, perché sarebbe identico a last, per cui inutile.

Due funzioncine che, assieme, tornano utili quando devo fare i mask confrontando col frame precedente o successivo. È roba che facevo anche spesso, eppure non m'era mai venuto in mente di scrivermi qualche funzioncina per semplificarmi la vita. Ovviamente, sfruttando queste due assieme, il massimo del pesaculismo è riunito nelle seguenti funzioni:

CODICE
function maskprev(clip c, int "thr", bool "bin", int "u", int "v") {
thr = default(thr,6)
bin = default(bin,false)
u = default(u,1)
v = default(v,1)
diffmask(c,c.shift(-1),thr,bin,u,v)
}

function masknext(clip c, int "thr", bool "bin", int "u", int "v") {
thr = default(thr,6)
bin = default(bin,false)
u = default(u,1)
v = default(v,1)
diffmask(c,c.shift(1),thr,bin,u,v)
}


Che danno il mask con la differenza dal frame precedente o dal frame successivo.


Bene, ho fatto il mio post inutile periodico, ciao.
 
Web  Top
0 replies since 26/9/2016, 20:05   186 views
  Share