32#include "../improc/eigenImage.hpp"
33#include "../improc/eigenCube.hpp"
50template <
typename realT>
55 for(
int i = 0; i < modes.planes(); ++i )
57 modes.image( i ) *= mask;
73template <
typename realT>
80 realT maskSum = mask.sum();
81 for(
int i = 0; i < modes.planes(); ++i )
83 float mean = ( modes.image( i ) * mask ).sum() / maskSum;
85 modes.image( i ) -= mean;
88 modes.image( i ) *= mask;
104template <
typename realT>
109 if( mask.rows() != modes.rows() )
111 std::cerr <<
"mx::sigproc::basisUtils2D::basisNormalize: modes and mask have different numbers of rows\n";
115 if( mask.cols() != modes.cols() )
117 std::cerr <<
"mx::sigproc::basisUtils2D::basisNormalize: modes and mask have different numbers of columns\n";
121 realT psum = mask.sum();
125 std::cerr <<
"mx::sigproc::basisUtils2D::basisNormalize: mask sums to <= 0\n";
129 for(
int i = 0; i < modes.planes(); ++i )
131 float norm = ( modes.image( i ) * mask ).square().sum() / psum;
133 modes.image( i ) /= sqrt( norm );
149template <
typename realT>
151 std::vector<realT> &s,
155 bool subtract =
false,
165 realT apertureNPix = mask.sum();
170 if( meanIgnore == 2 )
173 mean = ( im * mask ).sum() / apertureNPix;
178 for(
int i = 0; i < N; ++i )
180 amps[i] = ( im * modes.image( i ) * mask ).sum() / apertureNPix;
184 im -= amps[i] * modes.image( i );
188 if( meanIgnore && !subtract )
An image cube with an Eigen-like API.
imageT::Scalar imageMedian(const imageT &mat, const maskT *mask, std::vector< typename imageT::Scalar > *work=0)
Calculate the median of an Eigen-like array.
Eigen::Array< scalarT, -1, -1 > eigenImage
Definition of the eigenImage type, which is an alias for Eigen::Array.
int basisNormalize(improc::eigenCube< realT > &modes, improc::eigenImage< realT > &mask)
Normalize a basis set.
int basisMeanSub(improc::eigenCube< realT > &modes, improc::eigenImage< realT > &mask, bool postMult=true)
Mean-subtract a basis set.
int basisAmplitudes(std::vector< realT > &s, improc::eigenImage< realT > &im, improc::eigenCube< realT > &modes, improc::eigenImage< realT > &mask, bool subtract=false, int meanIgnore=0, int N=-1)
Measure the amplitudes of a set of basis modes fit to an image. Optionally subtract them.
int basisMask(improc::eigenCube< realT > &modes, improc::eigenImage< realT > &mask)
Mask a basis set.