Loading...
Searching...
No Matches
BlenderOp.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 BLENDER_OP
32#define BLENDER_OP "BlenderOp Markus.Peura@iki.fi"
33
34#include "WindowOp.h"
35
36#include "DistanceTransformOp.h"
37#include "DistanceTransformFillOp.h"
38#include "FastAverageOp.h"
39#include "FlowAverageWindowOp.h"
40#include "GaussianAverageOp.h"
41#include "QualityMixerOp.h"
42#include "QualityOverrideOp.h"
43
44#include "drain/util/FunctorPack.h"
45//#include "SlidingStripeAverageOp.h"
46
47namespace drain
48{
49namespace image
50{
51
52
54
94class BlenderOp: public WindowOp<> {
95
96public:
97
99 // TODO Rename, and use blender only for the op that mixes filtered t unfiltered
103 // TODO: re-consider the order of params?
104 // BlenderOp(int width=5, int height=0, char spreader='a', char mixer='m', unsigned short loops=1) : // , double coeff=0.5
105 BlenderOp(int width=5, int height=0, const std::string & spreader="avg", const std::string & blender="max",
106 unsigned short loops=1, double expansionCoeff=1.0) : // , double coeff=0.5
107 WindowOp<>(__FUNCTION__, "Smoothes image repeatedly, mixing original image with the result at each round.", width, height){
108 parameters.link("spreader", this->spreader = spreader, getSmootherAliasMap<false>().toStr()); //"a|g|d|D; avg, gaussianAvg, dist, distExp");
109 parameters.link("mix", this->blender = blender, "max|<coeff>: (quality) max, (quality) blend");
110 parameters.link("loops", this->loops = loops, "number of repetitions");
111 parameters.link("expansionCoeff", this->expansionCoeff = expansionCoeff, "window enlargement");
112 };
113
114 // Every Op should have a copy const
115 BlenderOp(const BlenderOp & op) : WindowOp<>(op) {
116 parameters.copyStruct(op.getParameters(), op, *this);
117 };
118
119
120
121 inline
122 const std::string & getSmootherKey(){
123 return spreader;
124 }
125
126 virtual inline
127 void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const {
128 if (conf.frame.height == 0){
129 conf.frame.height = conf.frame.width;
130 }
131 }
132
134 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const;
135
136
138 inline
139 virtual void traverseChannel(const Channel &src, Channel & dst) const {
140 traverseAsChannelTrays(src, dst);
141 }
142
144 inline
145 void traverseChannel(const Channel &src, const Channel &srcWeight, Channel & dst, Channel & dstWeight) const {
146 traverseAsChannelTrays(src, srcWeight, dst, dstWeight);
147 }
148
149protected:
150
151 //mutable drain::SmartMap<std::string> aliasMap;
152
153 template <bool WEIGHTED=false>
154 static
156 static drain::SmartMap<std::string> aliasMap;
157 if (aliasMap.empty()){
159 /*
160 aliasMap["a"] = "average";
161 aliasMap["f"] = "flowAverage"; // magnitude/energy saving
162 aliasMap["g"] = "gaussianAverage";
163 aliasMap["d"] = WEIGHTED ? "distanceTransformFill" : "distanceTransform";
164 aliasMap["D"] = WEIGHTED ? "distanceTransformFillExp" : "distanceTransformExp";
165 */
166 // NEW
167 aliasMap["avg"] = "average";
168 aliasMap["avgFlow"] = "flowAverage"; // magnitude/energy saving
169 aliasMap["avgGauss"] = "gaussianAverage";
170 aliasMap["dist"] = WEIGHTED ? "distanceTransformFill" : "distanceTransform";
171 aliasMap["distExp"] = WEIGHTED ? "distanceTransformFillExp" : "distanceTransformExp";
172 }
173 return aliasMap;
174 }
175
176 template <bool WEIGHTED=false>
177 static
178 const drain::SmartMap<std::string> & getMixerAliasMap(){
179 static drain::SmartMap<std::string> aliasMap;
180 //aliasMap["b"] = WEIGHTED ? "qualityMixer" : "mix";
181 //aliasMap["m"] = WEIGHTED ? "qualityOverride" : "max";
182 // NEW
183 aliasMap["blend"] = WEIGHTED ? "qualityMixer" : "mix";
184 aliasMap["max"] = WEIGHTED ? "qualityOverride" : "max";
185 return aliasMap;
186 }
187
188
189 // SMOOTHING
190 std::string spreader;
191
192 // MIXING
193 std::string blender;
194
195 // int width=5, int height=0, char spreader='a', char blender='m', unsigned short loops=1
196 //void initRefs();
197
198 //double coeff;
199 unsigned short loops;
200
201 double expansionCoeff;
202
206 //ImageOp & getSmoother(const std::string & key, bool weighted, unsigned short & loops) const;
207
208 //ImageOp & getMixer(const std::string & key, bool weighted) const;
209 // double coeff;
210
211
212};
213
214
215
216
217} // namespace drain
218
219} //namespace image
220
221
222#endif
223
224// 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
A base class for smart maps providing methods for importing and exporting values, among others.
Definition SmartMap.h:66
Smoothes image and mixes the result with the original.
Definition BlenderOp.h:94
void traverseChannels(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Main operation, requires weighted image data.
Definition BlenderOp.cpp:44
virtual void traverseChannel(const Channel &src, Channel &dst) const
Force multi-channel processing.
Definition BlenderOp.h:139
static const drain::SmartMap< std::string > & getSmootherAliasMap()
Definition BlenderOp.h:155
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition BlenderOp.h:127
BlenderOp(int width=5, int height=0, const std::string &spreader="avg", const std::string &blender="max", unsigned short loops=1, double expansionCoeff=1.0)
Default constructor.
Definition BlenderOp.h:105
void traverseChannel(const Channel &src, const Channel &srcWeight, Channel &dst, Channel &dstWeight) const
Force multi-channel processing.
Definition BlenderOp.h:145
Image with static geometry.
Definition ImageChannel.h:60
Image with static geometry.
Definition ImageFrame.h:67
void traverseAsChannelTrays(const ImageFrame &src, ImageFrame &dst) const
Redirect to processing as trays. This is the opposite of processChannels...() functions.
Definition ImageOp.h:216
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:267
Definition WindowOp.h:50
Definition DataSelector.cpp:1277