7 #ifndef pupilFitter_hpp
8 #define pupilFitter_hpp
10 #include <mx/improc/eigenImage.hpp>
11 #include <mx/improc/imageUtils.hpp>
12 #include <mx/improc/circleOuterpix.hpp>
13 #include <mx/improc/imageTransforms.hpp>
21 template<
typename realT>
24 mx::improc::eigenImage<realT>
m_quad;
26 mx::improc::eigenImage<realT>
m_circ;
58 int threshold( mx::improc::eigenImage<realT> & im );
60 int getQuad( mx::improc::eigenImage<realT> & quad,
61 mx::improc::eigenImage<realT> & im,
65 int putQuad( mx::improc::eigenImage<realT> & im,
66 mx::improc::eigenImage<realT> & quad,
76 int fit( mx::improc::eigenImage<realT> & im,
77 mx::improc::eigenImage<realT> & edged
84 template<
typename realT>
92 m_quad.resize(m_rows,m_cols);
93 m_circ.resize(m_rows,m_cols);
96 m_quadMag.resize(m_quad.rows()*10, m_quad.cols()*10);
97 m_circMag.resize(m_circ.rows()*10, m_circ.cols()*10);
99 m_pixs.resize(m_quadMag.rows()*m_quadMag.cols());
104 template<
typename realT>
130 if(quadNo == 1) i0 = m_rows;
131 if(quadNo == 2) j0 = m_cols;
143 template<
typename realT>
146 for(
int i =0; i< im.rows(); ++i)
148 for(
int j=0; j< im.cols(); ++j)
150 if(im(i,j) >= m_thresh) im(i,j) = 1;
158 template<
typename realT>
160 mx::improc::eigenImage<realT> & im,
165 if(im.rows() != 2*m_rows || im.cols() != 2*m_cols)
171 quadCoords(i0, j0, quadNo);
173 for(
size_t i =i0; i< i0+m_rows; ++i)
175 for(
size_t j=j0; j<j0+m_cols;++j)
177 quad(i-i0, j-j0) = im(i,j);
184 template<
typename realT>
186 mx::improc::eigenImage<realT> & quad,
190 if(im.rows() != 2*m_rows || im.cols() != 2*m_cols)
196 quadCoords(i0, j0, quadNo);
198 for(
size_t i =i0; i< i0+m_rows; ++i)
200 for(
size_t j=j0; j<j0+m_cols;++j)
202 im(i,j) = quad(i-i0, j-j0);;
209 template<
typename realT>
219 mx::improc::circleOuterpix(x0, y0, avgr0, avgx, avgy, avgr, m_circMag, m_quadMag);
226 quadCoords(i0, j0, quadNo);
237 template<
typename realT>
239 mx::improc::eigenImage<realT> & edged
242 mx::improc::eigenImage<realT> imin = im;
244 for(
int i=0; i< m_numPupils; ++i)
247 getQuad(m_quad, imin, i);
249 mx::improc::imageMagnify(m_quadMag, m_quad, mx::improc::bilinearTransform<realT>());
253 for(
size_t j=0; j < m_pixs.size(); ++j)
255 m_pixs[j] = m_quadMag.data()[j];
258 std::sort(m_pixs.begin(), m_pixs.end());
260 m_bg[i] = m_pixs[m_bgMedIndex*m_pixs.size()];
262 m_med[i] = m_pixs[m_pupMedIndex*m_pixs.size()];
264 m_quadMag = (m_quadMag - m_bg[i]) / (m_med[i] - m_bg[i]);
267 threshold(m_quadMag);
270 outerpix(m_avgx[i], m_avgy[i], m_avgr[i], i);
273 mx::improc::imageRebinSum( m_quad, m_quadMag,
true);
274 mx::improc::imageRebinSum( m_circ, m_circMag);
275 putQuad(im, m_quad, i);
276 putQuad(edged, m_circ, i);
Struct to perform centration and measure diameter of Pyramid pupils.
int m_numPupils
the number of pupils. Default is 4, 3 is also supported.
unsigned m_rows
[in] the size of a quad, in rows
std::vector< realT > m_pixs
int putQuad(mx::improc::eigenImage< realT > &im, mx::improc::eigenImage< realT > &quad, int quadNo)
int outerpix(float &avgx, float &avgy, float &avgr, int quadNo)
unsigned m_cols
[in] the size of a quad, in cols
int getQuad(mx::improc::eigenImage< realT > &quad, mx::improc::eigenImage< realT > &im, int quadNo)
mx::improc::eigenImage< realT > m_circMag
int setSize(unsigned rows, unsigned cols)
mx::improc::eigenImage< realT > m_quadMag
int quadCoords(size_t &i0, size_t &j0, int quadNo)
Returns the quadrant starting coordinates.
int threshold(mx::improc::eigenImage< realT > &im)
mx::improc::eigenImage< realT > m_circ
mx::improc::eigenImage< realT > m_quad
float m_pupMedIndex
the index of the illuminated pupil median in a sorted array.
int fit(mx::improc::eigenImage< realT > &im, mx::improc::eigenImage< realT > &edged)