Image editing using ArrayFire: Part 2

Pradeep ArrayFire, Image Processing 10 Comments

A couple of weeks back, we did a post on a few image editing functions using ArrayFire library. Today, we shall be doing the second post in the series Image Editing using ArrayFire. We will be looking at the following operations today.

  • Image distortion
  • Noise addition
  • Noise reduction
  • Edge filters
  • Boundary extraction
  • Difference of gaussians

Code and sample input/outputs corresponding to each operation are described below.

Image distortion

We will be looking at spread and pick filters in this section. Both of these filters are fundamentally the same, they replace each pixel in the original image with one of it's neighboring pixels. How the neighbor is chosen is essentially the difference between spread and pick. Both of these functions use a common function getRandomNeighbor to select neighboring pixels. The code snippet for getRandomNeighbor is given below.

lena512x512

Input image

spread

Image with spread applied

lena512x512

Input image

pick

After Pick filter

Noise addition

We will at look hurl noise now. Despite the fancy name, what the filter essentially does is replace some of the pixels of the image with random color. New colors are introduced into the resulting image. Therefore, giving a high repeat input value might result in an image that is completely different from the original.

lena512x512

Input Image

hurl

After adding hurl noise

Noise reduction

Noise reduction is typically achieved using smoothing filters. We will look at bilateral, median and Gaussian blur filters today. Our library has a built-in function(af::bilateral) that readily does bilateral filtering on an image.

hurl

Input image

bilateral

Bilateral smoothing

bilateral

Bilateral with more spatial and chromatic variance

As you can see in the above images, bilateral is not quite effective with hurl noise. Increasing spatial radius might help a little but might result in loosing features as shown in the third picture. Next, we will look at Gaussian blur.

hurl

Input Image

gblur

After applying Gaussian smoothing

Gaussian blur was able to remove noise to certain extent, but it is blurring out all important features equally and the noisy pixels participate in the convolution operation. Hence, Gaussian blur might not be a right candidate always.

hurl

Input Image

medfilt

After Median filter is applied

Median filter seems to do a good job for this type of noise.

Edge filters

We will be looking at Sobel and Prewitt filters.

lena512x512

Input Image

prewitt

Prewitt Gradient

lena512x512

Input Image

sobel

Sobel Gradient

Boundary extraction

The following code snippet extracts boundaries in an image using erosion morphological operator.

lena512x512

Input Image

bdry

Boundaries

Difference of gaussians

lena512x512

Input Image

dog

Difference of Gaussians

Last two sections use a utility function normalizeImage that basically re-scales the pixels values to [0-255] range.

Conclusion

All the functions from this post are updated and available through github repository located here. Hope, you guys are enjoying this series.

Facebooktwittergoogle_plusredditlinkedinmail