image_processing/deconvolution.cpp
/*******************************************************
* Copyright (c) 2018, ArrayFire
* All rights reserved.
*
* This file is distributed under 3-clause BSD license.
* The complete license agreement can be obtained at:
* https://arrayfire.com/licenses/BSD-3-Clause
********************************************************/
#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>(in.as(f32));
float mn = min<float>(in.as(f32));
return (in - mn) / (mx - mn);
}
int main(int argc, char *argv[]) {
int device = argc > 1 ? atoi(argv[1]) : 0;
try {
af::setDevice(device);
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");
myWindow.show();
}
} catch (af::exception &e) {
fprintf(stderr, "%s\n", e.what());
throw;
}
return 0;
}
util.h
af::info
AFAPI void info()
af::array::as
const array as(dtype type) const
Converts the array into another type.
af::setDevice
AFAPI void setDevice(const int device)
Sets the current device.
af::inverseDeconv
AFAPI array inverseDeconv(const array &in, const array &psf, const float gamma, const inverseDeconvAlgo algo)
C++ Interface for Tikhonov deconvolution algorithm.
af::array
A multi dimensional data container.
Definition: array.h:35
af
Definition: algorithm.h:15
af::gaussianKernel
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.
AF_ITERATIVE_DECONV_RICHARDSONLUCY
@ AF_ITERATIVE_DECONV_RICHARDSONLUCY
Richardson-Lucy Deconvolution.
Definition: defines.h:526
af::exception
An ArrayFire exception class.
Definition: exception.h:29
af::iterativeDeconv
AFAPI array iterativeDeconv(const array &in, const array &ker, const unsigned iterations, const float relaxFactor, const iterativeDeconvAlgo algo)
C++ Interface for Iterative deconvolution algorithm.
AF_ITERATIVE_DECONV_LANDWEBER
@ AF_ITERATIVE_DECONV_LANDWEBER
Landweber Deconvolution.
Definition: defines.h:525
af::loadImage
AFAPI array loadImage(const char *filename, const bool is_color=false)
C++ Interface for loading an image.
arrayfire.h
AF_INVERSE_DECONV_TIKHONOV
@ AF_INVERSE_DECONV_TIKHONOV
Tikhonov Inverse deconvolution.
Definition: defines.h:531
af::exception::what
virtual const char * what() const
Returns an error message for the exception in a string format.
Definition: exception.h:60
af::convolve
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.
af::Window
Window object to render af::arrays.
Definition: graphics.h:37
f32
@ f32
32-bit floating point values
Definition: defines.h:211