forked from arrayfire/arrayfire
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeconvolution.cpp
More file actions
68 lines (53 loc) · 2.06 KB
/
deconvolution.cpp
File metadata and controls
68 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*******************************************************
* 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);
af::info();
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,
AF_ITERATIVE_DECONV_LANDWEBER);
array richlucy =
iterativeDeconv(blurred, kernel, ITERATIONS, RELAXATION_FACTOR,
AF_ITERATIVE_DECONV_RICHARDSONLUCY);
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;
}