31 #ifndef ImpulseResponse2_H
32 #define ImpulseResponse2_H
34 #include <drain/image/CoordinatePolicy.h>
39 #include "drain/image/FilePng.h"
72 void addLeft(
int i,
double value,
double weight) = 0;
76 void addRight(
int i,
double value,
double weight) = 0;
80 void addDown(
int i,
double value,
double weight) = 0;
84 void addUp(
int i,
double value,
double weight) = 0;
89 double get(
int i) = 0;
124 return this->conf.getName();
129 return this->conf.getDescription();
133 typename T::conf_t conf;
169 this->parameters.
append(this->conf.getParameters());
170 this->parameters.link(
"extendHorz", extendHorz = 0,
"pix");
171 this->parameters.link(
"extendVert", extendVert = 0,
"pix");
172 this->parameters.link(
"weightThreshold", weightThreshold = 0.05,
"[0..1.0]");
218 void setExtensions(
int horz,
int vert){
227 double weightThreshold;
235 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
237 mout.
debug(
"delegating to traverseChannel(src, empty, dst, empty)" );
240 traverseChannel(src, empty, dst, empty);
247 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
249 dst.setScaling(src.getScaling());
254 mout.
warn(dst.getProperties() );
256 traverseChannelHorz(src, srcWeight, dst, dstWeight);
257 traverseChannelVert(dst, dstWeight, dst, dstWeight);
265 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
269 const bool UNWEIGHTED = (srcWeight.isEmpty() || dstWeight.isEmpty());
271 const int width = src.getWidth();
272 const int widthExt = src.getWidth()+extendHorz;
273 const int height = src.getHeight();
274 const double defaultWeight = 1.0;
283 T bucket(this->conf);
284 bucket.init(src,
true);
288 for (
int j=0; j<height; ++j){
295 for (
int i=-extendHorz; i<widthExt; ++i){
297 point.setLocation(i, j);
298 coordHandler.handle(point);
300 bucket.addLeft(point.x, src.
get<
double>(point.x, point.y), defaultWeight);
303 point.setLocation(width-1-i, j);
304 coordHandler.handle(point);
306 bucket.addRight(point.x, src.
get<
double>(point.x, point.y), defaultWeight);
312 for (
int i=0; i<width; ++i){
320 for (
int i=-extendHorz; i<widthExt; ++i){
322 point.setLocation(i, j);
323 coordHandler.handle(point);
325 bucket.addLeft(point.x, src.
get<
double>(point.x, point.y), srcWeight.
getScaled(point.x, point.y));
328 point.setLocation(width-1-i, j);
329 coordHandler.handle(point);
331 bucket.addRight(point.x, src.
get<
double>(point.x, point.y), srcWeight.
getScaled(point.x, point.y));
337 for (
int i=0; i<width; ++i){
338 w = bucket.getWeight(i);
339 if (w > weightThreshold){
355 void ImpulseResponseOp<T>::traverseChannelVert(
const Channel & src,
const Channel & srcWeight, Channel & dst, Channel & dstWeight)
const {
357 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
361 const bool UNWEIGHTED = (srcWeight.isEmpty() || dstWeight.isEmpty());
363 const int width = src.getWidth();
364 const int height = src.getHeight();
365 const int heightExt = src.getHeight() + extendVert;
366 const double defaultWeight = 1.0;
374 T bucket(this->conf);
375 bucket.init(src,
false);
379 for (
int i=0; i<width; i++){
386 for (
int j=-extendVert; j<heightExt; ++j){
388 point.setLocation(i, j);
389 coordHandler.handle(point);
390 bucket.addLeft(point.y, src.get<
double>(point.x, point.y), defaultWeight);
392 point.setLocation(i, height-1-j);
393 coordHandler.handle(point);
394 bucket.addRight(point.y, src.get<
double>(point.x, point.y), defaultWeight);
399 for (
int j=0; j<height; ++j){
400 dst.putScaled(i,j, bucket.get(j));
407 for (
int j=-extendVert; j<heightExt; ++j){
409 point.setLocation(i, j);
410 coordHandler.handle(point);
411 bucket.addLeft(point.y, src.get<
double>(point.x, point.y), srcWeight.getScaled(point.x, point.y));
413 point.setLocation(i, height-1-j);
414 coordHandler.handle(point);
415 bucket.addRight(point.y, src.get<
double>(point.x, point.y), srcWeight.getScaled(point.x, point.y));
420 for (
int j=0; j<height; ++j){
421 w = bucket.getWeight(j);
422 if (w > weightThreshold){
423 dst.putScaled(i,j, bucket.get(j));
424 dstWeight.putScaled(i,j, w);
427 dstWeight.putScaled(i,j, 0);
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition: Log.h:426
Logger & debug(const TT &... args)
Public, yet typically used "internally", when TIMING=true.
Definition: Log.h:676
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition: ReferenceMap.h:320
Image with static geometry.
Definition: ImageChannel.h:60
Definition: CoordinateHandler.h:62
double getScaled(size_t i, size_t j) const
Get intensity in original physical scale.
Definition: ImageFrame.h:287
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
void putScaled(size_t i, size_t j, double x)
Put intensity using original physical value.
Definition: ImageFrame.h:241
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets the supported range for physical values and optionally adjusts the scaling for maximal resolutio...
Definition: ImageFrame.h:106
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
Base class for image processing functions.
Definition: ImageOp.h:49
void traverseChannelsSeparately(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Process each (src,dst) channel pair independently. Raise error if their counts differ.
Definition: ImageOp.cpp:340
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
Definition: ImpulseResponseOp.h:54
virtual double get(int i)=0
Return natural (not encoded) value at position i.
virtual void addRight(int i, double value, double weight)=0
When traversing down or right, add a encoded value to bucket in position i.
virtual void reset()=0
Clear statistics before traversing each row or column.
virtual double getWeight(int i)=0
Return weight at position i.
virtual void addLeft(int i, double value, double weight)=0
When traversing up or left, add a encoded value to bucket in position i.
virtual void addDown(int i, double value, double weight)=0
When traversing down or right, add a encoded value to bucket in position i.
virtual void init(const Channel &src, bool horizontal=true)
Adapt to input geometry, type, and scaling.
Definition: ImpulseResponseOp.h:64
virtual void addUp(int i, double value, double weight)=0
When traversing up or left, add a encoded value to bucket in position i.
Definition: ImpulseResponseOp.h:108
virtual const std::string & getName() const
Return the name of an instance.
Definition: ImpulseResponseOp.h:123
virtual const std::string & getDescription() const
Return a brief description.
Definition: ImpulseResponseOp.h:128
A fill operation for one color.
Definition: ImpulseResponseOp.h:147
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition: ImpulseResponseOp.h:234
Definition: DataSelector.cpp:1277