35#include <drain/image/ImageFile.h>
36#include <drain/TypeUtils.h>
37#include "drain/util/Functor.h"
82 this->getParameters().
copyStruct(op.getParameters(), op, *
this);
88 void adaptParameters(
bool adaptLimit =
false){
90 p.
append(this->functor.getParameters());
93 p.link(
"LIMIT", this->LIMIT);
102 bool processOverlappingWithTemp(
const ImageFrame & srcFrame,
Image & dstImage)
const {
115 FunctorOp(
bool adaptParams =
false,
bool adoptLimit =
false) :
120 adaptParameters(adoptLimit);
133template <
class F,
bool NORM=false,
bool SIGN=false>
148 this->parameters.
copyStruct(op.parameters, op, *
this);
153 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
156 mout.debug2(
"invoking processChannelsSeparately()" );
195 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
196 mout.
warn(this->functor.getName() ,
" would need signed type instead of : " , dst.
getEncoding() );
208 dst.setGeometry(src.getGeometry());
218 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
220 this->functor.updateBean();
226template <
class T,
bool NORM,
bool SIGN>
230 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
231 mout.
debug(
"start" );
236 mout.
debug(
"SCALE=" , (
int)SCALE );
237 mout.
debug(
"functor=" , this->functor );
240 if (drain::Type::call<drain::typeIsInteger>(src.
getType())){
241 mout.
warn(
"float dst type, but LIMIT applied" , dst );
242 const double coeff = 0.01 * drain::Type::call<drain::typeMax,double>(src.
getType());
244 for (
int i = 0; i < 100; ++i) {
245 d = ::round(coeff *
static_cast<double>(i));
246 std::cout << __FILE__ <<
':' << __FUNCTION__ <<
':' << d <<
"\t -> ";
248 std::cout << d <<
"\t";
249 d = this->functor(d);
250 std::cout << d <<
"\t";
252 std::cout << d <<
'\n';
261 mout.info(DRAIN_LOG(srcScale));
262 mout.info(DRAIN_LOG(dstScale));
271 while (d != dst.
end()){
272 *d = this->functor(
static_cast<double>(*s));
278 while (d != dst.
end()){
279 *d = dstScale.
inv(this->functor(srcScale.
fwd(
static_cast<double>(*s))));
287 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType())){
288 mout.
warn(
"float dst type, but LIMIT applied" , dst );
294 while (d != dst.
end()){
295 *d = limiter(this->functor(
static_cast<double>(*s)));
301 while (d != dst.
end()){
302 *d = limiter(dstScale.
inv(this->functor(srcScale.
fwd(
static_cast<double>(*s)))));
336 this->parameters.
copyStruct(op.parameters, op, *
this);
346 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
348 mout.debug2(
"delegating to: processChannelsRepeated(src, dst)" );
355 mout.
debug2(
"delegating unary src to binary, with src2=dst: (src, dst) => (src,dst, dst) " );
375 mout.debug2(
"start: " , *
this );
376 mout.debug3(
"src1: " , src1 );
377 mout.debug3(
"src2: " , src2 );
379 if ((src1.getGeometry() == src2.getGeometry()) && (src1.getGeometry() == dst.getGeometry()) ){
383 traverseSpatially(src1, src2, dst);
391 void traverseSpatially(
const Channel &src1,
const Channel &src2, Channel & dst)
const;
397 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
398 mout.
debug(
"Unary init for Binary" );
400 this->functor.updateBean();
410 this->functor.updateBean();
423 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
424 mout.
warn(
"2nd image empty, problems ahead" , *
this );
425 dst.setGeometry(src.getGeometry());
440 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
441 mout.
debug(
"start, " , this->functor );
448 mout.
debug(
"SCALE::" , (
int)SCALE );
450 mout.
debug(
"s1 scale:" , s1s );
451 mout.
debug(
"s2 scale:" , s2s );
452 mout.
debug(
"d scale:" , ds );
460 mout.
debug(
"LIMIT=False" );
463 while (d != dst.
end()){
464 *d = this->functor(*s1, *s2);
471 while (d != dst.
end()){
472 *d = ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2)));
479 mout.
debug(
"LIMIT=True" );
480 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
481 mout.
warn(
"float dst type, but LIMIT applied" , dst );
485 while (d != dst.
end()){
486 *d = limit(this->functor(*s1, *s2));
492 while (d != dst.
end()){
493 *d = limit(ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2))));
505 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
506 mout.debug(
"start" );
509 const size_t width1 = src1.getWidth();
510 const size_t height1 = src1.getHeight();
514 const size_t width2 = src2.getWidth();
515 const size_t height2 = src2.getHeight();
518 mout.debug2(handler1 );
519 mout.debug2(handler2 );
521 const size_t width = dst.getWidth();
522 const size_t height = dst.getHeight();
533 mout.debug(
"LIMIT=false" );
535 mout.debug(
"SCALE=false" );
536 for (
size_t i = 0; i < width; ++i) {
537 for (
size_t j = 0; j < height; ++j) {
538 handler1.handle( p1.setLocation(i,j) );
539 handler2.handle( p2.setLocation(i,j) );
540 dst.
put(i,j, this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2)));
545 mout.debug(
"SCALE=true" );
546 for (
size_t i = 0; i < width; ++i) {
547 for (
size_t j = 0; j < height; ++j) {
548 handler1.handle( p1.setLocation(i,j) );
549 handler2.handle( p2.setLocation(i,j) );
550 dst.
put(i,j, dst.getScaling().
inv(this->functor(
551 src1.getScaling().
fwd(src1.
get<
double>(p1)),
552 src2.getScaling().
fwd(src2.
get<
double>(p2))
560 mout.debug(
"LIMIT=true" );
561 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
562 mout.warn(
"float dst type, but LIMIT applied" , dst );
569 mout.debug(
"SCALE=false" );
570 for (
size_t i = 0; i < width; ++i) {
571 for (
size_t j = 0; j < height; ++j) {
572 handler1.handle( p1.setLocation(i,j) );
573 handler2.handle( p2.setLocation(i,j) );
574 dst.
put(i,j, limit(this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2))));
579 mout.debug(
"SCALE=true" );
581 for (
size_t i = 0; i < width; ++i) {
582 for (
size_t j = 0; j < height; ++j) {
583 handler1.handle( p1.setLocation(i,j) );
584 handler2.handle( p2.setLocation(i,j) );
585 dst.
put(i,j, limit(dst.getScaling().
inv(this->functor(
586 src1.getScaling().
fwd(src1.
get<
double>(p1)),
587 src2.getScaling().
fwd(src2.
get<
double>(p2))
virtual const std::string & getName() const
Return the name of an instance.
Definition BeanLike.h:82
virtual const std::string & getDescription() const
Return a brief description.
Definition BeanLike.h:87
Definition CastableIterator.h:57
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition Log.h:358
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:430
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:666
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:676
Definition ReferenceMap.h:207
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition ReferenceMap.h:328
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:407
Linear scaling and physical range for image intensities.
Definition ValueScaling.h:64
const Range< double > & getPhysicalRange() const
Returns a typical or supported range for physical values.
Definition ValueScaling.h:221
double getMinPhys() const
Returns the minimum physical value.
Definition ValueScaling.h:269
bool isScaled() const
Returns true, if scaling has effect ie. scale!=1.0 or offset!=0.0.
Definition ValueScaling.h:263
double fwd(double x) const
Forward scaling: given encoded value x, returns corresponding value (possibly physically meaningful).
Definition ValueScaling.h:295
virtual void setScaling(double scale, double offset)
Set linear scaling.
Definition ValueScaling.h:136
double inv(double y) const
Inverse scaling: given physically meaningful value y, returns the corresponding code value.
Definition ValueScaling.h:301
virtual const ValueScaling & getScaling() const
Get linear scaling.
Definition ValueScaling.h:147
double getScale() const
Returns the intensity scaling factor. See set setScale()
Definition ValueScaling.h:252
Class for using two-parameter function objects (like std::functor) for sequential and spatial pixel i...
Definition FunctorOp.h:324
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition FunctorOp.h:353
virtual void traverseSequentially(const Channel &src1, const Channel &src2, Channel &dst) const
Definition FunctorOp.h:437
BinaryFunctorOp(bool adaptParams=true, bool adoptLimit=true)
Default constructor.
Definition FunctorOp.h:332
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:395
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &src2, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:405
void getDstConf(const ImageConf &src, ImageConf &dst) const
Does not change dst geometry.
Definition FunctorOp.h:417
Image with static geometry.
Definition ImageChannel.h:60
Definition CoordinateHandler.h:77
bool typeIsSet() const
Get the storage type.
Definition ImageConf.h:116
const Encoding & getEncoding() const
Return type and scaling.
Definition ImageConf.h:68
void setEncoding(const Encoding &e)
Set type and scaling.
Definition ImageConf.h:83
const std::type_info & getType() const
Linear scaling.
Definition ImageConf.h:110
void setPhysicalRange(const Range< double > &range, bool rescale=false)
Sets channel specific scaling instead of shared (image-level) scaling.
Definition ImageConf.h:229
Class for using simple function objects (like std::functor) for sequential pixel iteration.
Definition FunctorOp.h:75
FunctorOp(bool adaptParams=false, bool adoptLimit=false)
Definition FunctorOp.h:115
Struct for image (excluding data)
Definition ImageConf.h:333
void setCoordinatePolicy(const T &policy)
Does not set any CoordinateHandler object.
Definition ImageConf.h:368
Image with static geometry.
Definition ImageFrame.h:64
const iterator & begin()
Returns iterator pointing to the first image element.
Definition ImageFrame.h:116
const iterator & end()
Returns the iterator pointing to the element after the last element of the image buffer.
Definition ImageFrame.h:122
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition ImageFrame.h:189
T get(size_t i) const
Gets the intensity at location i. See address().
Definition ImageFrame.h:251
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition ImageLike.h:174
const std::type_info & getType() const
Get the storage type.
Definition ImageLike.h:100
Base class for image processing functions.
Definition ImageOp.h:49
void traverseChannelsRepeated(const ImageTray< const Channel > &src, ImageTray< Channel > &dst) const
Recycle channels until all dst channels completed.
Definition ImageOp.cpp:454
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:193
Class for using simple function objects (like std::functor) for sequential pixel iteration.
Definition FunctorOp.h:135
UnaryFunctorOp(bool adaptParams=true, bool adoptLimit=true)
Definition FunctorOp.h:143
void traverseChannel(const Channel &src, Channel &dst) const
Process the image.
Definition FunctorOp.h:227
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:216
void getDstConf(const ImageConf &src, ImageConf &dst) const
Given source image, determine respective dest image configuration.
Definition FunctorOp.h:170
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:100
Definition DataSelector.cpp:1277
Helper class that only ensures that functor is initialized before ImageOp.
Definition FunctorOp.h:55