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