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);
133 template <
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() );
206 dst.setGeometry(src.getGeometry());
216 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
218 this->functor.updateBean();
224 template <
class T,
bool NORM,
bool SIGN>
228 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
229 mout.
debug(
"start" );
234 mout.
debug(
"SCALE=" , (
int)SCALE );
235 mout.
debug(
"functor=" , this->functor );
238 for (
int i = 0; i < 256; i+=8) {
239 std::cout << __FILE__ <<
':' << __FUNCTION__ <<
':' << i <<
"\t -> " << ss.
fwd(i) <<
"\t" << this->functor(ss.
fwd(i)) <<
'\n';
244 mout.
debug2(
"ss scale:" , ss );
245 mout.
debug2(
"ds scale:" , ds );
254 while (d != dst.
end()){
255 *d = this->functor(
static_cast<double>(*s));
261 while (d != dst.
end()){
262 *d = ds.
inv(this->functor(ss.
fwd(
static_cast<double>(*s))));
270 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
271 mout.
warn(
"float dst type, but LIMIT applied" , dst );
276 while (d != dst.
end()){
277 *d = limiter(this->functor(
static_cast<double>(*s)));
283 while (d != dst.
end()){
284 *d = limiter(ds.
inv(this->functor(ss.
fwd(
static_cast<double>(*s)))));
318 this->parameters.
copyStruct(op.parameters, op, *
this);
328 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
330 mout.debug2(
"delegating to: processChannelsRepeated(src, dst)" );
337 mout.
debug2(
"delegating unary src to binary, with src2=dst: (src, dst) => (src,dst, dst) " );
357 mout.debug2(
"start: " , *
this );
358 mout.debug3(
"src1: " , src1 );
359 mout.debug3(
"src2: " , src2 );
361 if ((src1.getGeometry() == src2.getGeometry()) && (src1.getGeometry() == dst.getGeometry()) ){
365 traverseSpatially(src1, src2, dst);
373 void traverseSpatially(
const Channel &src1,
const Channel &src2, Channel & dst)
const;
379 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
380 mout.
debug(
"Unary init for Binary" );
382 this->functor.updateBean();
392 this->functor.updateBean();
405 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
406 mout.
warn(
"2nd image empty, problems ahead" , *
this );
407 dst.setGeometry(src.getGeometry());
422 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
423 mout.
debug(
"start, " , this->functor );
430 mout.
debug(
"SCALE::" , (
int)SCALE );
432 mout.
debug(
"s1 scale:" , s1s );
433 mout.
debug(
"s2 scale:" , s2s );
434 mout.
debug(
"d scale:" , ds );
442 mout.
debug(
"LIMIT=False" );
445 while (d != dst.
end()){
446 *d = this->functor(*s1, *s2);
453 while (d != dst.
end()){
454 *d = ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2)));
461 mout.
debug(
"LIMIT=True" );
462 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
463 mout.
warn(
"float dst type, but LIMIT applied" , dst );
467 while (d != dst.
end()){
468 *d = limit(this->functor(*s1, *s2));
474 while (d != dst.
end()){
475 *d = limit(ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2))));
487 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
488 mout.debug(
"start" );
491 const size_t width1 = src1.getWidth();
492 const size_t height1 = src1.getHeight();
496 const size_t width2 = src2.getWidth();
497 const size_t height2 = src2.getHeight();
500 mout.debug2(handler1 );
501 mout.debug2(handler2 );
503 const size_t width = dst.getWidth();
504 const size_t height = dst.getHeight();
515 mout.debug(
"LIMIT=false" );
517 mout.debug(
"SCALE=false" );
518 for (
size_t i = 0; i < width; ++i) {
519 for (
size_t j = 0; j < height; ++j) {
520 handler1.handle( p1.setLocation(i,j) );
521 handler2.handle( p2.setLocation(i,j) );
522 dst.
put(i,j, this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2)));
527 mout.debug(
"SCALE=true" );
528 for (
size_t i = 0; i < width; ++i) {
529 for (
size_t j = 0; j < height; ++j) {
530 handler1.handle( p1.setLocation(i,j) );
531 handler2.handle( p2.setLocation(i,j) );
532 dst.
put(i,j, dst.getScaling().
inv(this->functor(
533 src1.getScaling().
fwd(src1.
get<
double>(p1)),
534 src2.getScaling().
fwd(src2.
get<
double>(p2))
542 mout.debug(
"LIMIT=true" );
543 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
544 mout.warn(
"float dst type, but LIMIT applied" , dst );
551 mout.debug(
"SCALE=false" );
552 for (
size_t i = 0; i < width; ++i) {
553 for (
size_t j = 0; j < height; ++j) {
554 handler1.handle( p1.setLocation(i,j) );
555 handler2.handle( p2.setLocation(i,j) );
556 dst.
put(i,j, limit(this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2))));
561 mout.debug(
"SCALE=true" );
563 for (
size_t i = 0; i < width; ++i) {
564 for (
size_t j = 0; j < height; ++j) {
565 handler1.handle( p1.setLocation(i,j) );
566 handler2.handle( p2.setLocation(i,j) );
567 dst.
put(i,j, limit(dst.getScaling().
inv(this->functor(
568 src1.getScaling().
fwd(src1.
get<
double>(p1)),
569 src2.getScaling().
fwd(src2.
get<
double>(p2))
virtual const std::string & getName() const
Return the name of an instance.
Definition: BeanLike.h:69
virtual const std::string & getDescription() const
Return a brief description.
Definition: BeanLike.h:74
Definition: CastableIterator.h:57
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition: Log.h:308
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition: Log.h:354
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
Logger & debug2(const TT &... args)
Debug information.
Definition: Log.h:686
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:320
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
Linear scaling and physical range for image intensities.
Definition: ValueScaling.h:64
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 const ValueScaling & getScaling() const
Get linear scaling.
Definition: ValueScaling.h:147
const Range< double > & getPhysicalRange() const
Returns a typical or supported range for physical values.
Definition: ValueScaling.h:221
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
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:306
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition: FunctorOp.h:335
virtual void traverseSequentially(const Channel &src1, const Channel &src2, Channel &dst) const
Definition: FunctorOp.h:419
BinaryFunctorOp(bool adaptParams=true, bool adoptLimit=true)
Default constructor.
Definition: FunctorOp.h:314
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition: FunctorOp.h:377
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &src2, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition: FunctorOp.h:387
void getDstConf(const ImageConf &src, ImageConf &dst) const
Does not change dst geometry.
Definition: FunctorOp.h:399
Image with static geometry.
Definition: ImageChannel.h:60
Definition: CoordinateHandler.h:62
const Encoding & getEncoding() const
Return type and scaling.
Definition: ImageConf.h:68
bool typeIsSet() const
Get the storage type.
Definition: ImageConf.h:116
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:67
const iterator & begin()
Returns iterator pointing to the first image element.
Definition: ImageFrame.h:119
void put(size_t i, T x)
Sets the intensity in location i to x. See \address.
Definition: ImageFrame.h:192
const iterator & end()
Returns the iterator pointing to the element after the last element of the image buffer.
Definition: ImageFrame.h:125
T get(size_t i) const
Gets the intensity at location i. See address().
Definition: ImageFrame.h:254
const std::type_info & getType() const
Get the storage type.
Definition: ImageLike.h:100
const CoordinatePolicy & getCoordinatePolicy() const
Coord policy.
Definition: ImageLike.h:167
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
ImageOp(const std::string &name=__FUNCTION__, const std::string &description="")
Definition: ImageOp.h:156
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
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:225
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition: FunctorOp.h:214
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:653
Definition: DataSelector.cpp:1277
Helper class that only ensures that functor is initialized before ImageOp.
Definition: FunctorOp.h:55