31#ifndef PixelVectorOP_H_ 
   32#define PixelVectorOP_H_ 
   40#include "drain/util/FunctorBank.h" 
   42#include "drain/util/FunctorPack.h" 
   69    std::string functorDef;
 
   74    PixelVectorOp(
const std::string & name, 
const std::string & description) :
 
   75        ImageOp(name, description + 
" Post-scaling with desired functor."), rescale(0.0), POW(1.0), INVPOW(1.0) { 
 
   77        parameters.link(
"functor", this->functorDef);
 
 
   94    std::string coefficients;
 
  101        parameters.link(
"coeff", coefficients=
"1.0", 
"c[:c2:c3:...]");
 
  102        parameters.link(
"normalize", normalize=
true, 
"true|false");
 
  115        mout.
warn(
"already a single-channel image?");
 
 
 
  137        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  138        mout.
debug(
"delegating: process(src, dst, dst)" );
 
 
  148        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  150        mout.debug(
"imitating: " );
 
  157            traverseFrame(src1, tmp, dst);
 
  172            traverseFrame(src1, src2, dst); 
 
  177    void traverseChannels(
const ImageTray<const Channel> & srcTray, ImageTray<Channel> & dstTray)
 const {
 
  178        Logger mout(getImgLog(), __FILE__, __FUNCTION__);
 
  179        mout.unimplemented(
"traverseChannels for one srcTray only " );
 
  183    void traverseChannels(
const ImageTray<const Channel> & src, 
const ImageTray<const Channel> & src2,
 
  184            ImageTray<Channel> & dst) 
const;
 
  186    void traverseFrame(
const ImageFrame &src1, 
const ImageFrame &src2, ImageFrame &dst)
 const {
 
  188        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  189        mout.debug(
"delegate to: traverseChannels(src, dst, dst)" );
 
  191        ImageTray<const Channel> src1Channels;
 
  192        src1Channels.setChannels(src1);
 
  194        ImageTray<const Channel> src2Channels;
 
  195        src2Channels.setChannels(src2);
 
  197        ImageTray<Channel> dstChannels;
 
  198        dstChannels.setChannels(dst);
 
  200        traverseChannels(src1Channels, src2Channels, dstChannels);
 
 
  217void BinaryPixelVectorOp<F>::traverseChannels(
const ImageTray<const Channel> & src1, 
const ImageTray<const Channel> & src2,
 
  218        ImageTray<Channel> & dst)
 const {
 
  221    Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  224        mout.error(
"src1 empty" );
 
  227        mout.error(
"src2 empty" );
 
  230        mout.error(
"dst empty" );
 
  232    Channel & dstChannel = dst.get();
 
  234    if (src1.getGeometry() != src2.getGeometry()){
 
  235        mout.warn(
"src1" , src1.getGeometry() );
 
  236        mout.warn(
"src2" , src2.getGeometry() );
 
  237        mout.note(
"dstChannel" , dstChannel );
 
  238        mout.error(
"src1 and src2 geometry error" );
 
  242    const int width  = src1.getGeometry().getWidth(); 
 
  243    const int height = src1.getGeometry().getHeight(); 
 
  244    const size_t channels = src1.size(); 
 
  246    double x=0.0, sum=0.0;
 
  255    std::string functorName;
 
  256    std::string functorParams;
 
  261    if (!functorBank.has(functorName)){
 
  263        mout.note(functorBank );
 
  264        mout.error(
"functor '" , functorName , 
"' not found: " , functorDef );
 
  268    UnaryFunctor & scalingFunctor = functorBank.clone(functorName); 
 
  272    const std::type_info & t = dstChannel.getType();
 
  273    if (Type::call<drain::typeIsSmallInt>(t)){
 
  274        const double m = Type::call<typeMax, double>(t);
 
  275        scalingFunctor.setScale(m, 0.0); 
 
  276        mout.info(
"small int type, scaling with its maximum (" , m , 
')' );
 
  281        scalingFunctor.setParameters(functorParams, 
'=', 
'/');
 
  282    } 
catch (
const std::exception & e) {
 
  283        mout.info(scalingFunctor);
 
  284        mout.warn(scalingFunctor.getParameters());
 
  285        mout.error(e.what());
 
  288    mout.debug2(scalingFunctor.getName() , 
':' , scalingFunctor );
 
  290    const double coeff = (rescale>0.0) ? 1.0/rescale : 1.0/static_cast<double>(channels);
 
  291    const bool USE_POW    = (POW != 1.0);
 
  292    const bool USE_INVPOW = (INVPOW != 1.0);
 
  293    mout.debug3(
"coeff " , coeff );
 
  294    const BinaryFunctor & f = binaryFunctor;
 
  296    for (
int j = 0; j < height; j++) {
 
  297        for (
int i = 0; i < width; i++) {
 
  300            a = dstChannel.address(i,j);
 
  301            for (
size_t k = 0; k < channels; k++){
 
  303                x = f(src1.get(k).get<
double>(a) , src2.get(k).get<
double>(a)) ;
 
  310                dstChannel.put(a, scalingFunctor(pow(coeff*sum, INVPOW)));
 
  312                dstChannel.put(a, scalingFunctor(coeff*sum));
 
  403        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  404        mout.
debug(
"delegating to: process(src, src, dst)" );
 
 
  411        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  412        mout.warn(
"delegating to: traverseFrame(src, src, dst)" );
 
  419        Logger mout(getImgLog(), __FILE__, __FUNCTION__); 
 
  420        mout.debug(
"delegate to: traverseChannels(src, SRC, dst)" );
 
 
LogSourc e is the means for a function or any program segment to "connect" to a Log.
Definition Log.h:312
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
virtual void clear()
Removes all the elements of the map.
Definition ReferenceMap.h:382
Definition PixelVectorOp.h:127
virtual void process(const ImageFrame &src, Image &dst) const
Main interface. Typically splits processing to each channel.
Definition PixelVectorOp.h:136
Image with static geometry.
Definition ImageChannel.h:60
Computes the distance between intensity vectors.
Definition PixelVectorOp.h:334
Definition PixelVectorOp.h:90
virtual void traverseChannel(const Channel &src, Channel &dst) const
Apply to single channel.
Definition PixelVectorOp.h:113
Struct for image (excluding data)
Definition ImageConf.h:333
Image with static geometry.
Definition ImageFrame.h:64
void copyData(const ImageFrame &src)
Copies data. Does not change encoding, geometry, or coordinate policy.
Definition ImageFrame.cpp:236
bool hasOverlap(const ImageFrame &image) const
Checks if images have a common memory segment.
Definition ImageFrame.h:338
Base class for image processing functions.
Definition ImageOp.h:49
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:193
void copyDeep(const ImageFrame &src)
Copies the type, geometry, coordinate policy and data of the given image.
Definition Image.h:323
Computes pixel magnitude, that is, euclidean norm of the intensity vector.
Definition PixelVectorOp.h:389
virtual void process(const ImageFrame &src, Image &dst) const
Main interface. Typically splits processing to each channel.
Definition PixelVectorOp.h:402
A base class for operations between of multi-channel pixels (intensity vectors) of two images.
Definition PixelVectorOp.h:62
virtual void getDstConf(const ImageConf &srcConf, ImageConf &dstConf) const
Given source image, determine respective dest image configuration.
Definition PixelVectorOp.cpp:40
Computes dot product of intensities of two images.
Definition PixelVectorOp.h:364
Definition DataSelector.cpp:1277
BankSuper< UnaryFunctor > FunctorBank
Prepared set of fuzzy functors.
Definition FunctorBank.h:45
FunctorBank & getFunctorBank()
Definition FunctorBank.cpp:51