31 #ifndef MOTIONIllustrator_OP_H_
32 #define MOTIONIllustrator_OP_H_
53 template <
class T=
unsigned char,
class T2=
unsigned char>
60 "Illustrates an image using a motion field in injection.",
61 "m,n,scale,contrast,brightness",p){};
67 process(motion,dst,dst);
75 const int width = src.getWidth();
76 const int height = src.getHeight();
78 const int m = this->getParameter(
"m",20);
79 const int n = this->getParameter(
"n",20);
81 const float scale = this->getParameter(
"scale",1.0f);
84 const float contrast = this->getParameter(
"contrast",1.0f);
85 const float brightness = this->getParameter(
"brightness",0.0f);
87 op.setGrayPalette(3,0,brightness,contrast);
90 const ImageT<T> &u = motion.getChannel(0);
91 const ImageT<T> &v = motion.getChannel(1);
92 const ImageT<T> &w = motion.getChannel(motion.getChannelCount()-1);
94 const bool weighted = (motion.getChannelCount()>2);
96 CoordinateHandler c(width,height);
100 const int iOffset = width/m/2;
101 const int jOffset = height/n/2;
106 for (
int j = 0; j < n; ++j) {
107 for (
int i = 0; i < m; ++i) {
110 i2 = (width*i)/m + iOffset;
111 j2 = (height*j)/n + jOffset;
114 dst.at(i2+1,j2+0) = 128;
115 dst.at(i2+0,j2+1) = 128;
116 dst.at(i2-1,j2+0) = 128;
117 dst.at(i2+0,j2-1) = 128;
122 magn =
static_cast<int>(scale * sqrt(u2*u2 + v2*v2));
123 for (
int k=0; k<magn; k++){
124 p.setLocation(i2 + (u2*k)/magn,j2 + (v2*k)/magn);
128 if (c.handle(p) == CoordinateHandler::UNCHANGED){
129 w2 = weighted ? 255-(255*16)/(16+w.at(a)) : 128;
130 dst.at(p.x,p.y,0) =
static_cast<T2
>(127+w2/2);
131 dst.at(p.x,p.y,1) =
static_cast<T2
>(w2);
132 dst.at(p.x,p.y,2) =
static_cast<T2
>(127+w2/2);
size_t address(size_t i) const
Computes the index location from image coordinates. Does not involve bit resolution.
Definition: ImageFrame.h:148
Base class for image processing functions.
Definition: ImageOp.h:49
virtual void process(const ImageFrame &src, Image &dst) const
Main interface. Typically splits processing to each channel.
Definition: ImageOp.cpp:126
A template class for images with static storage type.
Definition: ImageT.h:67
Definition: MotionIllustratorOp.h:55
Colorizes an image of 1 channel to an image of N channels by using a palette image as a lookup table.
Definition: PaletteOp.h:55
Definition: DataSelector.cpp:1277