Guest User

Untitled

a guest
Oct 18th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.82 KB | None | 0 0
  1. patch_explorer :
  2.  
  3.   N=32
  4.  
  5.   P=17
  6.  
  7.   -v -
  8.   P2={int($P/2)} P1={$P-$P2-1}
  9.   -nm[-1] img
  10.  
  11.   # Select initial patch.
  12.   -v + -e[^-1] "Select a patch." -v -
  13.   -w[img] -1,-1,1,0,"Select a patch"
  14.   -do
  15.     -wait[0]
  16.     x=@{!,x}
  17.     y=@{!,y}
  18.     -if {$x>=0}
  19.       --rectangle[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2},0.5,255,255,0
  20.       -rectangle[-1] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2},1,0xFFFFFFFF,0,255,0
  21.       -text_outline[-1] "Coords : ("$x","$y")",2,2,13,2,1,255,255,255
  22.       -w[-1] -rm[-1]
  23.       --crop[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2}
  24.       -r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
  25.       -w1[-1] 300,300,0,0,"Patch view" -rm[-1]
  26.     -endif
  27.   -while {@!" && "!@{!,b}}
  28.   -if @! -v + -e[0--3] "Patch selected at ("$x,$y")." -v -
  29.   -else -v + -e[0--3] "No patch selected. exiting." -return
  30.   -endif
  31.  
  32.   # Compute SSD with selected patch, and get N best matchs.
  33.   -v + -e[^-1] "Compute similar patchs." -v -
  34.   -i[visu] [img]
  35.   x0=$x y0=$y
  36.   --crop[img] {$x0-$P1},{$y0-$P1},{$x0+$P2},{$y0+$P2} -nm[-1] patch
  37.   --ssd_patch[-2,-1] 0,0 -nm[-1] ssd
  38.   -repeat $N
  39.     xyzc=@{ssd,c} x={arg(1,$xyzc)} y={arg(2,$xyzc)} ssd=@{ssd,($xyzc)}
  40.     -rectangle[ssd] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},1,inf
  41.     -rectangle[visu] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},{1/(1.5+$>)},0,255,0
  42.     -rectangle[visu] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},1,0xFFFFFFFF,0,255,0
  43.     ($ssd,$x,$y)
  44.   -done
  45.   -rm[ssd]
  46.   -a[-$N--1] y -nm[-1] best
  47.   --r[patch] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0 -w1[-1] 300,300,0,0,"Reference patch" -rm[-1]
  48.   -w[] -1,-1,-1,-1,"Best matches"
  49.  
  50.   # Compute best patch mosaic.
  51.   -repeat $N
  52.     ssd=@{best,(0,$>)}
  53.     x=@{best,(1,$>)}
  54.     y=@{best,(2,$>)}
  55.     --crop[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2}
  56.     -r[-1] 80,80,1,3,3 -frame[-1] 1,1,0 -frame[-1] 20,20,255
  57.     -text[-1] "\#"$>" SSD="{_sqrt($ssd)},5,2,13,1,0
  58.     -frame[-1] 1,1,0
  59.   -done
  60.   --[-$N--1] 255 -append_tiles[-$N--1] , -+[-1] 255
  61.   -w4[-1] -1,-1,0,0,"Mosaic of best patchs"
  62.  
  63.   # Explore patchs
  64.   -v + -e[^-1] "Start patch exploration." -v -
  65.   -do
  66.     -wait[0]
  67.     x=@{!,x}
  68.     y=@{!,y}
  69.     -if {$x>=0}
  70.       i=0 d=inf -repeat $N p=@{best,(1,$>)} q=@{best,(2,$>)} nd={sqrt(($x-$p)^2+($y-$q)^2)} -if {$nd<$d} d=$nd i=$> -endif -done
  71.       xn=@{best,(1,$i)} yn=@{best,(2,$i)} ssdn=@{best,(0,$i)}
  72.       [visu] -rectangle[-1] {$xn-$P1},{$yn-$P2},{$xn+$P1},{$yn+$P2},0.5,255,255,0
  73.       -text_outline[-1] "Coords : ("$x","$y")",2,2,13,2,1,255,255,255
  74.       -w[-1] -rm[-1]
  75.  
  76.       --crop[img] {$xn-$P1},{$yn-$P1},{$xn+$P2},{$yn+$P2}
  77.  
  78.       --r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
  79.       -text_outline[-1] "SSD^1/2 : "{_sqrt($ssdn)}"\nRank \#"{$i+1},2,2,13,2,1,255,255,255
  80.       -w3[-1] 300,300,0,0,"Patch view" -rm[-1]
  81.  
  82.       --[-1] [patch] -norm[-1] -r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
  83.       -w2[-1] 300,300,1,0,"Patch difference" -rm[-1]
  84.  
  85.     -endif
  86.   -while @!
  87.   -rm
  88.   -v +
Add Comment
Please, Sign In to add comment