13 #ifndef IMAGE_SOBEL_HPP
14 #define IMAGE_SOBEL_HPP
28 virtual double get(
int i,
int j,
int k)
const
30 const int in = wrap(i - 1,
L->
get_height(), mode & 1);
31 const int is = wrap(i + 1,
L->
get_height(), mode & 1);
32 const int jw = wrap(j - 1,
L->
get_width (), mode & 2);
33 const int je = wrap(j + 1,
L->
get_width (), mode & 2);
35 double d1 =
L->
get(in, jw, k);
36 double d3 =
L->
get(in, je, k);
37 double d4 =
L->
get(i, jw, k);
38 double d6 =
L->
get(i, je, k);
39 double d7 =
L->
get(is, jw, k);
40 double d9 =
L->
get(is, je, k);
42 return d3 - d1 + 2.0 * (d6 - d4) + d9 - d7;
45 virtual void doc(std::ostream& out)
const
47 out <<
"sobelx " << mode;
66 virtual double get(
int i,
int j,
int k)
const
68 const int in = wrap(i - 1,
L->
get_height(), mode & 1);
69 const int is = wrap(i + 1,
L->
get_height(), mode & 1);
70 const int jw = wrap(j - 1,
L->
get_width (), mode & 2);
71 const int je = wrap(j + 1,
L->
get_width (), mode & 2);
73 double d1 =
L->
get(in, jw, k);
74 double d2 =
L->
get(in, j, k);
75 double d3 =
L->
get(in, je, k);
76 double d7 =
L->
get(is, jw, k);
77 double d8 =
L->
get(is, j, k);
78 double d9 =
L->
get(is, je, k);
80 return d7 - d1 + 2.0 * (d8 - d2) + d9 - d3;
83 virtual void doc(std::ostream& out)
const
85 out <<
"sobely " << mode;
100 :
image(L), dy(dy), dx(dx), mode(mode) { }
102 virtual double get(
int i,
int j,
int k)
const
104 const int in = wrap(i - 1, L->
get_height(), mode & 1);
105 const int is = wrap(i + 1, L->
get_height(), mode & 1);
106 const int jw = wrap(j - 1, L->
get_width (), mode & 2);
107 const int je = wrap(j + 1, L->
get_width (), mode & 2);
109 double d1 = L->
get(in, jw, k);
110 double d2 = L->
get(in, j, k);
111 double d3 = L->
get(in, je, k);
112 double d4 = L->
get(i, jw, k);
113 double d6 = L->
get(i, je, k);
114 double d7 = L->
get(is, jw, k);
115 double d8 = L->
get(is, j, k);
116 double d9 = L->
get(is, je, k);
118 double Ly = d7 - d1 + 2.0 * (d8 - d2) + d9 - d3;
119 double Lx = d3 - d1 + 2.0 * (d6 - d4) + d9 - d7;
121 return 0.5 + Ly * dy + Lx * dx;
130 virtual void doc(std::ostream& out)
const
132 out <<
"relief " << dy <<
" " << dx <<
" " << mode;
154 virtual double get(
int i,
int j,
int k)
const
156 const int in = wrap(i - 1,
L->
get_height(), mode & 1);
157 const int is = wrap(i + 1,
L->
get_height(), mode & 1);
158 const int jw = wrap(j - 1,
L->
get_width (), mode & 2);
159 const int je = wrap(j + 1,
L->
get_width (), mode & 2);
161 double d1 =
L->
get(in, jw, k);
162 double d2 =
L->
get(in, j, k);
163 double d3 =
L->
get(in, je, k);
164 double d4 =
L->
get(i, jw, k);
165 double d6 =
L->
get(i, je, k);
166 double d7 =
L->
get(is, jw, k);
167 double d8 =
L->
get(is, j, k);
168 double d9 =
L->
get(is, je, k);
170 double Lx = d3 - d1 + 2.0 * (d6 - d4) + d9 - d7;
171 double Ly = d7 - d1 + 2.0 * (d8 - d2) + d9 - d3;
173 return sqrt(Lx * Lx + Ly * Ly);
176 virtual void doc(std::ostream& out)
const
178 out <<
"gradient " << mode;
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
image(image *L=0, image *R=0)
Create a new image object with left child L and right child R. The parents of L and R are set to this...
Definition: image.hpp:26
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_sobel.hpp:130
Horizontal Sobel filter.
Definition: image_sobel.hpp:20
virtual void tweak(int a, int v)
Tweak image parameter a, changing the value by a factor of v.
Definition: image_sobel.hpp:124
sobelx(int mode, image *L)
Apply the horizontal 3x3 Sobel filter to image L. This will detect vertical lines in the input...
Definition: image_sobel.hpp:26
Gradient filter.
Definition: image_sobel.hpp:145
Base class for all image sources, filters, and operators.
Definition: image.hpp:20
gradient(int mode, image *L)
Compute the magnitude of the gradient of image L. This is the value of the greatest rate of change in...
Definition: image_sobel.hpp:152
virtual int get_height() const
Return the height of this image.
Definition: image.hpp:46
Vertical Sobol filter.
Definition: image_sobel.hpp:58
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_sobel.hpp:45
virtual int get_width() const
Return the height of this image.
Definition: image.hpp:56
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_sobel.hpp:176
sobely(int mode, image *L)
Apply the vertical 3x3 Sobel filter to image L. This will detect horizontal lines in the input...
Definition: image_sobel.hpp:64
Relief shading filter.
Definition: image_sobel.hpp:96
virtual void doc(std::ostream &out) const
Produce a string documenting the function of this object.
Definition: image_sobel.hpp:83