It is actually the concrete classes derived from MomentCalcBase (call them, as a group, the MomentCalculator classes) that implement the multiProcess functions. These derived classes allow different algorithms to be written with which moments of the vector can be computed.
Now, so far, we have a LatticeApply function which iterates through Lattices, extracts vectors, and offers them up to functions implemented in the derived MomentCalculator classes to compute the moments. As well as that, we need some class to actually construct the MomentCalculator classes and to feed them to LatticeApply. This is the role of the ImageMoments class. It is a high level class which takes control information from users specifying which moments they would like to calculate and how. It also provides the ancilliary masking lattice to the MomentCalculator constructors. The actual computational work is done by the MomentCalculator classes. So ImageMoments, MomentCalcBase and its derived MomentCalculator classes are really one unit; none of them are useful without the others. The separation of functionality is caused by having the LatticeApply class that knows all about optimally iterating through Lattices.
The coupling between these classes is done partly by the "friendship". ImageMoments grants friendship to MomentCalcBase so that the latter has access to the private data and private functions of ImageMoments. MomentCalcBase then operates as an interface between its derived MomentCalculator classes and ImageMoments. It retrieves private data from ImageMoments, and also activates private functions in ImageMoments, on behalf of the MomentCalculator classes. The rest of the coupling is done via the constructors of the derived MomentCalculator classes.
Finally, MomentCalcBase also has a number of protected functions that are common to its derived classes (e.g. plotting, fitting, accumulating sums etc). It also has protected data that is common to all the MomentCalculator classes. This protected data is accessed directly by name rather than with interface functions as there is too much of it. Of course, since MomentCalcBase is an abstract base class, it is up to the MomentCalculator classes to give the MomentCalcBase protected data objects values.
For discussion about different moments and algorithms to compute them see the discussion in ImageMoments and also in the derived classes documentation.
Note that there are is assignment operator or copy constructor. Do not use the ones the system would generate either.
Returns the number of failed fits if doing fitting
Accumulate statistical sums from a vector
Determine if the spectrum is pure noise
Check validity of constructor inputs
Convert from
Convert from
Find out from the selectMoments array whether we want
to compute the more expensive moments
Return reference plotting device from ImageMoments object
Return automatic/interactive switch from the ImageMoments object
Return the Bool saying whether we need to compute coordinates
or not for the requested moments
Return the Bool from the ImageMoments object saying whether we
are going to fit Gaussians to the profiles or not.
Draw a horizontal line across the full x range of the plot
Draw a spectrum on the current panel with the box already drawn on
Draw and label a spectrum on the current or next panel
Draw on lines marking the mean and +/- sigma
Draw a vertical line of the given length at a given abcissa
Find the next masked or unmasked point in a vector
Fit a Gaussian to x and y arrays given guesses for the gaussian parameters
Return the fixed Y-plotting limits switch from the
ImageMoments object
Automatically fit a Gaussian to a spectrum, including finding the
starting guesses.
Automatically work out a guess for the Gaussian parameters
Returns False if all pixels masked.
Read the cursor button
Interactively define a guess for a Gaussian fit, and then
do the fit. Do this repeatedly until the user is content.
Interactively define a guess for the Gaussian parameters
Read the cursor and return its coordinates if not off the plot.
Also interpret which button was pressed
Compute the world coordinate for the given moment axis pixel
Examine a mask and determine how many segments of unmasked points
it consists of.
Resize an abcissa vector for plotting
Return the moment axis from the ImageMoments object
Return the name of the moment/profile axis
Return the number of moments that the ImageMoments class can calculate
Return the peak SNR for determination of all noise spectra from
the ImageMoments object
Return the selected pixel intensity range from the ImageMoments
object and the Bools describing whether it is inclusion or exclusion
The MomentCalculators compute a vector of all possible moments.
This function returns a vector which selects the desired moments from that
"all moment" vector.
Fill the ouput moments array
Fill a string with the position of the cursor
Install CoordinateSystem and SpectralCoordinate
in protected data members
Set up separable moment axis coordinate vector and
conversion vectors if not separable
Plot the Gaussian fit
Find some statistics from teh masked vector.
Returns False if no unmasked points.
Return standard deviation of image from ImageMoments object
Return the auto y min and max from the ImageMoments object
MomentClip computes moments directly from a vector of pixel intensities
extracted from the primary lattice. An optional pixel intensity inclusion
or exclusion range can be applied. It can also compute a mask based on the
inclusion or exclusion ranges applied to an ancilliary lattice (the ancilliary
vector corresponding to the primary vector is extracted). This mask is then
applied to the primary vector for moment computation (ImageMoments offers
a smoothed version of the primary lattice as the ancilliary lattice)
The constructor takes an ImageMoments object; the one that is constructing
the MomentClip object of course. There is much control information embodied
in the state of the ImageMoments object. This information is extracted by the
MomentCalcBase class and passed on to MomentClip for consumption.
Note that the ancilliary lattice is only accessed if the ImageMoments
object indicates that a pixel inclusion or exclusion range has been
given as well as the pointer to the lattice having a non-zero value.
See the ImageMoments
for discussion about the moments that are available for computation.
Destructor (does nothing).
This function is not implemented and throws an exception.
This function returns a vector of numbers from each input vector.
the output vector contains the moments known to the ImageMoments
object passed into the constructor.
Can handle null mask
MomentWindow computes moments from a subset of the pixels selected from the
input profile. This subset is a simple index range, or window. The window is
selected, for each profile, that is thought to surround the spectral feature
of interest. This window can be found from the primary lattice, or from an
ancilliary lattice (ImageMoments offers a smoothed version of the primary
lattice as the ancilliary lattice). The moments are always computed from
primary lattice data.
For each profile, the window can be found either interactively or automatically.
There are two interactive methods. Either you just mark the window with the
cursor, or you interactively fit a Gaussian to the profile and the +/- 3-sigma
window is returned. There are two automatic methods. Either Bosma's converging
mean algorithm is used, or an automatically fit Gaussian +/- 3-sigma window
is returned.
The constructor takes an ImageMoments object; the one that is constructing
the MomentWindow object of course. There is much control information embodied
in the state of the ImageMoments object. This information is extracted by the
MomentCalcBase class and passed on to MomentClip for consumption.
Note that the ancilliary lattice is only accessed if the pointer to it
is non zero.
See the ImageMoments
for discussion about the moments that are available for computation.
Destructor (does nothing).
This function is not implemented and throws an exception.
This function returns a vector of numbers from each input vector.
the output vector contains the moments known to the ImageMoments
object passed into the constructor.
Draw two vertical lines marking a spectral window
Automatically determine the spectral window
Automatically determine the spectral window via Bosma's algorithm
Interactively specify the spectral window with the cursor
Interactively define the spectral window
Returns false if can't define window.
Take the fitted Gaussian parameters and set an N-sigma window.
If the window is too small return a Fail condition.
MomentFit computes moments by fitting a Gaussian to each profile. The
moments are then computed from that fit. The fitting can be done either
interactively or automatically.
The constructor takes an ImageMoments object; the one that is constructing
the MomentFit object of course. There is much control information embodied
in the state of the ImageMoments object. This information is extracted by the
MomentCalcBase class and passed on to MomentFit for consumption.
See the ImageMoments
for discussion about the moments that are available for computation.
Destructor (does nothing).
This function is not implemented and throws an exception.
This function returns a vector of numbers from each input vector.
the output vector contains the moments known to the ImageMoments
object passed into the constructor.
static T convertF(const Float value)
void costlyMoments(ImageMoments<T>& iMom, Bool& doMedianI, Bool& doMedianV, Bool& doAbsDev) const
PGPlotter& device(ImageMoments<T>& iMom) const
Bool doAuto(const ImageMoments<T>& iMom) const
void doCoordCalc(Bool& doCoordProfile, Bool& doCoordRandom, const ImageMoments<T>& iMom) const
Bool doFit(const ImageMoments<T>& iMom) const
void drawHorizontal(const T& y, PGPlotter& plotter) const
void drawLine (const Vector<T>& x, const Vector<T>& y, PGPlotter& plotter) const
Bool drawSpectrum (const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title, const Bool advancePanel, String& plotter) const
void drawMeanSigma (const T dMean, const T dSigma, PGPlotter& plotter) const
void drawVertical(const T x, const T yMin, const T yMax, PGPlotter& plotter) const
Bool findNextDatum (uInt& iFound, const uInt& n, const Vector<Bool>& mask, const uInt& iStart, const Bool& findGood) const
Bool fitGaussian (uInt& nFailed, T& peak, T& pos, T& width, T& level, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakGuess, const T posGuess, const T widthGuess, const T levelGuess) const
Bool fixedYLimits(const ImageMoments<T>& iMom) const
Bool getAutoGaussianFit(uInt& nFailed, Vector<T>& gaussPars, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation, PGPlotter& plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getAutoGaussianGuess(T& peakGuess, T& posGuess, T& widthGuess, T& levelGuess, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask) const
void getButton(Bool& reject, Bool& redo, PGPlotter& plotter) const
Bool getInterGaussianFit(uInt& nFailed, Vector<T>& gaussPars, LogIO& os, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const LogIO xLabel, const LogIO yLabel, const LogIO title, String& plotter) const
void getInterGaussianGuess(T& peakGuess, T& posGuess, T& widthGuess, Vector<Int>& window, Bool& reject, Vector& os, const Int nPts, LogIO& plotter) const
Bool getLoc(T& x, Bool& allSubsequent, Bool& ditch, Bool& redo, const Bool final, PGPlotter& plotter) const
Double getMomentCoord(ImageMoments<T>& iMom, Vector<Double>& pixelIn, Vector<Double>& worldOut, const Double momentPixel) const
void lineSegments (uInt& nSeg, Vector<uInt>& start, Vector<uInt>& nPts, const Vector<Bool>& mask) const
void makeAbcissa(Vector<T>& x, const Int& n) const
Int& momentAxis(ImageMoments<T>& iMom) const
String momentAxisName(const CoordinateSystem&, const ImageMoments<T>& iMom) const
uInt nMaxMoments() const
T& peakSNR(ImageMoments<T>& iMom) const
void selectRange(Vector<T>& pixelRange, Bool& doInclude, Bool& doExlude, ImageMoments<T>& iMom) const
Vector<Int> selectMoments(ImageMoments<T>& iMom) const
void setCalcMoments (ImageMoments<T>& iMom, Vector<T>& calcMoments, Vector<Bool>& calcMomentsMask, Vector<Double>& pixelIn, Vector<Double>& worldOut, Bool doCoord, Double integratedScaleFactor, T dMedian, T vMedian, Int nPts, typename NumericTraits<T>::PrecisionType s0, typename NumericTraits<T>::PrecisionType s1, typename NumericTraits<T>::PrecisionType s2, typename NumericTraits<T>::PrecisionType s0Sq, typename NumericTraits<T>::PrecisionType sumAbsDev, T dMin, T dMax, Int iMin, Int iMax) const
void setPosLabel(String& title, const IPosition& pos) const
void setCoordinateSystem (CoordinateSystem& cSys, const ImageMoments<T>& iMom)
void setUpCoords (ImageMoments<T>& iMom, Vector<Double>& pixelIn, Vector<Double>& worldOut, Vector<Double>& sepWorldCoord, Vector& os, Double& integratedScaleFactor, const LogIO& cSys, Bool doCoordProfile, Bool doCoordRandom) const
void showGaussFit(const T peak, const T pos, const T width, const T level, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, Vector& plotter) const
Bool stats(T& dMin, T& dMax, uInt& minPos, uInt& maxPos, T& mean, const Vector<T>& profile, const Vector<Bool>& mask) const
T& stdDeviation(ImageMoments<T>& iMom) const
void yAutoMinMax(T& yMin, T& yMax, ImageMoments<T>& iMom) const
virtual void init (uInt nOutPixelsPerCollapse)
Check if #pixels is indeed 1.
template <class T> class MomentClip : public MomentCalcBase<T>
Interface
Description
Review Status
Prerequisite
Synopsis
This concrete class is derived from the abstract base class MomentCalcBase
which provides an interface layer to the ImageMoments driver class.
ImageMoments creates a MomentClip object and passes it to the LatticeApply
function, lineMultiApply. This function iterates through a given lattice,
and invokes the multiProcess member function of MomentClip on each vector
of pixels that it extracts from the input lattice. The multiProcess
function returns a vector of moments which are inserted into the output
lattices also supplied to the LatticeApply function.
Example
This example comes from ImageMoments. outPt is a pointer block holding
pointers to the output lattices. The ancilliary masking lattice is
just a smoothed version of the input lattice.
// Construct desired moment calculator object. Use it polymorphically
// via a pointer to the base class. os_P is a LogIO object.
MomentCalcBase<T>* pMomentCalculator = 0;
if (clipMethod || smoothClipMethod) {
pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (windowMethod) {
pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (fitMethod) {
pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
}
// Iterate optimally through the image, compute the moments, fill the output lattices
LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,
momentAxis_p, pProgressMeter);
delete pMomentCalculator;
Note that there are is assignment operator or copy constructor.
Do not use the ones the system would generate either.
To Do
Member Description
MomentClip(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)
Constructor. The pointer is to an ancilliary lattice used as a mask.
If no masking lattice is desired, the pointer value must be zero. We also
need the ImageMoments object which is calling us, the ImageMoments
logger, and the number of output lattices ImageMoments has created.
~MomentClip()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)
virtual Bool canHandleNullMask() const
template <class T> class MomentWindow : public MomentCalcBase<T>
Interface
Description
Review Status
Prerequisite
Synopsis
This concrete class is derived from the abstract base class MomentCalcBase
which provides an interface layer to the ImageMoments driver class.
ImageMoments creates a MomentWindow object and passes it to the LatticeApply
function lineMultiApply. This function iterates through a given lattice,
and invokes the multiProcess member function of MomentWindow on each profile
of pixels that it extracts from the input lattice. The multiProcess function
returns a vector of moments which are inserted into the output lattices also
supplied to the LatticeApply function.
Example
This example comes from ImageMoments. outPt is a pointer block holding
pointers to the output lattices. The ancilliary masking lattice is
just a smoothed version of the input lattice. os_P is a LogIO object.
<srcBlock>
// Construct desired moment calculator object. Use it polymorphically via
// a pointer to the base class.
MomentCalcBase<T>* pMomentCalculator = 0;
if (clipMethod || smoothClipMethod) {
pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (windowMethod) {
pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (fitMethod) {
pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
}
// Iterate optimally through the image, compute the moments, fill the output lattices
LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,
momentAxis_p, pProgressMeter);
delete pMomentCalculator;
Motivation
Note that there are is assignment operator or copy constructor.
Do not use the ones the system would generate either.
To Do
Member Description
MomentWindow(Lattice<T>* pAncilliaryLattice, ImageMoments<T>& iMom, ImageMoments& os, const uInt nLatticeOut)
Constructor. The pointer is to a lattice containing the masking
lattice (created by ImageMoments). We also need the
ImageMoments object which is calling us, the ImageMoments logger,
and the number of output lattices ImageMoments has created.
~MomentWindow()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)
void drawWindow(const Vector<Int>& window, PGPlotter& plotter) const
Bool getAutoWindow(uInt& nFailed, Vector<Int>& window, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation, const Bool doFit, PGPlotter& plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getBosmaWindow (Vector<Int>& window, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const T peakSNR, const T stdDeviation, PGPlotter& plotter, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const PGPlotter xLabel, const PGPlotter yLabel, const PGPlotter title) const
Bool getInterDirectWindow(Bool& allSubsequent, LogIO& os, Vector<Int>& window, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title, String& plotter) const
Bool getInterWindow (uInt& nFailed, Bool& allSubsequent, LogIO& os, Vector<Int>& window, const Bool doFit, const Vector<T>& x, const Vector<T>& y, const Vector<Bool>& mask, const Bool fixedYLimits, const T yMinAuto, const T yMaxAuto, const String xLabel, const String yLabel, const String title, String& plotter) const
Bool setNSigmaWindow(Vector<Int>& window, const T pos, const T width, const Int nPts, const Int N) const
template <class T> class MomentFit : public MomentCalcBase<T>
Interface
Description
Review Status
Prerequisite
Synopsis
This concrete class is derived from the abstract base class MomentCalcBase
which provides an interface layer to the ImageMoments driver class.
ImageMoments creates a MomentFit object and passes it to the LatticeApply
function, lineMultiApply. This function iterates through a given lattice,
and invokes the multiProcess member function of MomentFit on each vector
of pixels that it extracts from the input lattice. The multiProcess
function returns a vector of moments which are inserted into the output
lattices also supplied to the LatticeApply function.
Example
This example comes from ImageMoments. outPt is a pointer block holding
pointers to the output lattices. os_P is a LogIO object.
<srcBlock>
// Construct desired moment calculator object. Use it polymorphically via
// a pointer to the base class.
MomentCalcBase<T>* pMomentCalculator = 0;
if (clipMethod || smoothClipMethod) {
pMomentCalculator = new MomentClip<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (windowMethod) {
pMomentCalculator = new MomentWindow<T>(pSmoothedImage, *this, os_p, outPt.nelements());
} else if (fitMethod) {
pMomentCalculator = new MomentFit<T>(*this, os_p, outPt.nelements());
}
// Iterate optimally through the image, compute the moments, fill the output lattices
LatticeApply<T>::lineMultiApply(outPt, *pInImage_p, *pMomentCalculator,
momentAxis_p, pProgressMeter);
delete pMomentCalculator;
Motivation
Note that there are is assignment operator or copy constructor.
Do not use the ones the system would generate either.
To Do
Member Description
MomentFit(ImageMoments<T>& iMom, LogIO& os, const uInt nLatticeOut)
Constructor. We need the ImageMoments object which is calling us,
the ImageMoments logger, and the number of output lattices
ImageMoments has created.
~MomentFit()
virtual void process(T& out, Bool& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const Vector& pos)
virtual void multiProcess(Vector<T>& out, Vector<Bool>& outMask, const Vector<T>& in, const Vector<Bool>& inMask, const IPosition& pos)