DISCONTINUED: Interested parties in purchasing the source code can contact me via email.
ABXVImage and Filters
This is the first article on the use of the new ABXVision framework. I’ve decided to start with the most fundamental class: ABXVImage.
ABXVImage is the core image object that will be used in every project you create with ABXVision. It’s a new ‘picture’ object in Xojo that is especially written to optimize the algorithms you can use (Color filters, Edge detectors, Blurs, Corner detectors, Shape Detectors, etc…).
To make it clear if we are working with a Xojo picture or an ABXVImage, I’ve split up the terms:
Whenever I use picture, I mean a Xojo picture. Whenever I use Image, I mean an ABXVImage.
So the first thing we need to do is convert a picture to an image and back:
' create a ABXVImage from a Xojo Picture
dim img as new ABXVImage
Img contains the data of the picture, ready to be processed. We can now make use of the filters. Some basic filters (like grayscaling, a thing you’ll be doing all the time), are also build-in the ABXVImage class.
For example, if we want to grayscale the image for further processing, we can use the following code:
You’ll notice the 8Bit part in the method name. A lot of the methods in ABXVision (like binarization) use this 8Bit pointer to perform their work. As a grayscaled image has the same value in its Red, Green and Blue channel, there is no need to run the whole filter over all 3 channels. Keeping record of one channel will do.
Once this function is performed, the ABXVImage will have its BitDepth property set to ABXVBITDEPTH.BIT8. Now, all other methods can check this property and see if it is ok to perform the action.
If, for some reason we want it back as a 32Bit (24Bit in many cases where no alpha is used), we can use the following code:
This will also set the BitDepth property of the image to ABXVBITDEPTH.BIT32.
Now, after our hard work, we want to have a Xojo picture with the result. This can be done with the GetPicture() method:
mBuffer = img.GetPicture()
Beware of overusing the GetPicture() method! If you have to run a lot of filters after each other and have no need to see every single step, there is no need to use the GetPicture() method. GetMethod() is mostly called after everything is done, e.g. when the image is analyzed, a glyph is found and the augmented part is drawn on the image.
1. GetPicture() will do a GrayScaled8BitTo32Bit() automatatically if it was a 8 Bit image.
2. To be complete, most methods can handle 32 bit picture (R, G, B + Alpha/Mask), but it’s not advised to use this kind of image. Those methods will also perform their action on the alpha channel, and this takes time. The SetPicture() method will set the image as ABXVMASKTYPE.MASK_NONE, so the Alpha channel is ignored. If for some reason you want your Alpha channel, use the Mask parameter of the SetPicture() method. You can use ABXVMASKTYPE.MASK_OLD (This is the old Realbasic format where the mask is also a complete picture object) or ABXVMASKTYPE.MASK_NEW (This is the new Xojo picture format, with an extra real Alpha channel. This is experimental and not fully tested)
3. A lot of optimization is done using #Pragmas in the framework. This means it will run a lot faster once compiled, but will do also less error checks. Always make sure you follow the rules of the syntax of the method. e.g. if the method asks an array with 4 points, don’t give it one with 3 points. Your program will crash!
Here are the pragmas used:
#if not DebugBuild
#pragma StackOverflowchecking False
#pragma NilObjectChecking False
There are many filters available in ABXVision. I’ve tried to split them up so they made some sense. (Click the titles to jump to the help)
Provides a number of 2 source filters – filters which take two input images to produce the result image.
Provides several adaptive binarization filters, which are aimed to find binarization threshold automatically and then apply it to the source image.
Provides different binarization filters, which may be used as in image processing, as in some computer vision tasks.
Provides number of image processing filters, which allow to filter pixels depending on their color values.
These image processing filters may be used to keep pixels, which color falls inside or outside of specified range, and fill the rest of pixels with specified color.
Provides convolution filters and a set of derived filters, which allow to perform image convolution with common kernels.
Provides a number of edge detection filters, which may suite different tasks providing different performance.
Provides a set of filters from mathematical morphology.
All of the filters may be applied as using default structuring element, as using custom specified structuring element.
Provides transformations methods, which allow to perform image transformationq.
In the attached demo project, some of those filters are used to show the different techniques used. You’ll notice most of the filters have multiple calling methods. They are mostly split up as follows:
1. call(img1). The action is performed on the image.
2. img2 = call(img1). The action is performed on img and returned in img2 without altering img1.
3. call(img1, rect). Perform the action on the image itself, but only on the part described by the rectangle.
4. img2 = call(img1, rect). Perform the action on the image itself, but only on the part described in the rectangle and also only return this part as img2, without altering img1
I suggest you read up on the help and play with the ABXVImage object and familiarize with it. The demo project contains some filters, but you can try out others.
This concludes the introduction. I felt it was needed to talk about ABXVImage first before going into other subjects as this is a core object. The source code and framework can be found on the ABXVision page (see top of this page)
You need to read the Getting Started document as you have to copy the framework into the demo projects.
In my next article, we’ll tackle Augmented Reality, as seen in the teaser video!
Click here to if you like my work