Creating Gray-Code sequences using gimp
June 15th, 2009
No comments
I needed to implement gray-code sequences for a fringe projection system i'm trying to build. To avoid hard to understand and not really intuitive C-code, i used gimp to produce the projection images. In this article i'm going to document the code used.
First is the script-fu function to generate a picture with a given number of fringes or - alternatively - a given width of the period:
CODE:
-
(define (script-fu-oan-create-fringes fwidth t fcount)
-
(let*
-
(
-
(myimg (aref (cadr (gimp-image-list)) 0))
-
(mylayer (gimp-image-active-drawable myimg))
-
(layers (gimp-image-get-layers myimg))
-
(channels (gimp-image-get-channels myimg))
-
(height (car (gimp-drawable-height (car mylayer))))
-
)
-
(if (= t TRUE) (set! fwidth (/ (car (gimp-drawable-width (car mylayer))) (* anzahl 2)))
-
(set! fcount (/ (car (gimp-drawable-width (car mylayer))) (* breite 2)))
-
)
-
(define i 0)
-
(gimp-selection-all myimg)
-
(gimp-edit-clear (car mylayer))
-
(gimp-selection-none myimg)
-
(while
-
(<i fcount)
-
(gimp-rect-select myimg (* (* fwidth i) 2) 0 fwidth height CHANNEL-OP-ADD FALSE 0)
-
(set! i (+ i 1))
-
)
-
(gimp-edit-bucket-fill (car mylayer) FG-BUCKET-FILL NORMAL-MODE 100 0 FALSE 0 0)
-
)
-
)
Then there is the register-function call to enable the menu item for the function:
CODE:
-
(script-fu-register
-
"script-fu-oan-create-fringes" ;func name
-
"Create Fringes" ;menu label
-
"Create an image of fringes\
-
" ;description
-
"Omar Abo-Namous" ;author
-
"copyright 2009, Omar Abo-Namous" ;copyright notice
-
"March 02, 2009" ;date created
-
"" ;image type that the script works on
-
SF-VALUE "Fringe width:" "16" ;
-
SF-TOGGLE "Use Fringe count" FALSE ;
-
SF-VALUE "Fringe count:" "8" ;
-
)
-
(script-fu-menu-register "script-fu-oan-create-fringes" "<Image>/Xtns")