Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #@gmic boxfitting : _min_box_size>=1,_max_box_size>=0,_initial_density>=0
- #@gmic : Apply box fitting effect on selected images, as displayed the web page:
- #@gmic : [http://www.complexification.net/gallery/machines/boxFittingImg/]
- #@gmic : Default values: 'min_box_size=1', 'max_box_size=0' and 'initial_density=0.1'.
- #@gmic : $ image.jpg --box_fitting ,
- boxfitting : -check "isint(${1=3}) && $1>=1 && isint(${2=0}) && $2>=0 && ${3=0.1}>=0"
- -e[^-1] "Apply box fitting effect on image$?."
- -v -
- min_size=$1
- max_size={if($2,$2,max(w,h))}
- -repeat @# -l[$>]
- nb_try=0 prec=5
- 100%,100%
- -repeat 1e8
- # Add random non-intersecting squares with min size.
- -if {$><1} # Takes random points for the first iterations.
- 100%,100% -noise[-1] {max(1e-3,$3)},2
- -else # Then, try to take points near the median axis of the distance function otherwise.
- --distance[-1] 1 --rand[-1] 0,1 -*[-2,-1] -max_patch[-1] {round($prec*$min_size)}
- prec={max(1,$prec*0.9)}
- -endif
- # Discard new squares that intersect something.
- -dilate[-1] $min_size -area_fg[-1] 0,1 -eq[-1] {($min_size)^2}
- --dilate[-2] 3 -eq[-1] 0 -*[-2,-1] -area_fg[-1] 0,1 -eq[-1] {($min_size)^2}
- -if {!iM} nb_try={$nb_try+1} -if {$nb_try>3} -rm[-1] -break -endif # If no new squares have been placed.
- -else nb_try=0 -endif
- -+[-2,-1]
- # Make current squares grown until max square size is reached.
- -repeat {int(($max_size-$min_size)/2)}
- --dilate[-1] 3 -area_fg[-1] 0,1 -eq[-1] {($min_size+2*$>+2)^2}
- -if {!iM} -rm[-1] -break -endif # No more squares to grow.
- -or[-2,-1]
- -done
- -done
- -blend shapeaverage0
- -endl -done -v +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement