Loading...
Searching...
No Matches
SeparableWindowOp.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 SeparableWindowOP_H_
32#define SeparableWindowOP_H_
33
34
35#include "drain/image/SlidingWindow.h"
36#include "WindowOp.h"
37
38namespace drain
39{
40
41namespace image
42{
43
45
62// Consider diff assert here! ^^
63
64class SeparableWindowOp : public WindowOp<GaussianStripe<WindowCore> >
65{
66public:
67
71 SeparableWindowOp(int width=1, int height=0, double halfwidth=0.5);
72
74
79 virtual
80 inline
81 void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const {
82 }
83
84 virtual
85 void traverseChannels(const ImageTray<const Channel> & src, ImageTray<Channel> & dst) const {
86 this->processChannelsSeparately(src, dst);
87 }
88
89
90 virtual
91 void traverseChannel(const Channel & src, Channel &dst) const ;
92
93 virtual
94 void traverseChannel(const Channel & src, const Channel & srcAlpha, Channel &dst, Channel & dstAlpha) const ;
95
96
97
98protected:
99
100};
101
102
103
104SeparableWindowOp::SeparableWindowOp(int width, int height, double radius) :
105 WindowOp<GaussianStripe<WindowCore> >(__FUNCTION__, "Gaussian blur implemented as quick Wx1 and 1xH filtering.") {
106
107 this->conf.width = width;
108 this->conf.height = height;
109 parameters.link("radius", this->conf.radius = radius, "iDistance, relative to width and height, where gaussian kernel obtains value 0.5.");
110
111}
112
113
114void SeparableWindowOp::traverseChannel(const Channel & src, Channel & dst) const {
115
116 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
117
118 // TODO: generalize!
119
120 Image tmp;
121 makeCompatible(src, tmp);
122 //makeCompatible(src, dst); // unneeded in traverse?
123
124
125 // GaussianStripeHorz window1(conf.width, 0.5*conf.radius*static_cast<double>(conf.width));
126 // GaussianStripe2<true> window1(conf.width, 0.5*conf.radius*static_cast<double>(conf.width));
128
129 // Jotestin setParams
130 window.setSrc(src);
131 window.setDst(tmp);
132 mout.debug(window );
133 window.runHorz();
134
135 window.setSrc(tmp);
136 window.setDst(dst);
137 mout.debug(window );
138 window.runVert();
139
140 dst.scaling.setScale(src.scaling.getScale());
141}
142
143//void SeparableWindowOp::process(const ImageFrame & src, const ImageFrame & srcWeight, Image & dst, Image & dstWeight) const {
144void SeparableWindowOp::traverseChannel(const Channel & src, const Channel & srcWeight, Channel & dst, Channel & dstWeight) const {
145
146 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
147
148 Image tmp;
149 Image tmpWeight;
150 makeCompatible(src, tmp);
151 makeCompatible(srcWeight, tmpWeight);
152 //makeCompatible(src, dst);
153 //makeCompatible(srcWeight, dstWeight);
154
155 GaussianStripeWeighted2<true> window1(conf.width, 0.5*conf.radius*static_cast<double>(conf.width));
156
157
158 window1.setSrc(src);
159 window1.setSrcFrameWeight(srcWeight);
160 window1.setDst(tmp);
161 window1.setDstFrame1Weight(tmpWeight);
162 mout.debug(window1 );
163 window1.run();
164 // File::write(tmp, "gauss1d.png");
165 // File::write(tmpWeight, "gauss1w.png");
166
167 const int h = (conf.height>0.0) ? conf.height : conf.width;
168 GaussianStripeWeighted2<false> window2(h, 0.5*conf.radius*static_cast<double>(h));
169 window2.setSrc(tmp);
170 window2.setSrcFrameWeight(tmpWeight);
171 window2.setDst(dst);
172 window2.setDstFrame1Weight(dstWeight);
173 mout.debug(window2 );
174 window2.run();
175
176 dst.scaling.setScale(src.scaling.getScale());
177
178}
179
180
181
182} // image::
183
184} // drain::
185
186#endif
187
188// Drain
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:313
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Image with static geometry.
Definition ImageChannel.h:58
Definition GaussianWindow.h:59
Image with static geometry.
Definition ImageFrame.h:62
virtual int srcAlpha() const
Tell if alpha channel(s) is required in input.
Definition ImageMod.h:66
virtual void processChannelsSeparately(ImageTray< Channel > &dst) const
Run this modifier by calling traverseChannel(Channel &) for each image.
Definition ImageMod.cpp:66
virtual void makeCompatible(const ImageConf &src, Image &dst) const
Depending on the operator, modifies the geometry and type of dst.
Definition ImageOp.cpp:54
Container applicable for Channels and Images, with alpha support.
Definition ImageTray.h:266
Class for multi-channel digital images. Supports dynamic typing with base types (char,...
Definition Image.h:183
Sliding window averaging operator with optional weighting support.
Definition SeparableWindowOp.h:65
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition SeparableWindowOp.h:114
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Top-level function that delegates the invocation to each image channel.
Definition SeparableWindowOp.h:81
SeparableWindowOp(int width=1, int height=0, double halfwidth=0.5)
Definition SeparableWindowOp.h:104
Window implementation that uses incremental update of state.
Definition SlidingWindow.h:50
Container for source and target images, and their setters.
Definition Window.h:192
Definition WindowOp.h:50
Definition DataSelector.cpp:1277