Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- patch_explorer :
- N=32
- P=17
- -v -
- P2={int($P/2)} P1={$P-$P2-1}
- -nm[-1] img
- # Select initial patch.
- -v + -e[^-1] "Select a patch." -v -
- -w[img] -1,-1,1,0,"Select a patch"
- -do
- -wait[0]
- x=@{!,x}
- y=@{!,y}
- -if {$x>=0}
- --rectangle[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2},0.5,255,255,0
- -rectangle[-1] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2},1,0xFFFFFFFF,0,255,0
- -text_outline[-1] "Coords : ("$x","$y")",2,2,13,2,1,255,255,255
- -w[-1] -rm[-1]
- --crop[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2}
- -r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
- -w1[-1] 300,300,0,0,"Patch view" -rm[-1]
- -endif
- -while {@!" && "!@{!,b}}
- -if @! -v + -e[0--3] "Patch selected at ("$x,$y")." -v -
- -else -v + -e[0--3] "No patch selected. exiting." -return
- -endif
- # Compute SSD with selected patch, and get N best matchs.
- -v + -e[^-1] "Compute similar patchs." -v -
- -i[visu] [img]
- x0=$x y0=$y
- --crop[img] {$x0-$P1},{$y0-$P1},{$x0+$P2},{$y0+$P2} -nm[-1] patch
- --ssd_patch[-2,-1] 0,0 -nm[-1] ssd
- -repeat $N
- xyzc=@{ssd,c} x={arg(1,$xyzc)} y={arg(2,$xyzc)} ssd=@{ssd,($xyzc)}
- -rectangle[ssd] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},1,inf
- -rectangle[visu] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},{1/(1.5+$>)},0,255,0
- -rectangle[visu] {$x-$P1},{$y-$P2},{$x+$P1},{$y+$P2},1,0xFFFFFFFF,0,255,0
- ($ssd,$x,$y)
- -done
- -rm[ssd]
- -a[-$N--1] y -nm[-1] best
- --r[patch] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0 -w1[-1] 300,300,0,0,"Reference patch" -rm[-1]
- -w[] -1,-1,-1,-1,"Best matches"
- # Compute best patch mosaic.
- -repeat $N
- ssd=@{best,(0,$>)}
- x=@{best,(1,$>)}
- y=@{best,(2,$>)}
- --crop[img] {$x-$P1},{$y-$P1},{$x+$P2},{$y+$P2}
- -r[-1] 80,80,1,3,3 -frame[-1] 1,1,0 -frame[-1] 20,20,255
- -text[-1] "\#"$>" SSD="{_sqrt($ssd)},5,2,13,1,0
- -frame[-1] 1,1,0
- -done
- --[-$N--1] 255 -append_tiles[-$N--1] , -+[-1] 255
- -w4[-1] -1,-1,0,0,"Mosaic of best patchs"
- # Explore patchs
- -v + -e[^-1] "Start patch exploration." -v -
- -do
- -wait[0]
- x=@{!,x}
- y=@{!,y}
- -if {$x>=0}
- 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
- xn=@{best,(1,$i)} yn=@{best,(2,$i)} ssdn=@{best,(0,$i)}
- [visu] -rectangle[-1] {$xn-$P1},{$yn-$P2},{$xn+$P1},{$yn+$P2},0.5,255,255,0
- -text_outline[-1] "Coords : ("$x","$y")",2,2,13,2,1,255,255,255
- -w[-1] -rm[-1]
- --crop[img] {$xn-$P1},{$yn-$P1},{$xn+$P2},{$yn+$P2}
- --r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
- -text_outline[-1] "SSD^1/2 : "{_sqrt($ssdn)}"\nRank \#"{$i+1},2,2,13,2,1,255,255,255
- -w3[-1] 300,300,0,0,"Patch view" -rm[-1]
- --[-1] [patch] -norm[-1] -r[-1] 300,300 -grid[-1] {100/$P}%,{100/$P}%,0,0,1,0
- -w2[-1] 300,300,1,0,"Patch difference" -rm[-1]
- -endif
- -while @!
- -rm
- -v +
Add Comment
Please, Sign In to add comment