27 #ifndef improc_aperturePhotometer_hpp
28 #define improc_aperturePhotometer_hpp
31 #include <mx/improc/eigenImage.hpp>
32 #include <mx/improc/imageMasks.hpp>
55 template<
typename realT>
71 bool m_useNanMask {
false};
78 std::vector<realT> m_bgx;
79 std::vector<realT> m_bgy;
118 eigenImage<realT> & im,
130 std::vector<realT> & deltaPhot,
131 eigenImage<realT> & im,
145 std::vector<realT> * deltaPhot,
146 eigenImage<realT> & im,
158 void bgMin( realT bgm )
163 void bgMax( realT bgx )
168 void bg( realT bgm, realT bgx )
176 template<
typename realT>
184 if( sizeX == m_sizeX && sizeY == m_sizeY && xcen == m_xcen && ycen == m_ycen)
return 0;
192 m_indexIm.resize(m_sizeX, m_sizeY);
196 radIm.resize(m_sizeX, m_sizeY);
199 std::map<realT, size_t> unrads;
202 for(
int i=0;i<radIm.cols();++i)
204 for(
int j=0;j<radIm.rows();++j)
207 unrads.insert(std::pair<realT, size_t>( radIm(j,i), 0));
212 m_radius.resize(unrads.size());
213 typename std::map<realT, size_t>::iterator it;
215 for(it = unrads.begin(); it!=unrads.end(); ++it)
217 m_radius[n] = it->first;
222 for(
int i=0;i<radIm.cols();++i)
224 for(
int j=0;j<radIm.rows();++j)
226 it = unrads.find(radIm(j,i));
227 m_indexIm(j,i) = it->second;
231 if(m_bgMax > m_bgMin && m_bgMin > 0)
236 for(
int cc=0; cc<radIm.cols(); ++cc)
238 for(
int rr=0; rr< radIm.rows(); ++rr)
240 if(radIm(rr,cc) >= m_bgMin && radIm(rr,cc) <= m_bgMax)
252 template<
typename realT>
257 realT xcen = 0.5*(1.0*sizeX - 1.0);
258 realT ycen = 0.5*(1.0*sizeY - 1.0);
260 return resize(sizeX, sizeY, xcen, ycen);
264 template<
typename realT>
270 return cumPhotWork(cumPhot,
nullptr, im, maxr);
273 template<
typename realT>
275 std::vector<realT> & deltaPhot,
280 return cumPhotWork(cumPhot, &deltaPhot, im, maxr);
283 template<
typename realT>
285 std::vector<realT> * deltaPhot,
290 realT xcen = 0.5*(m_indexIm.rows()-1);
291 realT ycen = 0.5*(m_indexIm.cols()-1);
293 if(maxr <= 0) maxr = m_radius.back();
295 cumPhot.resize(m_radius.size(),0);
300 int x1 = xcen + maxr;
301 if(x1 > m_indexIm.rows()-1) x1 = m_indexIm.rows()-1;
305 int y1 = ycen + maxr;
306 if(y1 > m_indexIm.cols()-1) y1 = m_indexIm.rows()-1;
312 std::vector<realT> bgann(m_bgx.size());
313 for(
size_t n=0; n < m_bgx.size(); ++n)
315 bgann[n] = im(m_bgx[n], m_bgy[n]);
319 std::cerr <<
"background: " << bg <<
"\n";
325 if(maxr == m_radius.back())
327 for(
int i= y0; i<= y1; ++i)
329 for(
int j=x0; j<=x1; ++j)
331 cumPhot[ m_indexIm(j,i) ] += im(j,i) - bg;
337 for(
int i= y0; i<= y1; ++i)
339 for(
int j=x0; j<=x1; ++j)
341 if(m_radius[m_indexIm(j,i)] <= maxr) cumPhot[ m_indexIm(j,i) ] += im(j,i);
347 if(deltaPhot !=
nullptr)
349 deltaPhot->assign(cumPhot.begin(), cumPhot.end());
353 for(
int i=1; i<cumPhot.size(); ++i)
355 cumPhot[i] += cumPhot[i-1];
Class for performing aperture photometry on images.
eigenImage< size_t > m_indexIm
Maps a pixel in the image to the position in the radius vector.
realT radius(size_t i)
Get the radius value at an index of the vector.
int resize(int sizeX, int sizeY, realT xcen, realT ycen)
Resize the photometer, recalculating the radius vector and index image.
int cumPhot(std::vector< realT > &cumPhot, eigenImage< realT > &im, realT maxr=0)
Get the cumulative photometry of an image as a function of radius.
std::vector< realT > m_radius
Holds the ordered unique radii of the pixels in the image.
realT m_ycen
The y coordinate of the center of the image. Radii are caculated relative to this point....
int cumPhotWork(std::vector< realT > &cumPhot, std::vector< realT > *deltaPhot, eigenImage< realT > &im, realT maxr=0)
Get the cumulative photometry of an image as a function of radius.
int m_sizeY
The size of the image in Y (columns).
int m_sizeX
The size of the image in X (rows).
realT m_xcen
The x coordinate of the center of the image. Radii are caculated relative to this point....
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
void radiusImage(eigenT &m, typename eigenT::Scalar xc, typename eigenT::Scalar yc, typename eigenT::Scalar scale=1)
Fills in the cells of an Eigen 2D Array with their radius from the center.
vectorT::value_type vectorMedian(const vectorT &vec, vectorT *work=0)
Calculate median of a vector, leaving the vector unaltered.