REBOL [ Title: "Convolve" Author: cyphre@rebol.com Version: 1.1.0 Purpose: "Demo of REBOL/View convolution effect" History: [ "Carl" 1.1.0 "Added other images and contrast control." ] Needs: [view 1.3.2] ] foreach file [ %coast.jpg %sunset.jpg ][ if not exists? file [ if not request-download/to join http://www.rebol.com/view/demos/ file file [quit] ] ] img: load %coast.jpg time: func [b /local start] [ start: now/precise do b status/text: rejoin ["Rendered in: " difference now/precise start] show status ] reset: [ [ 0 0 0 0 1 0 0 0 0 ] 0 0 #[false] ] conv-data: [ "Emboss 1" [ [ 0 0 0 0 1 0 0 0 -1 ] 1 128 #[true] ] "Emboss 2" [ [ 2 0 0 0 -1 0 0 0 -1 ] 1 128 #[true] ] "Emboss 3" [ [ -2 -1 0 -1 1 1 0 1 2 ] 0 0 #[true] ] "Emboss 4 Laplascian" [ [ -1 0 -1 0 4 0 -1 0 -1 ] 1 127 #[true] ] "Emboss 5 All Directions" [ [ -1 -1 -1 -1 8 -1 -1 -1 -1 ] 1 127 #[true] ] "Emboss 6 Horizontal Only" [ [ 0 0 0 -1 2 -1 0 0 0 ] 1 127 #[true] ] "Emboss 7 Vertical Only" [ [ 0 -1 0 0 0 0 0 1 0 ] 1 127 #[true] ] "Emboss 8 Horiz/Vert" [ [ 0 -1 0 -1 4 -1 0 -1 0 ] 1 127 #[true] ] "Emboss 9 Lossy" [ [ 1 -2 1 -2 4 -2 -2 -1 -2 ] 1 127 #[true] ] "Sobel Horiz" [ [ 1 2 1 0 0 0 -1 -2 -1 ] 1 0 #[false] ] "Sobel Vert" [ [ 1 0 -1 2 0 -2 1 0 -1 ] 1 0 #[false] ] "Pervit Horiz" [ [ 1 1 1 0 0 0 -1 -1 -1 ] 1 0 #[false] ] "Pervit Vert" [ [ 1 0 -1 1 0 -1 1 0 -1 ] 1 0 #[false] ] "Kirsh Horiz" [ [ 5 5 5 -3 -3 -3 -3 -3 -3 ] 1 0 #[false] ] "Kirsh Vert" [ [ 5 -3 -3 5 -3 -3 5 -3 -3 ] 1 0 #[false] ] "Edge detect 1" [ [ 0 1 0 1 -4 1 0 1 0 ] 1 0 #[false] ] "Edge detect 2" [ [ -5 0 0 0 0 0 0 0 5 ] 1 0 #[false] ] "Edge detect 3" [ [ -0.125 -0.125 -0.125 -0.125 1 -0.125 -0.125 -0.125 -0.125 ] 0 0 #[false] ] "Edge detect 5" [ [ -1 -1 -1 -1 8 -1 -1 -1 -1 ] 0 127 #[false] ] "Edge detect 6" [ [ -1 -1 -1 2 2 2 -1 -1 -1 ] 0 127 #[false] ] "Edge detect 7" [ [ -5 -5 -5 -5 39 -5 -5 -5 -5 ] 0 127 #[false] ] "Edge enhance" [ [ 0 0 0 -1 1 0 0 0 0 ] 0 127 #[false] ] "Mean removal" [ [ -1 -1 -1 -1 9 -1 -1 -1 -1 ] 0 0 #[false] ] "sharpen 1" [ [ -1 -1 -1 -1 16 -1 -1 -1 -1 ] 0 0 #[false] ] "sharpen 2" [ [ 0 -2 0 -2 11 -2 0 -2 0 ] 3 0 #[false] ] "sharpen 3" [ [ 0 -1 0 -1 5 -1 0 -1 0 ] 0 0 #[false] ] "Gaussian blur 1" [ [ 1 2 1 2 4 2 1 2 1 ] 16 0 #[false] ] "Gaussian blur 2" [ [ 0.045 0.122 0.045 0.122 0.332 0.122 0.045 0.122 0.045 ] 0 0 #[false] ] "Gaussian blur 3" [ [ 0 1 0 1 1 1 0 1 0 ] 0 0 #[false] ] "blur/smooth" [ [ 1 1 1 1 1 1 1 1 1 ] 9 0 #[false] ] "box blur" [ [ 0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111 0.111 ] 0 0 #[false] ] "triangle blur" [ [ 0.0625 0.125 0.0625 0.125 0.25 0.125 0.0625 0.125 0.0625 ] 0 0 #[false] ] ] tl-data: extract conv-data 2 current-conv: reset set-gui: has [fac] [ repeat n 9 [ set in fac: get to-word rejoin ["m" n] 'text to-decimal pick current-conv/1 n show fac ] f-divisor/text: to-decimal current-conv/2 f-oft/text: to-integer current-conv/3 ch-gray/data: to-logic current-conv/4 show [f-divisor f-oft ch-gray] ] get-gui: has [fac] [ repeat n 9 [ poke current-conv/1 n to-decimal get in fac: get to-word rejoin ["m" n] 'text ] current-conv/2: to-decimal f-divisor/text current-conv/3: to-integer f-oft/text current-conv/4: to-logic ch-gray/data ] stylize/master [ field: field 200x20 edge [size: 1x1 color: black effect: none] info: field ] set-image: func [i] [ i1/image: i2/image: img: i show [i1 i2] ] set-effect: has [v] [ v: reduce ['fit 'convolve current-conv/1 to-decimal current-conv/2 to-integer current-conv/3 current-conv/4] if s-cont/data <> 0.5 [ insert next v reduce ['contrast to-integer (s-cont/data * 200 - 100)] ] v ] apply-effect: does [ set-gui i2/image: img i2/effect: set-effect time [show i2] show i2 ] view center-face layout [ style tog tog 50 snow gold origin 5 space 5 i1: image img i2: image img return guide tog 50 "Image 1" on of 'set [set-image load %coast.jpg] m1: field 50 m4: field 50 m7: field 50 return tog 50 "Image 2" of 'set [set-image load %sunset.jpg] m2: field 50 m5: field 50 m8: field 50 return tog 50 "Open" of 'set [ value: request-file/only/keep if all [value value: attempt [load value] image? value][ set-image value ] ] m3: field 50 m6: field 50 m9: field 50 return across style lab text 56 lab "divisor:" f-divisor: field 100 return lab "offset:" f-oft: field 100 return lab "contrast:" s-cont: slider 100x20 [get-gui apply-effect] with [data: .5] return ch-gray: check-line "preprocess grayscale" return btn "Apply" [ get-gui apply-effect ] btn 63 "Apply more" [ get-gui time [ use [fx][ fx: set-effect i2/image: to-image make system/standard/face [size: i2/size image: i2/image effect: fx edge: none] ] show i2 ] ] btn "Reset" [ s-cont/data: 0.5 show s-cont current-conv: copy/deep reset apply-effect ] return tl: text-list 165x214 [ current-conv: copy/deep select conv-data value apply-effect ] with [data: tl-data] return status: info 165 do [set-gui] ]