Loading...
Searching...
No Matches
ImageOpBank.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 DRAIN_IMAGE_OP_BANK_H_
32#define DRAIN_IMAGE_OP_BANK_H_
33
34//
35#include <iostream>
36
37
38
39#include "drain/util/Bank.h"
40#include "drain/util/FunctorPack.h"
41
42#include "ImageOp.h"
43#include "FunctorOp.h"
44
45#include "drain/prog/CommandBank.h"
46
47#include "drain/util/Cloner.h"
48#include "drain/util/Fuzzy.h"
49
50
51
52
53#include "RunLengthOp.h"
54
55#include "BlenderOp.h"
56
57#include "CatenatorOp.h"
58#include "CopyOp.h"
59#include "CropOp.h"
60#include "DistanceTransformFillOp.h"
61#include "DistanceTransformOp.h"
62#include "FastAverageOp.h"
63//#include "FastOpticalFlowOp.h"
64#include "FlowAverageWindowOp.h" // for SlidingWindowOp
65#include "FloodFillOp.h"
66#include "FunctorOp.h"
67#include "GaussianAverageOp.h"
68#include "DifferentialOp.h"
69#include "HighBoostOp.h"
70#include "HighPassOp.h"
71#include "ImpulseAvgOp.h"
72#include "MarginalStatisticOp.h"
73//#include "MotionExtrapolatorOp.h"
74//#include "MotionIllustratorOp.h"
75#include "MultiThresholdOp.h"
76#include "PixelVectorOp.h"
77#include "QualityMixerOp.h"
78#include "QualityOverrideOp.h"
79#include "QuantizatorOp.h"
80#include "ResizeOp.h"
81#include "RunLengthOp.h"
82#include "SegmentAreaOp.h"
83#include "SegmentStatisticsOp.h"
84#include "SlidingWindowHistogramOp.h"
85#include "SlidingWindowMedianOp.h"
86#include "TransposeOp.h"
87
88//#include "drain/image/SegmentProber.h"
89#include "SuperProberOp.h"
90
91
92namespace drain
93{
94
95namespace image
96{
97
98template <class T>
99class ImageOpCloner : public Cloner<ImageOp,T> {
100public:
101
102 static
103 const std::string & getName(){
104 static T op;
105 return op.getName();
106 }
107
108};
109
110template <class F>
111class UnaryFunctorOpCloner : public ImageOpCloner<UnaryFunctorOp<F> > {
112 public:
113};
114
115
116template <class F>
117class BinaryFunctorOpCloner : public ImageOpCloner<BinaryFunctorOp<F> > {
118 public:
119};
120
121
122class NegateOp : public ImageOp {
123
124public:
125
126 NegateOp() : ImageOp(__FUNCTION__, "Invert values (unsigned char or unsigned short int)"){
127 }
128
129 virtual inline
130 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
131 traverseChannelsEqually(src, dst);
132 }
133
134
136 virtual inline
137 void traverseChannel(const Channel & src, Channel & dst) const {
138
139 double srcMax = src.getConf().getTypeMax<double>();
140 double dstMax = dst.getConf().getTypeMax<double>();
141 double rescale = dstMax/srcMax;
142
144 Channel::iterator d = dst.begin();
145
146 while (d != dst.end()){
147 *d = dstMax - rescale*static_cast<double>(*s);
148 ++s;
149 ++d;
150 }
151
152 };
153
154
155
156};
157
158
159class ImageOpBank : public Bank<ImageOp> {
160
161public:
162
163 //CommandBank & cmdBank;
164
165 //ImageOpBank(CommandBank & cmdBank) : cmdBank(cmdBank) {
166 ImageOpBank() {
167 };
168
169 virtual
170 ~ImageOpBank(){}
171
173
176 template <class OP>
177 OP & install(const std::string & name = OP().getName()){
178
179 drain::Logger mout(getImgLog(), __FILE__, __FUNCTION__);
180
181 std::string key(name);
183 mout.warn() << name << ">" << OP().getName() << '>' << key << '\n';
184 return Bank<ImageOp>::add<OP>(key);
185 }
186
188 ImageOp & getComplete(const std::string & query, char separator=',', char assign='=', const drain::SmartMap<std::string> & aliasMap = drain::SmartMap<std::string>());
189
191 // Palette palette;
192
193};
194
195
196
197std::ostream & operator<<(std::ostream & ostr, const ImageOpBank & bank);
198
199
200
201// consider separate
202extern
204
205template <class T>
206void installImageOps(T & installer) {
207
208
209 try {
210 //installer.install<CmdHistogram>();
211 installer.template install<NegateOp>();
212 installer.template install<UnaryFunctorOp<ScalingFunctor> >("Rescale");
213 //installer.template install<UnaryFunctorOp<NegateFunctor> >();
214 installer.template install<UnaryFunctorOp<RemappingFunctor> >("Remap");
215 installer.template install<UnaryFunctorOp<ThresholdFunctor> >();
216 installer.template install<UnaryFunctorOp<BinaryThresholdFunctor> >("ThresholdBinary");
217
218
220 installer.template install<BinaryFunctorOp<AdditionFunctor> >("Add");
221 installer.template install<BinaryFunctorOp<DivisionFunctor> >("Div");
222 installer.template install<BinaryFunctorOp<MaximumFunctor> >("Max");
223 installer.template install<BinaryFunctorOp<MinimumFunctor> >("Min");
224 installer.template install<BinaryFunctorOp<MixerFunctor> >("Mix");
225 installer.template install<BinaryFunctorOp<MultiplicationFunctor> >("Mul");
226 installer.template install<BinaryFunctorOp<SubtractionFunctor> >("Sub");
227
228
230 installer.template install<UnaryFunctorOp<FuzzyBell<double>,true> >();
231 installer.template install<UnaryFunctorOp<FuzzyBell2<double>,true> >();
232 installer.template install<UnaryFunctorOp<FuzzyStep<double>,true> >();
233 installer.template install<UnaryFunctorOp<FuzzyStepsoid<double>,true> >();
234 installer.template install<UnaryFunctorOp<FuzzyTriangle<double>,true> >();
235 installer.template install<UnaryFunctorOp<FuzzyTwinPeaks<double>,true> >();
236
237
238 installer.template install<ChannelCatenatorOp>("Catenate");
239
240 installer.template install<CopyOp>();
241 installer.template install<CropOp>();
242
243 installer.template install<DistanceTransformLinearOp>("DistanceTransform"); // consider rename op
244 installer.template install<DistanceTransformExponentialOp>("DistanceTransformExp"); // consider rename op
245 installer.template install<DistanceTransformFillLinearOp>("DistanceTransformFill"); // consider rename op
246 installer.template install<DistanceTransformFillExponentialOp>("DistanceTransformFillExp"); // consider rename op
247
248 installer.template install<FastAverageOp>("Average");
249
250 installer.template install<FlowAverageOp>();
251
252 installer.template install<BlenderOp>();
253
254 installer.template install<ImpulseResponseOp<ImpulseAvg> >("impulseAvg"); // consider getName -> avg.getName()
255
256
257 //static ImageOpCloner<FastOpticalFlowOp> fastopticalflow;
258 //bank.template install< >(fastopticalflow);
259
260 installer.template install<FloodFillOp>();
261
262 // static ImageOpCloner<FunctorOp> functor;
263 installer.template install<UnaryFunctorOp<GammaFunctor,true> >();
264
265 //installer.template install<QuantizatorOp>();
266 installer.template install<UnaryFunctorOp<QuantizatorFunctor> >();
267
268 installer.template install<GaussianAverageOp>();
269
271 installer.template install<GradientOp>();
272 installer.template install<GradientHorzOp>();
273 installer.template install<GradientVertOp>();
274 installer.template install<LaplaceOp>();
275 installer.template install<LaplaceHorzOp>();
276 installer.template install<LaplaceVertOp>();
277
278
279 installer.template install<HighBoostOp>();
280
281 installer.template install<HighPassOp>();
282
283 installer.template install<MarginalStatisticOp>("marginStat"); // consider rename op
284
285 //static ImageOpCloner<MotionExtrapolatorOp> motionextrapolator;
286 //static ImageOpCloner<MotionIllustratorOp> motionillustrator;
287 //static ImageOpCloner<PaletteOp> palette;
288
289 //static ImageOpCloner<PixelVectorOp> pixelvector;
290 //bank.template install< >(pixelvector, "pixelvector");
291 installer.template install<GrayOp>();
292 installer.template install<DistanceOp>();
293 installer.template install<ProductOp>();
294 installer.template install<MagnitudeOp>();
295
296 installer.template install<MultiThresholdOp>();
297
298 //static ImageOpCloner<Distance2Op> distance2;
299 //bank.template install< >(distance2);
300
301 // installer.template install<QuadraticSmootherOp>();
302 // static ImageOpCloner<QuadraticSmootherOp> quadraticSmoother;
303 // bank.template install< >(quadraticSmoother);
304 installer.template install<QualityThresholdOp>();
305
306 installer.template install<QualityMixerOp>();
307
308 installer.template install<QualityOverrideOp>();
309
310
311 installer.template install<ResizeOp>();
312
313 //static ImageOpCloner<RecursiveRepairerOp> recursiveRepairer;
314 //bank.template install< >(recursiveRepairer);
315
316 installer.template install<RunLengthHorzOp>();
317 installer.template install<RunLengthVertOp>();
318
319 installer.template install<SegmentAreaOp<float,unsigned short> >();
320 installer.template install<SegmentStatisticsOp>("segmentStats");
321
322 // Experimental
323 installer.template install<SuperProberOp>();
324
325
326 installer.template install<SlidingWindowHistogramOp>("windowHistogram");
327 installer.template install<SlidingWindowMedianOp>("median");
328 installer.template install<TransposeOp>();
329
330 //static ImageOpCloner<ImageOp> image;
331 //static ImageOpCloner<SequentialImageOp> sequentialimage;
332 //bank.template install< >(sequentialimage, "sequentialimage");
333 //static ImageOpCloner<SlidingWindowOp> slidingWindow;
334 //bank.template install< >(slidingWindow);
335 //static ImageOpCloner<WindowOp> window;
336 //bank.install< >(window, "window");
337
338 } catch (std::exception & e) {
339 std::cerr << "Bank " << e.what() << std::endl;
340 }
341
342
343}
344
345
346}
347
348}
349
350#endif
351
352// Drain
Definition Bank.h:63
Definition CastableIterator.h:57
static void deriveCmdName(std::string &name, char prefix=0)
Given a command class name like MyFileReadCommand, derives a respective command line option ("myFileR...
Definition CommandBank.cpp:63
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
A base class for smart maps providing methods for importing and exporting values, among others.
Definition SmartMap.h:62
Definition ImageOpBank.h:117
Image with static geometry.
Definition ImageChannel.h:58
T getTypeMax() const
Returns the maximum value supported by the current storage type.
Definition ImageConf.h:281
const iterator & begin()
Returns iterator pointing to the first image element.
Definition ImageFrame.h:114
const iterator & end()
Returns the iterator pointing to the element after the last element of the image buffer.
Definition ImageFrame.h:120
Definition ImageOpBank.h:159
ImageOp & getComplete(const std::string &query, char separator=',', char assign='=', const drain::SmartMap< std::string > &aliasMap=drain::SmartMap< std::string >())
Supports querying operator with parameters set, eg. gaussianAverage,width=10,height=5.
Definition ImageOpBank.cpp:43
OP & install(const std::string &name=OP().getName())
Add ImageOp command to registry (CommandBank).
Definition ImageOpBank.h:177
Definition ImageOpBank.h:99
Base class for image processing functions.
Definition ImageOp.h:49
void traverseChannelsEqually(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Calls processWithTemp() if the frames overlap.
Definition ImageOp.cpp:414
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
Definition ImageOpBank.h:122
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition ImageOpBank.h:137
Definition ImageOpBank.h:111
ImageOpBank & getImageOpBank()
Definition ImageOpBank.cpp:124
void installImageOps(T &installer)
Definition ImageOpBank.h:206
Definition DataSelector.cpp:1277
Wrapper for derived class S, returning base class T.
Definition Cloner.h:118