convolution kernal examples
Convolution kernals are templates used to describe the effect of a region of pixels on a single pixel. The template is usually located over the pixel in question such that the pixel is in center of the kernal. When using 'pip-fixed-kernal' the kernal is applied to all the pixels of the image, in turn. Specific subordinate regions of an image may be addressed using 'pip-pixel-kernal', as shown in Example 3.
Example 1 :
This example uses a very simple 3x3 edge detection convolution kernal. Edge
detection kernals are recognized by the sum of the elements of the kernal
is zero (0.0).
ox--> (define ratimg (pip-formatted-read 'filename "Rat_w_cov.tiff"))
ox--> (define edgelist (list -1.0 -1.0 0.0
-1.0 0.0 1.0
0.0 1.0 1.0))
ox--> (define edgevec (list->vector edgelist))
ox--> ;; Process red, green and blue fields
ox--> (define redch (pip-fixed-kernal (car ratimg) edgevec))
ox--> (define grnch (pip-fixed-kernal (cadr ratimg) edgevec))
ox--> (define bluch (pip-fixed-kernal (caddr ratimg) edgevec))
ox--> ;; Edge image saved as an image of the red field.
ox--> ;; This gives a nice grey scale image. Otherwise, the colors
ox--> ;; separate when applying the kernal to each field and combining
ox--> ;; the fields back together.
ox--> (pip-formatted-save 'imglist (list redch) 'filename "Edge.tiff")
| source image | image of applied edge kernal |
|---|---|
|
|
Example 2 :
This example is one of blurring convolution kernals. One characteristic of a
blurring kernal is the sum of the elements of the kernal is one (1.0).
ox--> (define blurlist (list 0.04 0.04 0.04 0.04 0.04
0.04 0.04 0.04 0.04 0.04
0.04 0.04 0.04 0.04 0.04
0.04 0.04 0.04 0.04 0.04
0.04 0.04 0.04 0.04 0.04))
ox--> (define blurvec (list->vector blurlist))
ox--> (define lilimg (pip-formatted-read 'filename "Lilies_w_cov.tiff"))
ox--> (set! redch (pip-fixed-kernal (car lilimg) blurvec))
ox--> (set! grnch (pip-fixed-kernal (cadr lilimg) blurvec))
ox--> (set! bluch (pip-fixed-kernal (caddr lilimg) blurvec))
ox--> (pip-formatted-save 'imglist (list redch grnch bluch (cadddr ratimg))
'ioform "JPEG"
'filename "Blurred.jpeg")
| source image | image of applied blur kernal |
|---|---|
|
|
Example 3, using "pip-pixel-kernal" :
An 11x11 blur convolution kernal is used to blur just the region about the head of the charater in the image in this example. A transitional copy of the image is created to preserve the content of the rest of the image.
ox--> (define cellvalue (/ 1.0 121.0)) ox--> (define blurvec3 (make-vector 121 cellvalue)) ox--> (define ratimg (pip-formatted-read 'filename "Rat.tiff")) ox--> (define redch (pip-imgfld-copy (car ratimg))) ox--> (define grnch (pip-imgfld-copy (cadr ratimg))) ox--> (define bluch (pip-imgfld-copy (caddr ratimg))) ox--> ;; Define a working transitional copy of the image in ox--> ;; question. ox--> (define Rred (pip-imgfld-copy (car ratimg))) ox--> (define Rgrn (pip-imgfld-copy (cadr ratimg))) ox--> (define Rblu (pip-imgfld-copy (caddr ratimg))) ox--> (define xdist 0.0) ox--> (define ydist 0.0) ox--> (define dist 0.0) ox--> (for i 320 440 1 ox--> (for j 90 210 1 ox--> (set! xdist (exact->inexact (- 380 i))) ox--> (set! ydist (exact->inexact (- 150 j))) ox--> (set! dist (sqrt (+ (sqr xdist) (sqr ydist)))) ox--> (cond ox--> ((< dist 61.0) ox--> (set! Rred (pip-pixel-kernal redch Rred blurvec3 i j)) ox--> (set! Rgrn (pip-pixel-kernal grnch Rgrn blurvec3 i j)) ox--> (set! Rblu (pip-pixel-kernal bluch Rblu blurvec3 i j)) ox--> ) ox--> ) ox--> ) ox--> ) ox--> (pip-show (list Rred Rgrn Rblu) 'label "10 Most Wanted")
| source image | regionally blurred image |
|---|---|
|
|
Last updated: 02/08/97 / Peter Carswell ( pete@cgrg.ohio-state.edu ) Any comments or suggestions appreciated.