Advertisement
Guest User

Untitled

a guest
Jun 6th, 2013
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.67 KB | None | 0 0
  1. #@gmic boxfitting : _min_box_size>=1,_max_box_size>=0,_initial_density>=0
  2. #@gmic : Apply box fitting effect on selected images, as displayed the web page:
  3. #@gmic : [http://www.complexification.net/gallery/machines/boxFittingImg/]
  4. #@gmic : Default values: 'min_box_size=1', 'max_box_size=0' and 'initial_density=0.1'.
  5. #@gmic : $ image.jpg --box_fitting ,
  6. boxfitting : -check "isint(${1=3}) && $1>=1 && isint(${2=0}) && $2>=0 && ${3=0.1}>=0"
  7.   -e[^-1] "Apply box fitting effect on image$?."
  8.   -v -
  9.   min_size=$1
  10.   max_size={if($2,$2,max(w,h))}
  11.   -repeat @# -l[$>]
  12.     nb_try=0 prec=5
  13.     100%,100%
  14.     -repeat 1e8
  15.  
  16.       # Add random non-intersecting squares with min size.
  17.       -if {$><1} # Takes random points for the first iterations.
  18.         100%,100% -noise[-1] {max(1e-3,$3)},2
  19.       -else # Then, try to take points near the median axis of the distance function otherwise.
  20.         --distance[-1] 1 --rand[-1] 0,1 -*[-2,-1] -max_patch[-1] {round($prec*$min_size)}
  21.         prec={max(1,$prec*0.9)}
  22.       -endif
  23.  
  24.       # Discard new squares that intersect something.
  25.       -dilate[-1] $min_size -area_fg[-1] 0,1 -eq[-1] {($min_size)^2}
  26.       --dilate[-2] 3 -eq[-1] 0 -*[-2,-1] -area_fg[-1] 0,1 -eq[-1] {($min_size)^2}
  27.       -if {!iM} nb_try={$nb_try+1} -if {$nb_try>3} -rm[-1] -break -endif # If no new squares have been placed.
  28.       -else nb_try=0 -endif
  29.       -+[-2,-1]
  30.  
  31.       # Make current squares grown until max square size is reached.
  32.       -repeat {int(($max_size-$min_size)/2)}
  33.         --dilate[-1] 3 -area_fg[-1] 0,1 -eq[-1] {($min_size+2*$>+2)^2}
  34.         -if {!iM} -rm[-1] -break -endif  # No more squares to grow.
  35.         -or[-2,-1]
  36.       -done
  37.  
  38.     -done
  39.     -blend shapeaverage0
  40.   -endl -done -v +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement