2 #ifndef vil_transform_h_ 3 #define vil_transform_h_ 11 # include <vcl_msvc_warnings.h> 18 template <
class T,
class F >
21 const unsigned ni = image.
ni(), nj= image.
nj(), np = image.
nplanes();
29 for (
unsigned p=0;p<np;++p,plane += pstep)
32 for (
unsigned j=0;j<nj;++j,row += jstep)
34 T *pixel = row, *end_row = row+ni;
35 for (;pixel!=end_row;++pixel) *pixel = functor(*pixel);
43 for (
unsigned p=0;p<np;++p,plane += pstep)
46 for (
unsigned i=0;i<ni;++i,col += istep)
48 T *pixel = col, *end_col=col+nj;
49 for (;pixel!=end_col;++pixel) *pixel = functor(*pixel);
56 for (
unsigned p=0;p<np;++p,plane += pstep)
59 for (
unsigned j=0;j<nj;++j,row += jstep)
62 for (
unsigned i=0;i<ni;++i,pixel+=istep)
63 *pixel = functor(*pixel);
73 template <
class inP,
class outP,
class Op >
76 const unsigned ni = src.
ni(), nj= src.
nj(), np = src.
nplanes();
83 for (
unsigned p = 0; p < np; ++p)
84 for (
unsigned j = 0; j < nj; ++j)
86 const inP* src_row = &src(0,j,p);
87 outP* dest_row = &dest(0,j,p);
88 for (
unsigned i = 0; i < ni; ++i)
89 dest_row[i] = functor(src_row[i]);
94 for (
unsigned p = 0; p < np; ++p)
95 for (
unsigned j = 0; j < nj; ++j)
96 for (
unsigned i = 0; i < ni; ++i)
97 dest(i,j,p) = functor(src(i,j,p));
103 template <
class inP,
class outP,
class Op >
106 const unsigned ni = src.
ni(), nj= src.
nj(), np = src.
nplanes();
113 for (
unsigned p = 0; p < np; ++p)
114 for (
unsigned j = 0; j < nj; ++j)
116 const inP* src_row = &src(0,j,p);
117 outP* dest_row = &dest(0,j,p);
118 for (
unsigned i = 0; i < ni; ++i)
119 functor(src_row[i],dest_row[i]);
124 for (
unsigned p = 0; p < np; ++p)
125 for (
unsigned j = 0; j < nj; ++j)
126 for (
unsigned i = 0; i < ni; ++i)
127 functor(src(i,j,p), dest(i,j,p));
133 template <
class inA,
class inB,
class outP,
class BinOp >
141 for (
unsigned p = 0; p < srcA.
nplanes(); ++p)
142 for (
unsigned j = 0; j < srcA.
nj(); ++j)
143 for (
unsigned i = 0; i < srcA.
ni(); ++i)
144 dest(i,j,p) = functor(srcA(i,j,p),srcB(i,j,p));
150 template <
class inA,
class inB,
class outP,
class BinOp >
159 for (
unsigned p = 0; p < srcA.
nplanes(); ++p)
160 for (
unsigned j = 0; j < srcA.
nj(); ++j)
161 for (
unsigned i = 0; i < srcA.
ni(); ++i)
162 nc_dest(i,j,p) = functor(srcA(i,j,p),srcB(i,j,p));
166 #endif // vil_transform_h_ void vil_transform(vil_image_view< T > &image, F functor)
Apply a unary operation to each pixel in image.
Concrete view of image data of type T held in memory.
void set_size(unsigned ni, unsigned nj) override
resize current planes to ni x nj.
void vil_transform2(const vil_image_view< inP > &src, vil_image_view< outP > &dest, Op functor)
Apply a binary function to each pixel in src and dest that modifies dest.
std::ptrdiff_t jstep() const
Add this to your pixel pointer to get next j pixel.
unsigned ni() const
Width.
unsigned nj() const
Height.
std::ptrdiff_t planestep() const
Add this to your pixel pointer to get pixel on next plane.
A base class reference-counting view of some image data.
T * top_left_ptr()
Pointer to the first (top left in plane 0) pixel.
unsigned nplanes() const
Number of planes.
std::ptrdiff_t istep() const
Add this to your pixel pointer to get next i pixel.