![]() Original |
![]() Gaussian blurred |
To create the blur we use matrix convolution. The matrix convolution kernel coefficients are selected to approximate the Gaussian distribution along the width, length, and diagonal of the kernel.
For this example we use the 9 x 9 kernel:
0 0 1 1 1 1 1 0 0
0 1 2 3 3 3 2 1 0
1 2 3 6 7 6 3 2 1
1 3 6 9 11 9 6 3 1
1 3 7 11 12 11 7 3 1
1 3 6 9 11 9 6 3 1
1 2 3 6 7 6 3 2 1
0 1 2 3 3 3 2 1 0
0 0 1 1 1 1 1 0 0
The Victor Library matrixconvex function can accept kernels of size 3 x 3 to up to 63 x 63.
For more information about matrix convolution see any introductory image processing text book. For details about the Gaussian blur kernel development see The Image Processing Handbook, by John C Russ, CRC Press.
' ........... Defines and declarations ........... ' ................................................ ' Image descriptor Type imgdes ibuff As Long stx As Long sty As Long endx As Long endy As Long buffwidth As Long palette As Long colors As Long imgtype As Long bmh As Long hBitmap As Long End Type ' ................................................ Declare Function matrixconvex Lib "VIC32.DLL" (ByVal ksize As Long, ByRef firstelement as byte, ByVal divsr As Long, srcimg As imgdes, resimg As imgdes) As Long ' .................. Function ........................ Public Function gaussianblur(ByRef myimage As imgdes) As Long Dim rcode As Long Dim kernel(0 To 80) As Byte ' 9 x 9 kernel Dim kernelvalues As Variant Dim j As Integer Dim divisor As Long ' Kernel values: '0 0 1 1 1 1 1 0 0 '0 1 2 3 3 3 2 1 0 '1 2 3 6 7 6 3 2 1 '1 3 6 9 11 9 6 3 1 '1 3 7 11 12 11 7 3 1 '1 3 6 9 11 9 6 3 1 '1 2 3 6 7 6 3 2 1 '0 1 2 3 3 3 2 1 0 '0 0 1 1 1 1 1 0 0 kernelvalues = Array(0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 2, 3, 3, 3, 2, 1, 0, 1, 2, 3, 6, 7, 6, 3, 2, 1, 1, 3, 6, 9, 11, 9, 6, 3, 1, 1, 3, 7, 11, 12, 11, 7, 3, 1, 1, 3, 6, 9, 11, 9, 6, 3, 1, 1, 2, 3, 6, 7, 6, 3, 2, 1, 0, 1, 2, 3, 3, 3, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0) divisor = 0 For j = 0 To 80 kernel(j) = kernelvalues(j) divisor = divisor + kernel(j) Next j If divisor = 0 Then rcode = -1 ' Kernel is empty, return error code Else rcode = matrixconvex(9, kernel(0), divisor, myimage, myimage) End If gaussianblur = rcode End Function
Victor Image Processing Library homepage | Victor Product Summary | more source code