A high-performance general-purpose compute library
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:
* http://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;
}
Window object to render af::arrays.
Definition: graphics.h:37
A multi dimensional data container.
Definition: array.h:37
const array as(dtype type) const
Casts the array into another data type.
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
@ AF_ITERATIVE_DECONV_LANDWEBER
Landweber Deconvolution.
Definition: defines.h:529
@ AF_ITERATIVE_DECONV_RICHARDSONLUCY
Richardson-Lucy Deconvolution.
Definition: defines.h:530
@ AF_INVERSE_DECONV_TIKHONOV
Tikhonov Inverse deconvolution.
Definition: defines.h:535
AFAPI void info()
AFAPI void setDevice(const int device)
Sets the current device.
Definition: algorithm.h:15