13 #ifndef IMAGE_MEDIAN_HPP
14 #define IMAGE_MEDIAN_HPP
29 :
image(L), radius(radius), mode(mode) { }
31 virtual double get(
int i,
int j,
int k)
const
36 std::vector<double> v((2 * radius + 1) * (2 * radius + 1));
40 for (
int y = -radius; y <= radius; y++)
41 for (
int x = -radius; x <= radius; x++)
42 if (x * x + y * y <= radius * radius)
43 v[z++] =
L->
get(wrap(i + y, h, mode & 1),
44 wrap(j + x, w, mode & 2), k);
46 std::nth_element(v.begin(), v.begin() + z / 2, v.begin() + z);
50 virtual void tweak(
int a,
int v)
58 virtual void doc(std::ostream& out)
const
60 out <<
"median " << radius <<
" " << mode;
80 virtual double get(
int i,
int j,
int k)
const
84 std::vector<double> v(2 * radius + 1);
88 for (
int y = -radius; y <= radius; y++, z++)
89 v[z] =
L->
get(wrap(i + y, h, mode & 1), j, k);
91 std::nth_element(v.begin(), v.begin() + z / 2, v.begin() + z);
95 virtual void doc(std::ostream& out)
const
97 out <<
"medianv " << radius;
114 virtual double get(
int i,
int j,
int k)
const
118 std::vector<double> v(2 * radius + 1);
122 for (
int x = -radius; x <= radius; x++, z++)
123 v[z] =
L->
get(i, wrap(j + x, w, mode & 2), k);
125 std::nth_element(v.begin(), v.begin() + z / 2, v.begin() + z);
129 virtual void doc(std::ostream& out)
const
131 out <<
"medianh " << radius;
virtual double get(int i, int j, int k) const =0
Return the value of the sample at row i, column j, channel k.
image * L
Left child.
Definition: image.hpp:117
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
virtual int get_height() const
Return the height of this image.
Definition: image.hpp:46
virtual int get_width() const
Return the height of this image.
Definition: image.hpp:56