Source Code |
4 | vbMedia |   |
  |
VB Image Processing Sample Download the Image Processing Sample application (107kb) This sample requires the SSubTmr.DLL component because it includes an implementation of my Progress Bar control. Make sure you have loaded and registered this before trying the HotKey project. Download the Image Processing Class Only (4kb)
Now VB can compile applications to native code, there are a whole load of new things you can use
VB for
which were previously all but practical. Image processing is one of them. Image processing code
requires a huge number of bytes to be read and parsed (for example, blurring a 24 bit picture
of 640x480 resolution requires 23,040,000 multiplications and additions!). Whilst this sort of thing runs at
a hopeless crawl in the VB IDE or in p-code, when you compile to native code it can easily run
within a second. Cool!
It operates at blinding speed when compiled to native code, and is easy to adapt to further image processing types, such as erosion, diffusion, count and averaging filters.
Introduction to the Sample
    1/9     1/9     1/9 So, say we had a red pixel surrounded by blue pixels in a bitmap:
    ..     (0,0,255)     (0,0,255)     (0,0,255)     .. The result for the centre pixel will be the sum of 1/9 of each of the pixel's values, i.e.     (255/9),0,8x(255/9)
This is a mostly blue purple colour, so the single red value has been blurred by its blue neighbours to
a much bluer shade.
    1     1     1       Weight: 9
You can modify the filter to blur more by increasing the number of pixels that are sampled in the
matrix (e.g. use a 5x5 or 7x7 matrix rather than a 3x3 one) and by increasing the contribution for
the pixels surrounding the central one.
    1     1     1       Weight: 18
Sharpening Filters
    0     -1     0       Weight: 2
Other Filters
    1     0     0       Weight: 1 Embossing filter which detects changes in the upper-left direction
    -1     0     0       Weight: 1 Embossing filter which detects changes in the lower-right direction
In the code sample, 127 is added to all the pixel values output from the embossing filter to colour
the embossed image grey. This gives a better 3d visual embossing effect. The effect can be made
more attractive by colourising the result afterwards.
    1     1     -1       Weight: 1 Left-hand edge detection
    1     1     1       Weight: 1 Upper-left hand edge detection Suggestions for Further EnhancementsThe image processing class provided with this sample is a good start for further enhancements. There is a custom filter option provided in the demonstration which you can use to try out your own custom filter matrices (these are saved in the registry, so you can build up a library of interesting ones). Further filters can easily be added. You could implement non-linear filters such as maximium or minimum which provide fascinating, almost impressionistic effects to images. A maximum filter looks at all the pixels in a n x n array and picks the highest. Similarly a minimum filter picks the minimum value. An average filter sets the output pixel to an average of the pixels in the array. You could also try applying mathematical functions, such as sin and cos to the colour values of pixels. By this means you can achieve ripple effects, highlights and so forth. Enjoy! Back to top Back to Source Code Overview |
  |
About Contribute Send Feedback Privacy
|