* Copyright (c) 2018, ArrayFire
* All rights reserved.
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
#include <arrayfire.h>
#include <stdio.h>
#include <af/util.h>
#include <cstdlib>
using namespace af;
const unsigned ITERATIONS = 96;
const float RELAXATION_FACTOR = 0.05f;
array normalize(const array &in) {
float mx = max<float>(;
float mn = min<float>(;
return (in - mn) / (mx - mn);
int main(int argc, char *argv[]) {
int device = argc > 1 ? atoi(argv[1]) : 0;
try {
printf("** ArrayFire Image Deconvolution Demo **\n");
af::Window myWindow("Image Deconvolution");
array in = loadImage(ASSETS_DIR "/examples/images/house.jpg", false);
array kernel = gaussianKernel(13, 13, 2.25, 2.25);
array blurred = convolve(in, kernel);
array tikhonov =
inverseDeconv(blurred, kernel, 0.05, AF_INVERSE_DECONV_TIKHONOV);
array landweber =
iterativeDeconv(blurred, kernel, ITERATIONS, RELAXATION_FACTOR,
array richlucy =
iterativeDeconv(blurred, kernel, ITERATIONS, RELAXATION_FACTOR,
while (!myWindow.close()) {
myWindow.grid(2, 3);
myWindow(0, 0).image(normalize(in), "Input Image");
myWindow(1, 0).image(normalize(blurred), "Blurred Image");
myWindow(0, 1).image(normalize(tikhonov), "Tikhonov");
myWindow(1, 1).image(normalize(landweber), "Landweber");
myWindow(0, 2).image(normalize(richlucy), "Richardson-Lucy");;
} catch (af::exception &e) {
fprintf(stderr, "%s\n", e.what());
return 0;
Window object to render af::arrays.
Definition: graphics.h:37
An ArrayFire exception class.
Definition: exception.h:22
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:46
@ f32
32-bit floating point values
Definition: defines.h:211
Landweber Deconvolution.
Definition: defines.h:525
Richardson-Lucy Deconvolution.
Definition: defines.h:526
Tikhonov Inverse deconvolution.
Definition: defines.h:531
AFAPI void info()
AFAPI void setDevice(const int device)
Sets the current device.
AFAPI array gaussianKernel(const int rows, const int cols, const double sig_r=0, const double sig_c=0)
C++ Interface for generating gausian kernels.
AFAPI array inverseDeconv(const array &in, const array &psf, const float gamma, const inverseDeconvAlgo algo)
C++ Interface for Tikhonov deconvolution algorithm.
AFAPI array iterativeDeconv(const array &in, const array &ker, const unsigned iterations, const float relaxFactor, const iterativeDeconvAlgo algo)
C++ Interface for Iterative deconvolution algorithm.
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
static af::array array(af::dim4 idims, cl_mem buf, af::dtype type, bool retain=false)
Create an af::array object from an OpenCL cl_mem buffer.
Definition: opencl.h:327
AFAPI array convolve(const array &signal, const array &filter, const convMode mode=AF_CONV_DEFAULT, const convDomain domain=AF_CONV_AUTO)
C++ Interface for convolution any(one through three) dimensional signals.
Definition: algorithm.h:15