35#include <drain/image/ImageFile.h>
37#include "drain/TypeName.h"
38#include "drain/Type.h"
39#include "drain/util/Functor.h"
84 this->getParameters().
copyStruct(op.getParameters(), op, *
this);
90 void adaptParameters(
bool adaptLimit =
false){
92 p.
append(this->functor.getParameters());
95 p.link(
"LIMIT", this->LIMIT);
104 bool processOverlappingWithTemp(
const ImageFrame & srcFrame,
Image & dstImage)
const {
117 FunctorOp(
bool adaptParams =
false,
bool adoptLimit =
false) :
122 adaptParameters(adoptLimit);
135template <
class F,
bool NORM=false,
bool SIGN=false>
150 this->parameters.
copyStruct(op.parameters, op, *
this);
155 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
158 mout.debug2(
"invoking processChannelsSeparately()" );
197 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
198 mout.
warn(this->functor.getName() ,
" would need signed type instead of : " , dst.
getEncoding() );
210 dst.setGeometry(src.getGeometry());
220 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
222 this->functor.updateBean();
228template <
class T,
bool NORM,
bool SIGN>
232 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
233 mout.
debug(
"start" );
238 mout.
debug(
"SCALE=" , (
int)SCALE );
239 mout.
debug(
"functor=" , this->functor );
242 if (drain::Type::call<drain::typeIsInteger>(src.
getType())){
243 mout.
warn(
"float dst type, but LIMIT applied" , dst );
244 const double coeff = 0.01 * drain::Type::call<drain::typeMax,double>(src.
getType());
246 for (
int i = 0; i < 100; ++i) {
247 d = ::round(coeff *
static_cast<double>(i));
248 std::cout << __FILE__ <<
':' << __FUNCTION__ <<
':' << d <<
"\t -> ";
250 std::cout << d <<
"\t";
251 d = this->functor(d);
252 std::cout << d <<
"\t";
254 std::cout << d <<
'\n';
263 mout.info(DRAIN_LOG(srcScale));
264 mout.info(DRAIN_LOG(dstScale));
273 while (d != dst.
end()){
274 *d = this->functor(
static_cast<double>(*s));
280 while (d != dst.
end()){
281 *d = dstScale.
inv(this->functor(srcScale.
fwd(
static_cast<double>(*s))));
289 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType())){
290 mout.
warn(
"float dst type, but LIMIT applied" , dst );
296 while (d != dst.
end()){
297 *d = limiter(this->functor(
static_cast<double>(*s)));
303 while (d != dst.
end()){
304 *d = limiter(dstScale.
inv(this->functor(srcScale.
fwd(
static_cast<double>(*s)))));
338 this->parameters.
copyStruct(op.parameters, op, *
this);
348 void traverseChannels(
const ImageTray<const Channel> & src, ImageTray<Channel> & dst)
const {
350 mout.debug2(
"delegating to: processChannelsRepeated(src, dst)" );
357 mout.
debug2(
"delegating unary src to binary, with src2=dst: (src, dst) => (src,dst, dst) " );
377 mout.debug2(
"start: " , *
this );
378 mout.debug3(
"src1: " , src1 );
379 mout.debug3(
"src2: " , src2 );
381 if ((src1.getGeometry() == src2.getGeometry()) && (src1.getGeometry() == dst.getGeometry()) ){
385 traverseSpatially(src1, src2, dst);
393 void traverseSpatially(
const Channel &src1,
const Channel &src2, Channel & dst)
const;
399 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
400 mout.
debug(
"Unary init for Binary" );
402 this->functor.updateBean();
412 this->functor.updateBean();
425 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
426 mout.
warn(
"2nd image empty, problems ahead" , *
this );
427 dst.setGeometry(src.getGeometry());
442 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
443 mout.
debug(
"start, " , this->functor );
450 mout.
debug(
"SCALE::" , (
int)SCALE );
452 mout.
debug(
"s1 scale:" , s1s );
453 mout.
debug(
"s2 scale:" , s2s );
454 mout.
debug(
"d scale:" , ds );
462 mout.
debug(
"LIMIT=False" );
465 while (d != dst.
end()){
466 *d = this->functor(*s1, *s2);
473 while (d != dst.
end()){
474 *d = ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2)));
481 mout.
debug(
"LIMIT=True" );
482 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
483 mout.
warn(
"float dst type, but LIMIT applied" , dst );
487 while (d != dst.
end()){
488 *d = limit(this->functor(*s1, *s2));
494 while (d != dst.
end()){
495 *d = limit(ds.
inv(this->functor(s1s.
fwd(*s1), s2s.
fwd(*s2))));
507 Logger mout(getImgLog(), __FILE__, __FUNCTION__);
508 mout.debug(
"start" );
511 const size_t width1 = src1.getWidth();
512 const size_t height1 = src1.getHeight();
516 const size_t width2 = src2.getWidth();
517 const size_t height2 = src2.getHeight();
520 mout.debug2(handler1 );
521 mout.debug2(handler2 );
523 const size_t width = dst.getWidth();
524 const size_t height = dst.getHeight();
535 mout.debug(
"LIMIT=false" );
537 mout.debug(
"SCALE=false" );
538 for (
size_t i = 0; i < width; ++i) {
539 for (
size_t j = 0; j < height; ++j) {
540 handler1.handle( p1.setLocation(i,j) );
541 handler2.handle( p2.setLocation(i,j) );
542 dst.
put(i,j, this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2)));
547 mout.debug(
"SCALE=true" );
548 for (
size_t i = 0; i < width; ++i) {
549 for (
size_t j = 0; j < height; ++j) {
550 handler1.handle( p1.setLocation(i,j) );
551 handler2.handle( p2.setLocation(i,j) );
552 dst.
put(i,j, dst.getScaling().
inv(this->functor(
553 src1.getScaling().
fwd(src1.
get<
double>(p1)),
554 src2.getScaling().
fwd(src2.
get<
double>(p2))
562 mout.debug(
"LIMIT=true" );
563 if (!drain::Type::call<drain::typeIsInteger>(dst.
getType()))
564 mout.warn(
"float dst type, but LIMIT applied" , dst );
571 mout.debug(
"SCALE=false" );
572 for (
size_t i = 0; i < width; ++i) {
573 for (
size_t j = 0; j < height; ++j) {
574 handler1.handle( p1.setLocation(i,j) );
575 handler2.handle( p2.setLocation(i,j) );
576 dst.
put(i,j, limit(this->functor(src1.
get<
double>(p1), src2.
get<
double>(p2))));
581 mout.debug(
"SCALE=true" );
583 for (
size_t i = 0; i < width; ++i) {
584 for (
size_t j = 0; j < height; ++j) {
585 handler1.handle( p1.setLocation(i,j) );
586 handler2.handle( p2.setLocation(i,j) );
587 dst.
put(i,j, limit(dst.getScaling().
inv(this->functor(
588 src1.getScaling().
fwd(src1.
get<
double>(p1)),
589 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:313
bool isDebug(level_t l=0)
Returns true, if the debug level of the monitor is at least l.
Definition Log.h:359
Logger & warn(const TT &... args)
Possible error, but execution can continue.
Definition Log.h:431
Logger & debug(const TT &... args)
Debug information.
Definition Log.h:667
Logger & debug2(const TT &... args)
Debug information.
Definition Log.h:677
Definition ReferenceMap.h:215
void append(ReferenceMap &rMap, bool replace=true)
Adopts the references of r. If replace==false, only new entries are appended.
Definition ReferenceMap.h:336
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:415
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:326
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition FunctorOp.h:355
virtual void traverseSequentially(const Channel &src1, const Channel &src2, Channel &dst) const
Definition FunctorOp.h:439
BinaryFunctorOp(bool adaptParams=true, bool adoptLimit=true)
Default constructor.
Definition FunctorOp.h:334
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:397
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &src2, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:407
void getDstConf(const ImageConf &src, ImageConf &dst) const
Does not change dst geometry.
Definition FunctorOp.h:419
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:77
FunctorOp(bool adaptParams=false, bool adoptLimit=false)
Definition FunctorOp.h:117
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:137
UnaryFunctorOp(bool adaptParams=true, bool adoptLimit=true)
Definition FunctorOp.h:145
void traverseChannel(const Channel &src, Channel &dst) const
Process the image.
Definition FunctorOp.h:229
virtual void initializeParameters(const ImageFrame &src, const ImageFrame &dst) const
Set applicable internal parameters before calling traverse().
Definition FunctorOp.h:218
void getDstConf(const ImageConf &src, ImageConf &dst) const
Given source image, determine respective dest image configuration.
Definition FunctorOp.h:172
Class for ensuring that variable of type D remains within limits of type S.
Definition TypeUtils.h:98
Definition DataSelector.cpp:1277
Helper class that only ensures that functor is initialized before ImageOp.
Definition FunctorOp.h:57