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