27 #ifndef improc_imageUtils_hpp
28 #define improc_imageUtils_hpp
45 template<
typename realT>
66 template<
class imageT,
typename valueT>
71 for(
int c=0;
c< im.cols(); ++
c)
73 for(
int r=0; r< im.rows(); ++r)
75 if( !std::isnormal( im(r,
c) ) )
84 template<
class imageT>
87 typename imageT::Scalar zero = 0;
88 zeroNaNs<imageT, typename imageT::Scalar> (im, zero);
95 for(
int p=0; p< imc.planes(); ++p)
97 for(
int c=0;
c< imc.cols(); ++
c)
99 for(
int r=0; r< imc.rows(); ++r)
101 if( !std::isnormal( imc.image(p)(r,
c) ) )
103 imc.image(p)(r,
c) = 0;
115 template<
class imageT>
118 typename imageT::Scalar m = 0;
120 for(
int c=0;
c<im.cols();++
c)
122 for(
int r=0;r<im.rows();++r)
128 m/=(im.rows()*im.cols());
138 template<
class imageT>
140 typename imageT::Scalar mean
143 typename imageT::Scalar v = 0;
145 for(
int c=0;
c<im.cols();++
c)
147 for(
int r=0;r<im.rows();++r)
149 v += pow(im(r,
c)-mean,2);
153 v /= (im.rows()*im.cols());
162 template<
typename imageT>
164 typename imageT::Scalar & y,
171 typename imageT::Scalar sum = im.sum();
175 x = 0.5*(im.rows()-1.0);
176 y = 0.5*(im.cols()-1.0);
180 for(
int j=0; j < im.cols(); ++j)
182 for(
int i=0; i< im.rows(); ++i)
201 template<
typename floatT,
typename imageT,
typename magImageT,
typename transformT>
211 floatT magSize_x = ceil( (im.rows() - 1.0)/ scale_x) + 1;
212 floatT magSize_y = ceil( (im.cols() - 1.0)/ scale_y) + 1;
214 floatT mag_x = ((floatT) magSize_x-1.0)/((floatT) im.rows() - 1.0);
215 floatT mag_y = ((floatT) magSize_y-1.0)/((floatT) im.cols() - 1.0);
220 magIm.resize(magSize_x, magSize_y);
225 magIm.maxCoeff(&ix,&iy);
238 template<
typename floatT,
typename imageT,
typename magImageT>
266 template<
typename imageT,
typename imageT1,
typename imageT2,
typename imageT3,
typename imageT4>
269 const imageT2 & mask1,
271 const imageT4 & mask2
274 combo.resize(im1.rows(), im2.cols());
276 for(
int c=0;
c < combo.cols(); ++
c)
278 for(
int r=0;r<combo.rows();++r)
280 if(mask1(r,
c) == 1 && mask2(r,
c) == 0) combo(r,
c) = im1(r,
c);
281 else if(mask2(r,
c) == 1 & mask1(r,
c) == 0) combo(r,
c) = im2(r,
c);
282 else if(mask1(r,
c) == 1 && mask2(r,
c) == 1) combo(r,
c) = 0.5*(im1(r,
c) + im2(r,
c));
288 template<
typename eigenT,
typename eigenTin>
289 void removeRowsAndCols(eigenT & out,
const eigenTin & in,
int st,
int w)
292 out.resize(in.rows() - w, in.cols() - w);
294 out.topLeftCorner(st,st) = in.topLeftCorner(st,st);
296 out.bottomLeftCorner(in.rows()-(st+w), st) = in.bottomLeftCorner(in.rows()-(st+w), st);
298 out.topRightCorner(st, in.cols()-(st+w)) = in.topRightCorner(st, in.cols()-(st+w));
300 out.bottomRightCorner(in.rows()-(st+w),in.cols()-(st+w)) = in.bottomRightCorner(in.rows()-(st+w),in.cols()-(st+w));
304 template<
typename eigenT,
typename eigenTin>
305 void removeRows(eigenT & out,
const eigenTin & in,
int st,
int w)
308 out.resize(in.rows() - w, in.cols());
310 out.topLeftCorner(st,in.cols()) = in.topLeftCorner(st,in.cols());
312 out.bottomLeftCorner(in.rows()-(st+w), in.cols()) = in.bottomLeftCorner(in.rows()-(st+w), in.cols());
316 template<
typename eigenT,
typename eigenTin>
317 void removeCols(eigenT & out,
const eigenTin & in,
int st,
int w)
320 out.resize(in.rows(), in.cols() - w);
322 out.topLeftCorner(in.rows(), st) = in.topLeftCorner(in.rows(), st);
324 out.topRightCorner(in.rows(),in.cols()-(st+w)) = in.topRightCorner(in.rows(),in.cols()-(st+w));
333 void *
imcpy(
void * dest,
constexpr units::realT c()
The speed of light.
int imageMaxInterp(floatT &x, floatT &y, floatT &scale_x, floatT &scale_y, magImageT &magIm, const imageT &im)
Find the maximum in an image at sub-pixel resolution by cubic convolution interpolation.
void * imcpy(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, with no transformation.
void zeroNaNs(imageT &im)
Zero any NaNs in an image.
imageT::Scalar imageMean(imageT &im)
Calculate the mean value of an image.
int imageCenterOfLight(typename imageT::Scalar &x, typename imageT::Scalar &y, const imageT &im)
Calculate the center of light of an image.
void combine2ImagesMasked(imageT &combo, const imageT1 &im1, const imageT2 &mask1, const imageT3 &im2, const imageT4 &mask2)
Combine two images, each with their own mask defining good pixels.
void zeroNaNCube(cubeT &imc)
Zero any NaNs in an image cube.
void * imcpy_flipLR(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping left-right.
void * imcpy_flipUDLR(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping up-down and left-right.
void * imcpy_flipUD(void *dest, void *src, size_t width, size_t height, size_t szof)
Copy one image to another, flipping up-down.
imageT::Scalar imageVariance(imageT &im, typename imageT::Scalar mean)
Calculate the variance of an image w.r.t. a given value.
int reflectImageCoords(int &x1, int &y1, int x0, int y0, realT xc, realT yc)
Reflect pixel coordinates across the given center pixel.