There are a number of additions and updates to image based features in the new v3.4 release of ArrayFire. Among the updates are:
- New interpolation methods for several existing functions
- Functions for image moments
This blog post will display some typical use cases for these new features.
ArrayFire v3.4 implements several new interpolation methods for 1-d and 2-d domains. The new interpolation methods for 1-d functions are:
and for 2-d functions are:
The behavior of the interpolation methods can be seen in the following pictures.
A common use for interpolation is image filtering. Given a coarse image, we can resample it to be smoother.
af::array img = af::randu(7,7); //create a random image
//define sample points for interpolation
af::array Xs = af::seq(0, 6, 0.1f);
af::array Ys = af::seq(0, 6, 0.1f);
Xs = af::tile(Xs, 1, Ys.dims(0));
Ys = af::tile(Ys.T(), Xs.dims(0));
//interpolate based on specific method
af::array img_bilinear = af::approx2(img, Xs, Ys, AF_INTERP_BILINEAR);
af::array img_bilinearcos = af::approx2(img, Xs, Ys, AF_INTERP_BILINEAR_COSINE);
af::array img_bicubic = af::approx2(img, Xs, Ys, AF_INTERP_BICUBIC_SPLINE);
The new interpolation methods further apply to several similar image transformation functions:
Different interpolation methods greatly affect the final result of image processing operations. In general, bilinear and bilinear-cosine produce a good result when upscaling an image, however they often result in a blurry look. The bicubic method tends to sharpen the image resulting in slightly stronger borders and a better overall look. Below are some examples of this behavior using image rotation and image scaling.
Image moments are another new addition to ArrayFire v3.4. Image moments are weighted averages of pixels in an image which provide useful properties of an image. A common use of image moments is to find the center of mass or area (or gray level sum) of an image.
Currently, ArrayFire calculates all first order moments. Each moment can be returned individually or all first-order moments can be calculated at once. All moments can be found as follows:
af::array moments = af::moments(input_image, AF_MOMENT_FIRST_ORDER);
double m00, m01, m10;
af::moments(&m00, aimg, AF_MOMENT_M00);
af::moments(&m01, aimg, AF_MOMENT_M01);
af::moments(&m10, aimg, AF_MOMENT_M10);
double area = m00;
double x_center = m10 / m00;
double y_center = m01 / m00;
ArrayFire v3.4 can be downloaded from these locations:
ArrayFire is continually improving through the addition of new image processing and computer vision functions. We welcome your feedback:
- General discussion forums on the ArrayFire Google Group
- Live discussion chat on the ArrayFire Gitter
- Issue reports on the ArrayFire GitHub
Finally, as you find success with ArrayFire, we invite you to contribute a post to this blog to share with the broader community. Email email@example.com to contribute to this blog.