Loading...
Searching...
No Matches
DifferentialOp.h
1/*
2
3MIT License
4
5Copyright (c) 2017 FMI Open Development / Markus Peura, first.last@fmi.fi
6
7Permission is hereby granted, free of charge, to any person obtaining a copy
8of this software and associated documentation files (the "Software"), to deal
9in the Software without restriction, including without limitation the rights
10to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11copies of the Software, and to permit persons to whom the Software is
12furnished to do so, subject to the following conditions:
13
14The above copyright notice and this permission notice shall be included in all
15copies or substantial portions of the Software.
16
17THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23SOFTWARE.
24
25*/
26/*
27Part of Rack development has been done in the BALTRAD projects part-financed
28by the European Union (European Regional Development Fund and European
29Neighbourhood Partnership Instrument, Baltic Sea Region Programme 2007-2013)
30*/
31#ifndef GradientOP_H_
32#define GradientOP_H_
33
34
35#include <math.h>
36
37#include "ImageOp.h"
38
39namespace drain
40{
41
42namespace image
43{
44
45
47
50// TODO: consider changing "span=2" to "radius=1"
51class DifferentialOp : public ImageOp
52{
53
54public:
55
56 virtual
57 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const;
58
59 virtual
60 void getDstConf(const ImageConf & src, ImageConf & dst) const;
61 //void makeCompatible(const ImageFrame & src, Image & dst) const;
62
63
64protected:
65
66 inline
67 DifferentialOp(const std::string & name, const std::string & description, size_t channels=1, int radius=1) : // , double scale=1.0, double bias=0.0
68 ImageOp(name, description), channels(channels) {
69 //parameters.link("span", this->span = span, "pix");
70 parameters.link("radius", this->radius = radius, "pix");
71 parameters.link("LIMIT", this->LIMIT = true, "0|1");
72 };
73
74 inline
75 DifferentialOp(const DifferentialOp & op) : ImageOp(op), radius(op.radius), channels(op.channels), LIMIT(op.LIMIT) {
76 parameters.copyStruct(op.getParameters(), op, *this);
77 };
78
79
80 // double bias;
81 // double scale;
82 // int span;
83 int radius;
84
85 const size_t channels;
86
87public:
88
90 bool LIMIT;
91
92protected:
93
94
95 // Consider image range limited by 1 pix, to skip CoordinateHandler::validate() .
96 virtual
97 void traverse(const Channel & src, Channel & dst, int di, int dj) const = 0;
98
99
100 inline
101 void traverseHorz(const Channel & src, Channel & dst) const {
102 traverse(src, dst, radius, 0);
103 }
104
105 inline
106 void traverseVert(const Channel & src, Channel & dst) const {
107 traverse(src, dst, 0, radius);
108 }
109
110};
111
112
114
124{
125public:
126
127 GradientOp(int radius=1) : DifferentialOp(__FUNCTION__,
128 "Computes horizontal and vertical derivatives: df/di and df/dj.", 2, radius) { // , scale, bias
129 };
130
131 GradientOp(const GradientOp & op) : DifferentialOp(op){
132 }
133
134
135protected:
136
137 GradientOp(const std::string & name, const std::string & description, size_t channels=1 , int radius=1) :
138 DifferentialOp(name, description, channels, radius){
139 };
140
141 virtual
142 void traverse(const Channel & src, Channel & dst, int di, int dj) const;
143
144};
145
155{
156public:
157
158 GradientHorzOp(int radius=1) :
159 GradientOp(__FUNCTION__, "Horizontal intensity difference", 1, radius){};
160
161 inline
162 void traverseChannel(const Channel &src, Channel & dst) const {
163 traverseHorz(src, dst);
164 }
165
166};
167
177{
178public:
179
180 inline
181 GradientVertOp(int radius=1) : // double scale=1.0, double bias=0.0,
182 GradientOp(__FUNCTION__, "Vertical intensity difference", 1 , radius){}; // , scale, bias
183
184 inline
185 void traverseChannel(const Channel &src, Channel & dst) const {
186 traverseVert(src, dst);
187 }
188
189};
190
191
193
202class LaplaceOp : public DifferentialOp {
203
204public:
205
206 LaplaceOp(int radius=1) : DifferentialOp(__FUNCTION__, "Second intensity derivatives, (df/di)^2 and (df/dj)^2", 2, radius){
207 }
208
209protected:
210
211 LaplaceOp(const std::string & name, const std::string & description, int radius=1) : DifferentialOp(name, description, 1, radius){
212 }
213
214 virtual
215 void traverse(const Channel &src, Channel &dst, int di, int dj) const;
216 //void traverse(const ImageFrame &src, ImageFrame &dst, int diLow, int djLow, int diHigh, int djHigh) const;
217
218};
219
221
232{
233public:
234
235 inline
236 LaplaceHorzOp(int radius=1) : LaplaceOp(__FUNCTION__, "Second horizontal differential"){
237 this->radius = radius;
238 };
239
240 inline
241 void traverseChannel(const Channel &src, Channel & dst) const {
242 traverseHorz(src, dst);
243 };
244
245};
246
248
261{
262public:
263
264 inline
265 LaplaceVertOp(int radius=1) : LaplaceOp(__FUNCTION__, "Second vertical differential"){
266 this->radius = radius;
267 };
268
269
270 inline
271 void traverseChannel(const Channel &src, Channel & dst) const {
272 traverseVert(src, dst);
273 };
274
275};
276
277}
278}
279
280
281#endif /*GradientOP_H_*/
282
283// Drain
void copyStruct(const ReferenceMap &m, const T &src, T &dst, extLinkPolicy policy=RESERVE)
Experimental. Copies references and values of a structure to another.
Definition ReferenceMap.h:399
Image with static geometry.
Definition ImageChannel.h:60
Virtual base class for horizontal and vertical intensity derivatives.
Definition DifferentialOp.h:52
bool LIMIT
Applied only for unsigned dst types.
Definition DifferentialOp.h:90
virtual void getDstConf(const ImageConf &src, ImageConf &dst) const
Given source image, determine respective dest image configuration.
Definition DifferentialOp.cpp:46
Definition DifferentialOp.h:155
void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition DifferentialOp.h:162
Computes spatial horizontal derivatives (dx and dy).
Definition DifferentialOp.h:124
virtual void traverse(const Channel &src, Channel &dst, int di, int dj) const
Definition DifferentialOp.cpp:115
Definition DifferentialOp.h:177
void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition DifferentialOp.h:185
Struct for image (excluding data)
Definition ImageConf.h:333
Base class for image processing functions.
Definition ImageOp.h:49
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
Computes second horizontal derivative, dx2.
Definition DifferentialOp.h:232
void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition DifferentialOp.h:241
Computes second intensity derivatives.
Definition DifferentialOp.h:202
virtual void traverse(const Channel &src, Channel &dst, int di, int dj) const
Definition DifferentialOp.cpp:224
Computes second vertical derivative, dy2.
Definition DifferentialOp.h:261
void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition DifferentialOp.h:271
Definition DataSelector.cpp:1277