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 package org.openimaj.image.processing.convolution;
31
32 import org.openimaj.citation.annotation.Reference;
33 import org.openimaj.citation.annotation.ReferenceType;
34 import org.openimaj.image.FImage;
35 import org.openimaj.image.processor.SinglebandImageProcessor;
36
37
38
39
40
41
42
43 @Reference(
44 type = ReferenceType.Inproceedings,
45 author = { "Kovesi, P." },
46 title = "Fast Almost-Gaussian Filtering",
47 year = "2010",
48 booktitle = "Digital Image Computing: Techniques and Applications (DICTA), 2010 International Conference on",
49 pages = { "121", "125" },
50 month = "Dec",
51 customData = {
52 "keywords", "Gaussian processes;approximation theory;band-pass filters;image processing;Gaussian bandpass filters;fast almost-Gaussian filtering;image averaging;integral images;log-Gabor filters;separable moving average filters;summed area tables;symmetric transfer function;Approximation methods;Bandwidth;Computer vision;Frequency domain analysis;Laplace equations;Pixel;Transfer functions;Difference of Gaussian filtering;Gaussian smoothing",
53 "doi", "10.1109/DICTA.2010.30"
54 })
55 public class FFastGaussianConvolve implements SinglebandImageProcessor<Float, FImage> {
56 private final int n;
57 private final int m;
58 private SinglebandImageProcessor<Float, FImage> wlBox;
59 private SinglebandImageProcessor<Float, FImage> wuBox;
60
61
62
63
64
65
66
67
68
69
70
71 public FFastGaussianConvolve(float sigma, int n) {
72 if (sigma < 1.8) {
73
74 this.m = 1;
75 this.n = 1;
76 this.wlBox = new FGaussianConvolve(sigma);
77 } else {
78 final float ss = sigma * sigma;
79 final double wIdeal = Math.sqrt((12.0 * ss / n) + 1.0);
80 final int wl = (((int) wIdeal) % 2 == 0) ? (int) wIdeal - 1 : (int) wIdeal;
81 final int wu = wl + 2;
82
83 this.n = n;
84 this.m = Math.round((12 * ss - n * wl * wl - 4 * n * wl - 3 * n) / (-4 * wl - 4));
85
86 this.wlBox = new AverageBoxFilter(wl);
87 this.wuBox = new AverageBoxFilter(wu);
88 }
89 }
90
91 @Override
92 public void processImage(FImage image) {
93 for (int i = 0; i < m; i++)
94 wlBox.processImage(image);
95 for (int i = 0; i < n - m; i++)
96 wuBox.processImage(image);
97 }
98 }