Image Processing Functions in ArrayFire v3.4

Stefan YurkevitchArrayFire Leave a Comment

There are a number of  additions and updates to image based features in the new v3.4 release of ArrayFire. Among the updates are:

This blog post will display some typical use cases for these new features.

Interpolation methods

ArrayFire v3.4 implements several new  interpolation methods for 1-d and 2-d domains. The new interpolation methods for 1-d functions are:

  • AF_INTERP_LINEAR_COSINE
  • AF_INTERP_CUBIC

and for 2-d functions are:

  • AF_INTERP_BILINEAR_COSINE
  • AF_INTERP_BICUBIC

The behavior of the interpolation methods can be seen in the following pictures.

 

Original data points

Original data points

Linear interpolation

Linear interpolation

Linear cosine interpolation

Linear cosine interpolation

Cubic interpolation

Cubic interpolation

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);

Capture

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.

3x image scaling using nearest-neighbor sampling

3x image scaling using nearest-neighbor sampling

3x image scaling using bilinear-cosine sampling

3x image scaling using bilinear-cosine sampling

3x image scaling using bicubic sampling

3x image scaling using bicubic sampling

  • rot_0

    Image rotation with nearest neighbor sampling.

  • rot_1

    Image rotation with bilinear sampling.

  • rot_2

    Image rotation with bilinear-cosine sampling.

  • rot_3

    Image rotation with bicubic sampling.

Image moments

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);
Here is an example of how the shorthand versions might be used to find the area and center of mass of an image:
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;

com

Download

ArrayFire v3.4 can be downloaded from these locations:

Community

ArrayFire is continually improving through the addition of new image processing and computer vision functions. We welcome your feedback:

Finally, as you find success with ArrayFire, we invite you to contribute a post to this blog to share with the broader community. Email scott@arrayfire.com to contribute to this blog.

Leave a Reply

Your email address will not be published. Required fields are marked *