Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1529

VB6 fast EdgeDetection (direct Pixel-Manipulation on Cairo-Surfaces)

$
0
0
Whilst cairo is known as a VectorGraphics-Library - it supports fast Blending-Operators
on its Pixel-Surfaces (aka ImageSurfaces) - and most wrappers around this library will
offer (in addition to cairos blending-ops) a few additional Pixel-Massaging-Methods.

The vbRichClient has 6 of that category already implemented:
- cCairo.PreMultiplyAlpha
- cCairo.DeMultiplyAlpha
- cCairoSurface.FastBlur
- cCairoSurface.GaussianBlur
- cCairoSurface.Sharpen
- cCairoSurface.AdjustColors (Brightness, Contrast, Gamma - all in one routine)

Now, there's certainly much more pixel-algorithms out there in the wild -
but the above few are what I restricted myself to, since they are often needed.

To accomodate those who want to perform their own PixelOps on those Surfaces, I've choosen
to make pixel-access as easy as possible - and so there exist two Array-Binding-Methods:
- cCairoSurface.BindArray(ByteArray) ... and its companion .ReleaseArray ByteArray
- cCairoSurface.BindArrayLong(LongArray) ... and its companion .ReleaseArrayLong LongArray

This is done without copying any Data - I guess the underlying SafeArray-technique is quite
wellknown in the meantime - and the Arrays in question need to be dynamic and uninitialized ones.

Well, that said - let's look at what the Demo has to offer:
Edge-Detection is a wide field - and I decided not to implement "the whole bunch of algos for comparison",
instead I concentrated on a very simple one (the "Roberts-Cross") - with focus on performance.

Since the algorithm is so simple (only using a small 2x2 Kernel), it was quite easy to avoid an
"inner Kernel-Loop" - and since the Formulas were not all that complex in this case too, coming
up with some Lookup-Tables for them was also relative easy to accomplish.

I've tuned it a bit though:
Instead of a SquareRoot on the "squared differences", I found that a logarithmic scaling produced
somewhat nicer results - and since the kernel is so small (compared to Sobel, Prewitt & Co.), the
algo captures fine details quite well, but tends to be "noisy" - so, a slight (and fast) PreBlurring was
added into the processing-queue, to remedy that.

For comparison (direct links instead of the forums img-tag, to get "the real image" -
and to easier compare - after loading them all - by just clicking between Browser-Tabs):
https://softwarebydefault.files.word..._grayscale.jpg
https://softwarebydefault.files.word..._grayscale.jpg
http://vbRichClient.com/Downloads/Lo...ithPreBlur.png

The last link of the above three, was generated with the Demo.

Performancewise, the Algo (including the steps: PreBlur, GreyScaling, LogarithmicRoberts, GammaCorrection, Sharpen)
takes in Sum only about 20msec total when native compiled (performing all steps on a 800x600 TrueColor-Image).

The Demo includes a few Demo-Images - here some ScreenShots:

Monarch-Original-Image:


Monarch-EdgeDetected and in ColorMode (algo performed on each color-channel separately).
The GreyScale-Result-Link I've posted already further above...


And another Result of one of the Demo-Images in Color-Mode:


Here's the Source-Zip:
EdgeDetection.zip

Have fun,

Olaf
Attached Files

Viewing all articles
Browse latest Browse all 1529

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>